This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_username(un): | |
import re | |
# clean username | |
un = re.sub(r'[^a-zA-Z0-9._]+', '', un) | |
# soft truncate | |
if len(un) > 30: | |
un = un.split('@')[0] # pray for email address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subl is a command line interface (cli) for a program called sublime text 2 | |
# http://www.sublimetext.com/docs/2/osx_command_line.html | |
alias subl="'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'" | |
alias nano="subl" | |
export EDITOR="subl" | |
alias edit_bash="subl ~/.bash_profile" | |
alias rebash=". ~/.bash_profile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Loop through files in current directory | |
Delete all directories that are named with digits | |
""" | |
import os | |
import shutil | |
for root, dirs, files in os.walk('.'): | |
basename = os.path.basename(root) | |
if os.path.isdir(basename) and basename.isdigit(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### one way ### | |
from string import letters | |
import random | |
rand_chars = ''.join(random.sample(letters, len(letters)))[:8] | |
### another way ### | |
from string import letters | |
from random import choice | |
rand_chars = ''.join([choice(letters) for i in xrange(8)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def password_generator(length=8): | |
from random import choice | |
from string import letters, digits | |
doppelgangers = set('io10szSZOIl25uvUV') | |
alphanums = set(letters+digits) | |
chars = list(doppelgangers - alphanums) | |
return ''.join([choice(chars) for i in range(length)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
print re.sub("[^a-zA-Z0-9]", "-", name.lower()[:200]).strip('-') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listify = lambda s='chicken egg',n=10: ((s+' ')*n).split() | |
listify() | |
listify('eloy') | |
listify('eloy',20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used for lastname, firstname situations or | |
# when using incomplete addresses | |
# ', '.join() method doesn't account for blank items | |
# assumes string; else will break on strip method call | |
def commafy(*args, **kwargs): | |
delimiter = kwargs.get('delimiter', ', ') | |
return delimiter.join([i for i in args if i.strip()]) | |
# ideal world: whole address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT COUNT(*) from information_schema.columns | |
WHERE table_name='forms_form'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 'marks the spot' | |
def f(): | |
if False: | |
x = '' | |
print x |