Skip to content

Instantly share code, notes, and snippets.

Ben Weaver weaver

Block or report user

Report or block weaver

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@weaver
weaver / primes.clj
Created Oct 16, 2014
Naive Primes in Clojure
View primes.clj
;;; 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 Oct 2, 2012
S3 Upload Example
View .gitignore
node_modules
.#*
*~
@weaver
weaver / org-capture-link.el
Created Mar 8, 2012
Capture an org-mode stored link. Add it to the kill-ring in a format suitable for use as a version control commit message.
View org-capture-link.el
@weaver
weaver / x-forwarded-host.php
Created Apr 30, 2011
Honor the `X-Forwarded-Host` header for the duration of a single request in WordPress.
View x-forwarded-host.php
<?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 Apr 6, 2011
Express + Formidable, works with bodyParser and sets req.body correctly.
View .gitignore
node_modules
@weaver
weaver / express-nested-server-middleware-bug.js
Created Mar 14, 2011
When nested middleware is used, the `res.app` and `req.app` properties aren't restored when outerNext is called.
View express-nested-server-middleware-bug.js
// 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 Mar 11, 2011
Convert dates to strings
View json-date.py
import json
from datetime import datetime
class Foo(object):
def __init__(self, when):
self.when = when
def __json__(self):
return self.__dict__
@weaver
weaver / stack1.js
Created Feb 10, 2011
Use stack introspection to determine the filename of a calling script.
View stack1.js
// 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 Feb 6, 2011
Node vs Scheme vs Ruby vs Python web server benchmarks.
View .gitignore
gambit-server/web-server
snap-hello-server/bin
snap-hello-server/dist/
You can’t perform that action at this time.