Skip to content

Instantly share code, notes, and snippets.

@jdp
jdp / fenwick.py
Last active June 28, 2019 17:01
Fenwick Range Tree (Binary Indexed Tree) on top of Redis
import sys
from calendar import timegm
from collections import Counter, defaultdict
from datetime import datetime, timedelta
import redis
class DictBackend(object):
def __init__(self, maximum=None):
@jdp
jdp / SketchSystems.spec
Last active August 7, 2018 19:59
Logged-out
Logged-out
Login
success -> Project List
failure -> Login
Logged-in*
search -> Search Results
logout -> Login
Project List
@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 / bleb.php
Created July 8, 2010 07:03
BlebCT's PHP framework
<?php
/**
* The Bleb PHP Framework
*
* @author Justin Poliey <jdp34@njit.edu>
* @copyright BlebCT 2010
* @package bleb
*/
namespace Bleb {
@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 / golf.sh
Last active April 29, 2016 22:53
Solution to Daily Programmer 264
awk 'NF {print $NF}' | tr a-z A-Z | tr -d .,\"—\; |
xargs -n 1 -I % grep '^% ' cmudict-0.7b |
perl -lne 'if (/.*\b((AA|AE|AH|AO|AW|AY|EH|ER|EY|IH|IY|OW|OY|UH|UW).*)/) {print $1}' |
tr -d 0-9 | awk 'BEGIN{i=1} !seen[$0] {seen[$0]=i++} {print seen[$0]}' | tr 1-9 a-j | tr -d '\n'
@jdp
jdp / server.py
Created February 10, 2016 06:55
Serve directory listing kinda like a GitHub project page
#!/usr/bin/env python
import cgi
import os
import mistune
from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import TCPServer
from cStringIO import StringIO
@jdp
jdp / example
Last active March 11, 2016 00:06
Generate a population following a distribution
$ mkpop -i pokemon 100 zipf | sort | uniq -c | sort -rn
68 hoopa
12 diancie
7 zygarde
3 yveltal
2 xerneas
1 volcanion
1 trevenant
1 pumpkaboo
1 noivern
@jdp
jdp / crunch.py
Created February 17, 2016 08:18
Toy URL shortener with Flask, Redis, and BaseConverter
from baseconv import BaseConverter
from flask import Flask, abort, make_response, redirect, request, url_for
from flask.ext.redis import FlaskRedis
app = Flask(__name__)
store = FlaskRedis(app)
converter = BaseConverter('23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')
@app.route('/<shortcode>')
@jdp
jdp / redux-storage-engine-file.js
Created February 16, 2016 20:31
Atomic file storage engine for redux-storage
import fs from 'fs';
import tmp from 'tmp';
export default (filename) => ({
load() {
return new Promise((resolve, reject) => {
fs.readFile(filename, (err, contents) => {
if (err) {
if (err.code === 'ENOENT') {
resolve({})