Skip to content

Instantly share code, notes, and snippets.

@woodphil
woodphil / img-srcset-example.html
Created July 28, 2016 15:22
img srcset example and comments
<img id="first-outfit"
srcset="small.jpg 300w,
large.jpg 1024w"
sizes="(min-width: 768px) 90vw, 100vw"
src="medium.jpg"
alt="first outfit" />
<!-- srcset defines the image sources and their dimensions -->
<!-- sizes defines the breakpoints and what the expected displays are at that break point, no media query is the default value-->
<!-- src is the default image when the queries aren't suitably matched/browser does not support srcset -->
@woodphil
woodphil / restart-tmux
Created June 9, 2016 19:33
restart tmux pane
ctrl-prefix + : respawn-pane -k
@woodphil
woodphil / lazy-carousel.js
Created May 30, 2016 18:31
Lazy loading for bootstrap's carousel
@woodphil
woodphil / grab-table-columns.sh
Last active May 25, 2016 21:27
Grab the table schema and columns of a mysql db
mysql -h<hostname> -u<username> -p<password> >output.txt << EOF
SELECT table_name, column_name, column_type
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema='<db_name>'
ORDER BY table_name, ordinal_position;
EOF
@woodphil
woodphil / dict-construction-I.py
Created March 21, 2016 20:06
pythonic dictionary inversion
# example: dictionary that has students as keys and within each entry has a list of teachers that teach that student
# this snippet will use that dictionary to create a dictionary with teachers as keys and within those entires have a list
# of students taught by that teacher
for e in dic.keys():
for d in dic[e]:
if not data.get(d):
data[d] = set()
data[d].add(e)
#simplified
@woodphil
woodphil / dict-comprehension-I.py
Created March 15, 2016 21:15
the power of dict comprehensions I
for i in list_thing:
temp = {}
data_obj = i.data
if data_obj:
data_within = data_obj.get('data1')
if data_within:
for data in data_within:
if data.get('field1') and data.get('field2):
temp[data] = helper.function(data_within[data].get('field1'), data_within[data].get('field2')
@woodphil
woodphil / dump-python-mako.js
Created March 15, 2016 19:42
dumping from python to mako requires careful attention to which quotes to use
var blah = '${ c.results_from_query | n}'
// | n filter returns them as raw unescaped string,
//take care that the string quotes are not the same as the value returned from the server
@woodphil
woodphil / hack-commit.git
Created February 23, 2016 18:21
hacky patch way of doing git commits
git diff > backup
git diff -w > changes (or whatever flag is needed)
git reset --hard
patch < changes (apply the changes listed in the file)
@woodphil
woodphil / specific-files.git
Created February 23, 2016 18:00
committing specific files from a branch
git checkout master
git checkout <target_branch> <paths>
ex:
git checkout cool_feature cool_new_file1 cool_new_file2
git commit
@woodphil
woodphil / jsonquotes.py
Created February 22, 2016 22:50
json double quotes format
import simplejson as json
s = "{'username':'dfdsfdsf'}" #1 INCORRECT, uses '' for quotes in strings
s = '{"username":"dfdsfdsf"}' #2 CORRECT, uses "" for quotes in strings
j = json.loads(s)