Skip to content

Instantly share code, notes, and snippets.

View eloyz's full-sized avatar
🎯
Focusing

Eloy Zuniga Jr. eloyz

🎯
Focusing
View GitHub Profile
@eloyz
eloyz / pg_dump.py
Last active December 16, 2015 17:09
We store postgres connection strings and sometimes I need to dump the sql from a database. This python files prints out the dump command for me when I pass the postgres connection string. Example: `python pg_dump.py postgres://<the rest of the string>'
import os
import re
import sys
from functools import partial
def f(host=u'', x=None):
"""
Returns string
"""
@eloyz
eloyz / codeintel.sublime-mousemap
Created March 26, 2013 10:46
This is a mouse binding that lets you keep the column select feature in Sublime Text 2 If you're using the CodeIntel plugin it gets overwritten, this is a way of bring it back. Not sure how to keep both bindings. Sublime > Preferences > Package Settings > SublimeCodeIntel > Mouse Bindings - User
[
{
"button": "button1", "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"by": "columns"}
}
]
@eloyz
eloyz / read_env.py
Created March 23, 2013 03:42
Function that reads environment variables from .env file and adds them to the os.environment dictionary.
# 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:
v = 'True'
def bool2():
v[0].lower() in ('t','1','y')
@eloyz
eloyz / csv_to_list.py
Created January 17, 2013 08:17
Using Python to read CSV file into list.
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
@eloyz
eloyz / json_with_uuid_support.py
Last active November 6, 2015 16:27
JSON with UUID serialization support
from utils import json
from uuid import uuid4
json.dumps({'id': uuid4()})
@eloyz
eloyz / pop_quiz.py
Created December 10, 2012 19:01
Pop Quiz
x = 'marks the spot'
def f():
if False:
x = ''
print x
@eloyz
eloyz / column_count.sql
Created October 11, 2012 14:51
Get number of columns in database table
SELECT COUNT(*) from information_schema.columns
WHERE table_name='forms_form';
@eloyz
eloyz / commafy.py
Created March 22, 2012 09:54
Commafiy: For those comma separated scenarios
# 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
@eloyz
eloyz / clone.py
Created December 16, 2011 14:27
Return a list of cloned items
listify = lambda s='chicken egg',n=10: ((s+' ')*n).split()
listify()
listify('eloy')
listify('eloy',20)