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
""" | |
Using Amazon S3 with filename to get data in string and convert to file object | |
then returning HTTP response from file object with mime type. | |
""" | |
import os | |
import mimetypes | |
from django.http import Http404, HttpResponse | |
from django.core.files.base import ContentFile | |
from django.core.files.storage import default_storage |
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 |
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 csv | |
def csv_to_list(file_path): | |
""" | |
Reads csv file into list. | |
""" | |
with open(file_path, 'rb') as f: | |
# load all data into memory, scary | |
dialect = csv.Sniffer().sniff(f.read(1024)) | |
f.seek(0) # reset cursor |
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
v = 'True' | |
def bool2(): | |
v[0].lower() in ('t','1','y') |
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
# manage.py in Django project | |
import re | |
def read_env(): | |
""" | |
Pulled from Honcho code with minor updates, reads local default | |
environment variables from a .env file located in the project root | |
directory. | |
""" | |
try: |
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
Show hidden characters
[ | |
{ | |
"button": "button1", "modifiers": ["alt"], | |
"press_command": "drag_select", | |
"press_args": {"by": "columns"} | |
} | |
] |