Skip to content

Instantly share code, notes, and snippets.

View josiahcarlson's full-sized avatar

Josiah Carlson josiahcarlson

View GitHub Profile
@josiahcarlson
josiahcarlson / zunion_range_score.py
Last active August 29, 2015 13:57
Zunion Range Score, an interesting scripting solution.
'''
Written on March 28, 2014 by Josiah Carlson
Released into the public domain
ZUNIONRANGESCORE:
Zunion Range Score performs a Redis ZUNIONSTORE operation, selecting *only
those items in the provided ranges. The scores are added. Proof of concept.
Warning: untested, use at your own risk.
@josiahcarlson
josiahcarlson / result_multiplex.py
Created October 12, 2014 21:20
Reliably multiplex receiving results via Redis lists
'''
result_multiplex.py
Copyright 2014 Josiah Carlson
Released as LGPL 2 or 3, your choice.
Problem:
You have a task processor that writes the results of tasks to a specified key
@josiahcarlson
josiahcarlson / redis_slots.py
Created November 19, 2014 22:31
Some useful crc utility functions for Redis cluster
'''
Released into the public domain.
This code will append 2 bytes to the end of a key to force the key to a specific Redis slot.
'''
from collections import defaultdict
from itertools import imap
import struct
'''
Copyright 2010 Josiah Carlson
Released into the public domain
alternate_tile.py
This will generate the integer-grid tiles of a provided polygon, similar in
fashion to Polygon.Util.tile(), though this uses a BSP-like algorithm to
partition the space for faster overall execution on large polygons with many
tiles.
@josiahcarlson
josiahcarlson / simple_svn2git.py
Created November 22, 2010 07:42
Convert PyPE's svn repository to git
'''
simple_svn2git.py
Written November 2010 by Josiah Carlson, released into the public domain.
This script was used to convert PyPE's svn repository on sourceforge to git.
Setup included checking out/cloning the two repos:
svn co https://pype.svn.sourceforge.net/svnroot/pype pype
@josiahcarlson
josiahcarlson / streaming_api.py
Created May 20, 2011 09:38
A way of implementing a Twitter-like streaming API without pubsub
'''
streaming_api.py
Written May 17-20, 2011 by Josiah Carlson
Released under the GNU GPL v2
available: http://www.gnu.org/licenses/gpl-2.0.html
Other licenses may be available upon request.
Given a Redis server and a task queue implementation, this code implements the
@josiahcarlson
josiahcarlson / git_prompt.bash
Created October 17, 2011 23:48
shell prompt with colored username, host, and git branch
PS1="\[\e[34;1m\]\[\033[01;34m\]\u@\h\[\033[00m\]\[\e[0m\] \w:\[\e[35;1m\]\`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\\\\\*\ \(.+\)$/\(\\\\\\\\\1\)\/\`\[\033[0m\]$\[\033[0m\] "
@josiahcarlson
josiahcarlson / make-key.sh
Created October 29, 2011 01:49
Create an OpenVPN key and zip it up with encryption for sending to your users.
#!/bin/bash
# Toss me in your /easy-rsa/2.0 path to have a quick and easy way to generat
# a key for a new machine, automatically zipped with encryption into /tmp.
# Requires that you have the below lines uncommented as part of a pre-configured
# client.conf sitting in keys/ .
# cert CHANGEME.crt
# key CHANGEME.key
source ./vars
@josiahcarlson
josiahcarlson / class_property.py
Created January 4, 2012 19:20
Get properties... on classes!
'''
Written January 4, 2012 by Josiah Carlson
Released into the public domain.
I've only ever needed this once, but I had to learn the descriptor protocol.
Works just like a property, except that what you decorate gets the class
instead of the instance.
class Example(object):
@josiahcarlson
josiahcarlson / convert_agile_author_annotations.py
Created February 26, 2012 01:46
Convert Word-style annotations to Agile Author style annotations for Manning books
'''convert_agile_author_annotations.py
Written February 25, 2012 by Josiah Carlson
Released into the public domain.
Did you write your annotions for Agile Author using the Word style?
<example id="...">
<title>title</title>
<programlisting>