Skip to content

Instantly share code, notes, and snippets.

View weaver's full-sized avatar

Ben Weaver weaver

View GitHub Profile
@weaver
weaver / yaml-omap.py
Created February 28, 2010 03:44
Use Python OrderedDict as YAML omap
import yaml
### OrderedDict from <http://pypi.python.org/pypi/ordereddict/1.1>
# Copyright (c) 2009 Raymond Hettinger
#
# 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,
@weaver
weaver / .gitignore
Created October 2, 2012 15:31
S3 Upload Example
node_modules
.#*
*~
@weaver
weaver / x-forwarded-host.php
Created April 30, 2011 17:27
Honor the `X-Forwarded-Host` header for the duration of a single request in WordPress.
<?php
/*
# X-Forwarded-Host #
Honor the `X-Forwarded-Host` header for the duration of a single
request in WordPress.
## Read Me First ##
@weaver
weaver / form.js
Created August 9, 2010 23:24
Express form validation #nodejs
//// form -- form validation
///
/// Represent the structure of a form and use it to validate form
/// data. Here's a Form that describes a create-account form:
///
/// var SignupForm = form.Form('Sign Up')
/// .text('account', 'Account Name', form.required(/[\w-\.]+/))
/// .email('email', 'Email', form.required())
/// .password('password', 'Password', form.required())
/// .password('confirm', 'Confirm', [form.required(), form.equal('password')]);
@weaver
weaver / primes.clj
Created October 16, 2014 13:42
Naive Primes in Clojure
;;; Naive Primes
;;;
;;; Produce a sequence of primes using a naive trial-division
;;; algorithm. This is very slow, but easy to understand at a
;;; glance. It's useful for unit testing.
;;;
;;; Optimizations:
;;;
;;; + Only test odd numbers for primality
;;; + Only do trial division up to the square root
@weaver
weaver / .gitignore
Created April 6, 2011 23:10
Express + Formidable, works with bodyParser and sets req.body correctly.
node_modules
import sys, socket, select, errno
from tornado import ioloop, iostream
### Main Program
def main(kind=None):
if not kind or kind not in ('Original', 'Modified'):
usage()
@weaver
weaver / setup.js
Created August 4, 2010 15:33
Manage library and external dependency folders in your Node.JS project.
//// setup.js -- add packages to require.paths
///
/// Manage library folders and external dependency folders in your
/// project by including setup.js in your project. Call it from the
/// beginning of your project's entry-point to adjust require.paths.
///
/// For example, if you're making an application structured like this:
///
/// README
/// app.js # main program
@weaver
weaver / tornado-webdav.py
Created February 26, 2010 20:06
Run a wsgidav WebDAV server through Tornado
#!/usr/bin/env python
"""tornado-webdav.py -- run a wsgidav server through tornado
This script requires tornado commit id
1ae186a504224e9f6cf5375b56f8e26e4774e2a0. The easiest way to get this
patch is to clone the git repository and install using setup.py:
git clone git://github.com/facebook/tornado.git
cd tornado
@weaver
weaver / org-capture-link.el
Created March 8, 2012 14:16
Capture an org-mode stored link. Add it to the kill-ring in a format suitable for use as a version control commit message.