Skip to content

Instantly share code, notes, and snippets.

View weaver's full-sized avatar

Ben Weaver weaver

View GitHub Profile
@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 October 2, 2012 15:31
S3 Upload Example
node_modules
.#*
*~
@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.
@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 / .gitignore
Created April 6, 2011 23:10
Express + Formidable, works with bodyParser and sets req.body correctly.
node_modules
@weaver
weaver / express-nested-server-middleware-bug.js
Created March 14, 2011 21:08
When nested middleware is used, the `res.app` and `req.app` properties aren't restored when outerNext is called.
// In Express 1.0.8, the `res.app` and `req.app` properties aren't restored when
// outerNext() is called by nested server middleware.
//
// Run this script, then try to visit something handled by the `notFound()` middleware
// (e.g. `http://localhost:3000/mumble`. An assertion error is raised because `res.app`
// is equal to the `middleware()` instead of `app`.
var Assert = require('assert'),
Express = require('express'),
app = Express.createServer();
@weaver
weaver / json-date.py
Created March 11, 2011 20:39
Convert dates to strings
import json
from datetime import datetime
class Foo(object):
def __init__(self, when):
self.when = when
def __json__(self):
return self.__dict__
.packages
*.pyc
@weaver
weaver / stack1.js
Created February 10, 2011 23:00
Use stack introspection to determine the filename of a calling script.
// An example of how to use stack introspection to determine the
// filename of a calling script.
//
// node stack1.js
//
function blah() {
require('./stack2');
}
@weaver
weaver / .gitignore
Created February 6, 2011 18:39
Node vs Scheme vs Ruby vs Python web server benchmarks.
gambit-server/web-server
snap-hello-server/bin
snap-hello-server/dist/