Skip to content

Instantly share code, notes, and snippets.

View crccheck's full-sized avatar

Chris Chang crccheck

View GitHub Profile
@crccheck
crccheck / .jshintrc
Created April 18, 2014 21:27
js hint config for qunit
{
"browser": true,
"strict": false,
"globals": {
"QUnit": false,
"module": false,
"test": false,
"asyncTest": false,
"expect": false,
"start": false,
@crccheck
crccheck / package managers.md
Last active August 29, 2015 14:01
Rosetta stone for web package managers (not extensive)
command pip bundler npm bower
Init touch requirements.txt bundle init npm init bower init
List installed packages pip freeze or pip list bundle list npm ls -g --depth 0 bower list
Search for a package npm search <name> bower search
Install a package pip install <name> npm install <name> --save-dev bower install <name>
Install everything pip install -r requirements.txt bundle install npm install
List outdated packages pip list --outdated bundle outdated npm outdated
Update everything pip install --upgrade bundle update `npm update --s
# Invoke cheat
function inv {
# if no parameters, then assume we want to list tasks
if [ -z $1 ]; then
invoke --list
else
# invoke expects --help to be first, so move it if it isn't
local numargs=$#
for ((i=2; i <= numargs ; i++))
do
@crccheck
crccheck / geoize.py
Created December 10, 2014 04:00
geocode and geojson
#!/usr/bin/env python3
"""
Usage: ./2geojson.py [<yaml_file> | <address>]
Requirements:
pip3 install PyYAML geopy
"""
import json
@crccheck
crccheck / README.md
Last active August 29, 2015 14:17
ElasticSearch Cheat Sheet
@crccheck
crccheck / Makefile
Last active August 29, 2015 14:19
Prometheus+Docker bootstrap
#### PROMETHEUS ##################################
.PHONY: prom
# add-host hack:
# https://github.com/docker/docker/issues/1143#issuecomment-70052272
prom: prom_exp prom_node
-@docker rm -f $@_1 > /dev/null
docker run -d --name $@_1 \
-v ${PWD}/prom/prometheus.conf:/prometheus.conf:ro \
-v ${PWD}/prom/data:/prometheus \
@crccheck
crccheck / README.md
Last active August 29, 2015 14:20
Isomorphic Ajax.js hell

Picking a testable ajax library for react (using jest)

Here are some examples of doing a GET request against a resource and getting JSON back.

jQuery

Works. Works great. It just brings along a lot of baggage you won't need in a ReactJS app. Removing jQuery will remove over 200KB (unminified/gzipped).

Fetch

@crccheck
crccheck / djtoolbar-sort.js
Created November 9, 2010 01:09
Sort Django Debug Toolbar SQL by execution time
jQuery.fn.sort = function() { return this.pushStack( [].sort.apply( this, arguments ), []); };
$('.djDebugSql').closest('tr').each(function(i) { this.setAttribute('rel',i); });
function dtsql(o){
switch (o) {
case 'clean' : $('.djDebugSql').each(function(){ $(this).contents()[1].nodeValue = ' '; }); break;
case 'time' : tbody = $('.djDebugSql:eq(0)').closest('tbody'); tbody.children('tr').sort(function(a,b){ return $(b).children('td:eq(0)').html() - $(a).children('td:eq(0)').html() }).appendTo(tbody);
break;
}
}
dtsql('time');
@crccheck
crccheck / View html output of a django url.py
Created November 10, 2010 16:30
Use Django Test Client to curl a url
from django.test.client import Client
def render_url(url):
c = Client()
return c.get(url).content
@crccheck
crccheck / django resolve url_to_view.py
Last active September 24, 2015 05:17
Too lazy to figure out what view goes with what url? Me too
# based on http://stackoverflow.com/questions/797773/django-caching-can-it-be-done-pre-emptively
# run this from `manage.py shell`
# if you have ipython, you can do `what_view /some/silly/url/` and remember the leading and trailing slash
from django.core.urlresolvers import resolve
def what_view(url):
try:
(v, foo, params) = resolve(url)
print "View Name: %s Line: %s of %s" % (v.__name__, v.__code__.co_firstlineno, v.__code__.co_filename)
return v, foo, params
except: