Skip to content

Instantly share code, notes, and snippets.

@jdp
jdp / jarg.py
Last active August 29, 2015 14:09
JSON shorthand for your CLI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
import sys
class InvalidJSONError(ValueError):
def __init__(self, key, *args, **kwargs):
self.key = key
@jdp
jdp / gophmt.py
Last active August 29, 2015 14:09
Write gophermap files easily and naturally
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import sys
import textwrap
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
@jdp
jdp / shorten.sh
Last active August 29, 2015 14:05
A URL shortening service in bash
#!/usr/bin/env bash
set -e
B56ALPHABET="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789"
if [[ "$REQUEST_METHOD" = "GET" ]]; then
URL=$(redis-cli get ${PATH_INFO:1})
if [[ -z "$URL" ]]; then
echo "Status: 404 Not Found"
echo "Content-Type: text/plain"
@jdp
jdp / Makefile
Last active September 24, 2015 13:22
makefile/procfile ultimate front end combo
JS = $(wildcard scripts/*.js)
all: game.js game.js.map game.css rules.html
game.js: $(JS)
game.js.map: $(JS)
%.js %.js.map:
closure-compiler --js $(JS) --js_output_file $*.js --create_source_map $*.js.map --source_map_format V3
@jdp
jdp / relsql.php
Created March 20, 2014 20:12
sketch of a DSL for generating SQL in PHP
<?php
$emp = Relation('emp');
$dept = Relation('dept');
/*
* SELECT *
* FROM emp
* WHERE rownum <= 5;
*/
select($emp, $emp->field('rownum')->lte(5))
@jdp
jdp / miner.py
Created March 7, 2014 02:46
gitcoin miner
#!/usr/bin/env python
import calendar
import datetime
import hashlib
import multiprocessing
import os
import re
import signal
import subprocess
import sys
@jdp
jdp / negotiation.py
Created March 4, 2014 20:50
content negotiation mixin for django class based views
import mimeparse
class ContentNegotiationMixin(object):
def not_acceptable(self, request):
return HttpResponse(status=406)
def get_acceptable(self, request):
return dict(self.accepts)
@jdp
jdp / csvq.py
Created January 15, 2014 23:58
turn csv files into sqlite tables and query them
#!/usr/bin/env python
import os
import sqlite3
from csvkit import table, CSVKitWriter
from csvkit.cli import CSVKitUtility
from csvkit.sql import make_create_table_statement, make_table
@jdp
jdp / urp.py
Created December 20, 2013 17:41
quick command line tool for parsing, inspecting, and mutating URL's
#!/usr/bin/env python
import argparse
import itertools
import os
import sys
import urllib
import urlparse
ERR_NO_SUCH_QUERY = 2
@jdp
jdp / rdb2proto.py
Created October 10, 2013 21:16
dump redis protocol from rdb file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import calendar
import sys
import rdbtools
def emit_protocol(*args):