Skip to content

Instantly share code, notes, and snippets.

@jdp
jdp / Makefile
Created August 31, 2012 06:07
Use Makefiles for CoffeeScript, Handlebars, and Sass
COFFEEC = coffee
SASSC = sass
HANDLEBARSC = handlebars
# Build app package
APPSRC = static/scripts/main.coffee
APPOBJ = ${APPSRC:.coffee=.js}
APPOUT = static/scripts/app.js
@jdp
jdp / simposium.py
Created June 1, 2012 06:09
simple object wrapper for simperium
from functools import partial
from urllib2 import HTTPError
from simperium.core import Auth, Api
def setup(app_id, api_key):
class User(object):
_auth = Auth(app_id, api_key)
def __init__(self, username=None, password=None, token=None):
@jdp
jdp / solution.py
Last active February 9, 2016 19:22 — forked from isa/gist:2571012
Convert in less than 30 lines
Question: Convert following into the latter data structure in less than 30 lines:
List:
A, B, C
A, C, E
E, F, D
D, A, J
E, D, J
List
@jdp
jdp / core.py
Created April 27, 2012 06:36
Redis-backed storage engine and DSL for querying tagged data
import hashlib
from collections import namedtuple
import redis
import query
def _tag_keys(tags):
return [("txn:tag:%s" % tag) for tag in tags]
# autocomplete.py - Redis autocomplete example
# download female-names.txt from http://antirez.com/misc/female-names.txt
# Ruby original: http://gist.github.com/574044
# Requires http://github.com/andymccurdy/redis-py/
from redis import Redis
r = Redis()
KEY = 'compl'
@jdp
jdp / bf2c.py
Created March 29, 2012 14:20
Naive brainfuck-to-C compiler
#!/usr/bin/env python
import argparse
import sys
def tokenize(source):
return list(source)
def parse(tokens):
@jdp
jdp / example.php
Created March 26, 2012 00:44
Partial function application with PHP
<?php
function foo($a, $b) {
echo "a: {$a} b: {$b}\n";
}
$foo_caller = new PartialCallable('foo', array('A'));
$foo_caller('B');
$foo_caller = partial_function('foo', 'A');
$foo_caller('B');
@jdp
jdp / session.sh
Created March 11, 2012 07:40
Set up a tmux session with a terminal, mongrel2 started, and CoffeeScript and Less watchers
#!/bin/sh
set -e
# Kill any Mongrels that may be running
if [ -e "run/mongrel2.pid" ]; then
kill -9 `cat run/mongrel2.pid`
fi
# Start a new tmux session
needs_attached=0
@jdp
jdp / git.sh
Created January 27, 2012 21:31
Quick and dirty git sh autocomplete, folder collapse, branch status
source "$HOME/Code/git-sh/git-completion.bash"
git_prompt_info() {
branch_prompt=`echo "$(__git_ps1)" | sed -E "s/\((.+)\)/\1/g" | sed -Ee "s/^[ \t]+//"`
if [ -n "$branch_prompt" ]; then
status_icon=$(git_status)
echo " (± $branch_prompt$status_icon)"
fi
}
@jdp
jdp / LICENSE
Last active April 15, 2022 15:42
A* pathfinding over any arbitrary graph structure, with example Cartesian grid implementation
Copyright (C) 2012 Justin Poliey <justin.d.poliey@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT