Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Krenzel stevekrenzel

View GitHub Profile
View doesnt_work
pyg = 'ay'
original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
if first == "a" or "e" or "i" or "o" or "u":
print "vowel"
else:
@stevekrenzel
stevekrenzel / gist:4678175
Last active Dec 11, 2015
Combinations Tree
View gist:4678175
import Data.List
import Data.Tree
combinationsTree xs = unfoldTree next ([], xs)
where next (path, xs) = (path, map (appendTo path . splitAt 1) $ init $ tails xs)
appendTo path (x, ys) = (path ++ x, ys)
depth 0 node = Node{rootLabel=(rootLabel node), subForest=[]}
depth n node = node{subForest=(map (depth (n - 1)) (subForest node))}
@stevekrenzel
stevekrenzel / hack.sh
Created Mar 31, 2012 — forked from erikh/hack.sh
OSX For Hackers
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@stevekrenzel
stevekrenzel / gist:2046371
Created Mar 15, 2012
Backbone Autodispose
View gist:2046371
jQuery.cleanData = _.wrap jQuery.cleanData, (cleanData, elems) ->
for elem in elems
$(elem).data('view')?.dispose()
cleanData.apply @, arguments
View gist:1810703
from sys import argv, exit
from random import choice
from string import ascii_letters, digits
if len(argv) < 2:
print "usage: %s length [quantity]" % (argv[0])
exit(1)
length, quantity = int(argv[1]), 1
if len(argv) == 3:
View gist:1807100
from sys import argv, exit
types = {
'simple': lambda capital, rate, time: capital * (1 + (rate * time)),
'compound': lambda capital, rate, time: capital * ((1 + rate) ** time)
}
if len(argv) != 5 or argv[1] not in types:
print "usage: %s <%s> capital rate time" % (argv[0], '|'.join(types))
exit(1)
View gist:1806675
#!/usr/bin/env python
lower, upper = 1, 100
print "Guess a number between %s and %s (inclusive)." % (lower, upper)
while lower < upper:
mid = (lower + upper) / 2
guess = raw_input("Is your number higher than %s? (y/n): " % (mid))
if guess == 'y':
@stevekrenzel
stevekrenzel / gist:1806574
Created Feb 12, 2012
Substitution Cipher
View gist:1806574
#!/usr/bin/env python
from string import printable, maketrans
from random import seed, shuffle
def cipher_alphabet(key):
alphabet = [c for c in printable]
seed(hash(key))
shuffle(alphabet)
return ''.join(alphabet)
View gist:1806459
caesar_encode = caesar_decode = lambda m: m.encode('rot13')
@stevekrenzel
stevekrenzel / gist:1806430
Created Feb 12, 2012
Scrambled words solution
View gist:1806430
#!/usr/bin/env python
from urllib import urlopen
word_list = urlopen('http://pastebin.com/raw.php?i=jSD873gL').read().split()
scrambled_words = ['mkeart', 'sleewa', 'edcudls', 'iragoge', 'usrlsle',
'nalraoci', 'nsdeuto', 'amrhat', 'inknsy', 'iferkna']
for scrambled in sorted(scrambled_words, key=len):
matches = [word for word in word_list if sorted(scrambled) == sorted(word)]
You can’t perform that action at this time.