Nov 27

Well, today my Windows Utilities post got Stumbled (God knows why, there's only about a hundred of these out there). My traffic shot through the roof. This was my first time being Stumbled, so needless to say, I was a little bit excited.

Thank you, StumbleUpon. :)

Nov 24

I've seen several different approaches to dictionary generators over time, and this was one method that struck me that it didn't seem like anyone else had used. If someone else has used this method, I apologize, you deserve full credit, but I came up with this particular version completely independently. I first wrote it in JavaScript (if you want that version, feel free to leave me a comment, but it was slow as fuck), then I ported it to Python for better speed. I even wrote comments for once, so that you can understand what I did (it's not very hard to understand, I just need to get into the habit). Enjoy it :)

def generate(size):
	f = file(raw_input("Output file: "), "w") # Set the output file
	y = [] # Create an empty list
	z = True # Set the toggle boolean to "True" (use the x list)
	charset = "0123456789abcdefghijklmnopqrstuvwxyz" # Charset for generating dictionary
	charlen = len(charset) # Length of charset
	x = list(charset) # Make a list with all the characters in the charset string
	for i in xrange(charlen): f.write(x[i] + "\\n") # Write the character set to the output file
	for i in xrange(1,size+1): # Loop until you have generated to the length specified
		if z == False: # If the toggle boolean is "False", append to y
			xlen = len(x) # Length of list x
			for i in xrange(0,charlen): # Loop through all the characters in charset
				for c in xrange(0,xlen): # Loop through all the items in x and prefix them with the appropriate character
					y.append(charset[i] + x[c]) # Append results to y
					f.write(charset[i] + x[c] + "\\n") # Write the results to file
			x = [] # Clear out list x

		else: # If the toggle boolean is "True", append to x
			ylen = len(y) # Length of list y
			for i in xrange(0,charlen): # Loop through all the characters in charset
				for c in xrange(0,ylen): # Loop through all the items in y and prefix them with the appropriate character
					x.append(charset[i] + y[c]) # Append results to x
					f.write(charset[i] + y[c] + "\\n") # Write the results to file
			y = [] # Clear out list y
		z = z == False # Flip the toggle boolean
	f.close() # Close the output file
generate(4) # Call with largest character length you want to generate
Nov 18

I had a project I was working on yesterday and I needed to sort out an array in order of most to least repeated, so I came up with this:

$array = array_count_values($array);
array_multisort($array, SORT_DESC);

If you don't want the frequency that they occur in as the value, you can do this:

$array = array_count_values($array);
array_multisort($array, SORT_DESC);
$array = array_keys($array);

Hope this helps someone. :)

Nov 12

Here was my problem: I needed to reverse a boolean value throughout a loop. True, False, True, False, etc. In most languages, let's say PHP, that looks like this:

$var = !$var;

Python doesn't like the ! when used in this context. However, I got to thinking, and this is what I came up with.

var = var == False

or

var = var != True

Hope this is useful to someone.

Nov 11

I stumbled upon this post which lists the parts of 10 episodes of an interesting documentary, The Day The Universe Changed. I soon realized that I didn't really want to open up 50 windows to watch them all in, so I wrote this. It's rather simplistic, and could certainly be improved, but for all intents and purposes, it works. Simply enter the links to the videos you want to watch, and hit the "Next" button when you're ready to move on to the next video.

« Previous Entries