User : Sunjay Varma

Title User Language Tags Description Date
Simple recursive function to non-recursive function Sunjay Varma python

This recipe is a simple solution for turning a recursive function into a non-recursive function.

May 27, 2011
Fibonacci Number Generator Sunjay Varma python

This recipe allows for individual number generation, and allows for generations of number ranges as well.

The recipe automatically memorizes numbers generated before and keeps them through out the running of the script. This recipe cannot handle too large of numbers, but does act as a simple solution for most cases.

April 13, 2011
Dictionary Who's Keys Act Like Attributes As Well Sunjay Varma python

Think of this as a JavaScript object. In JavaScript, the objects can be referenced by indexing (e.g. d[name]) or by directly using the dot (.) operator (e.g. d.name).

This is the same concept.

Note to Python 2.4 Users: You will need to change the "except KeyError as e:" line to "except KeyError, (e):".

February 28, 2011
Special Range Function for Different Kinds of Ranges (int, float, character) Sunjay Varma python

This module allows the user to create a more verbose set of ranges. Simple character ranges, and float ranges are supported.

Supported Ranges:

  • Basic Integer Ranges
  • Float Ranges (as accurate as a float range can get)
  • Simple character ranges (lowercase to lowercase, uppercase to uppercase, etc.)

It should work in Python 2 and Python 3.

If you tested this for speed, or want to test this for speed, please post the results! (And your system specs)

Edit: Found a really silly error of mine when using range instead of xrange in these functions!

February 20, 2011
Python Sessions Sunjay Varma python

I think this script should now be functional enough to post here at ActiveState. When you reply or vote down, please post some information on your problem with the code, and if you can, maybe something about the solution. This interface works, and is designed especially for Python. If you like it, don't be afraid to post that either, constructive criticism is all good, but compliments are even better! ;)

Get the latest version of this code here: http://wiki.sunjay.ca/Python:Contents/Python_Session

Latest Changes:

  • Added a new function for making the session cookie last longer. See code for set_expires. Note: This new function is just in case you need to include a session for longer than one brower session (for example, one day instead).
December 31, 2010
Simple Regular Expression Tester Sunjay Varma python

Is it possible to create a simple command line program that I can use to quickly test my regular expressions?

Yes it is. This simple regular expression tester uses Python's re module as well as others to quickly allow you to test your regular expression in one go.

TODO:

  • Add Support For Multiple Regular Expression Input

Recent Changes:

  • Made the output prettier with a little more whitespace. More bytes, but at least it's easier to read!
December 24, 2010
Python Tkinter Canvas Rectangle Selection Box Sunjay Varma python

A simple, yet effective rectangle selection box. :)

Works with a tkinter canvas! Just add the class and set it up like in the example code. The cross heir was my own touch, the RectTracker only draws a box.

Have fun! And please don't just vote down, post what you don't like if you don't like it.

September 27, 2010
Tkinter Splash Screen Sunjay Varma python

I wanted to mess around with the overrideredirect function of the window manager, and ended up making a pretty good Python Tkinter splash screen. :)

Just run it for a demo.

There are instructions and more info in the script

June 21, 2010
Python Tkinter Tabs Sunjay Varma python

This tabbed interface is very useful for Tkinter users. I am sure there is a better way to do it, but I did the best I could.

Please enjoy this tabbed interface by SunjayVarma - www.sunjay-varma.com

UPDATES: Fixed the index issues. Made it easier to use.

June 13, 2010
Improved range function Sunjay Varma python

While using the built-in range function a while ago. I found an odd (perhaps bug) where the range function couldn't use float steps. I am not sure if that was intended for simplicity or not, but I wrote my own range function that goes beyond that anyway.

June 5, 2010
Flatten a list (or list of lists, etc.) Sunjay Varma python

I created this function sometime ago for my own purposes. It simply flattens a list.

Check out the first comment for another version of someone else's design.

June 5, 2010