Skip to content

Instantly share code, notes, and snippets.

View stevekrenzel's full-sized avatar

Steve Krenzel stevekrenzel

View GitHub Profile
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 December 11, 2015 23:39
Combinations Tree
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 March 31, 2012 10:48 — forked from erikh/hack.sh
OSX For Hackers
#!/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 March 15, 2012 19:44
Backbone Autodispose
jQuery.cleanData = _.wrap jQuery.cleanData, (cleanData, elems) ->
for elem in elems
$(elem).data('view')?.dispose()
cleanData.apply @, arguments
@stevekrenzel
stevekrenzel / gist:1810703
Created February 12, 2012 20:22
Password Generator
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:
@stevekrenzel
stevekrenzel / gist:1807100
Created February 12, 2012 07:42
Interest
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)
@stevekrenzel
stevekrenzel / gist:1806675
Created February 12, 2012 06:14
Number guesser
#!/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 February 12, 2012 05:39
Substitution Cipher
#!/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)
@stevekrenzel
stevekrenzel / gist:1806459
Created February 12, 2012 05:01
Caesar Cipher
caesar_encode = caesar_decode = lambda m: m.encode('rot13')
@stevekrenzel
stevekrenzel / gist:1806430
Created February 12, 2012 04:51
Scrambled words solution
#!/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)]