Skip to content

Instantly share code, notes, and snippets.

@jdp
jdp / redis-delkeys.sh
Created August 21, 2013 19:19
Delete keys matching a pattern from Redis
#!/bin/sh
#
# Usage: ./redis-delkeys.sh [-h host] [-p port] [-n db] pattern
#
# Matches keys with the KEYS command matching pattern
# and deletes them from the specified Redis DB.
set -e
HOST="localhost"
@jdp
jdp / searchindex.py
Created November 25, 2012 00:06
Autocomplete search with Redis and Python
from functools import partial
from itertools import imap, izip, product
from redis import Redis
class SearchIndex(object):
"""Autocomplete search index.
>>> index = SearchIndex(Redis())
@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):
@jdp
jdp / countmin.py
Created April 7, 2013 15:49
example count-min sketch implementation
import random
class CountMinSketch(object):
def __init__(self, w, d, p):
self.w = w
self.d = d
self.p = p
self.C = [[0] * self.w for _ in range(self.d)]
self.a = [random.randint(1, self.p) for _ in range(self.d)]
@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
@jdp
jdp / Rationale.md
Created July 21, 2011 21:44 — forked from leegao/Rationale.md
JIT for dummies: JIT compiling RPN in python

If you don't care about the explanation, scroll down to find the code, it's 50 some odd lines and written by someone who doesn't know any better. You have been warned.

What it does

This is a very simple proof of concept jitting RPN calculator implemented in python. Basically, it takes the source code, tokenizes it via whitespace, and asks itself one simple question: am I looking at a number or not?

First, let's talk about the underlying program flow. Pretend that you are a shoe connoisseur with a tiny desk. You may only have two individual shoes on that desk at any one time, but should you ever purchase a new one or get harassed by an unruly shoe salesman without realizing that you have the power to say no (or even maybe?), you can always sweep aside one of the two shoes on the desk (the one on the right, because you're a lefty and you feel that the left side is always superior) onto the messy floor, put the other shoe on the right hand side, and then place your newly acquired shoe in

@jdp
jdp / refactor.py
Created December 7, 2010 04:59
A toy tail-recursive concatenative language implementation
#!/usr/bin/env python
import sys
import types
import operator
class Runtime:
def __init__(self, env={}, stack=[]):
self.env = {
# Primitive words, not an impressive base but it works
@jdp
jdp / spotlight.py
Created February 4, 2016 13:39
Run Spotlight queries from console in Python
#!/usr/bin/env python
# encoding: utf-8
from AppKit import *
from Foundation import *
from Cocoa import *
from PyObjCTools import AppHelper
@jdp
jdp / redis-movekeys.sh
Created August 22, 2013 22:24
Move keys matching pattern from one database to another
#!/bin/sh
#
# Usage: ./redis-movekeys.sh [-h host] [-p port] [-n src] [-m dest] pattern
#
# Move keys matching pattern from the src Redis database to the
# dest Redis database.
set -e
HOST="localhost"
@jdp
jdp / JsonParser.io
Created January 3, 2009 03:13
Simple JSON parser for Io
/*
* JsonParser.io
* A simple JSON parser for Io
* Copyright (c) 2008 Justin Poliey <jdp34@njit.edu>
*
* 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