Skip to content

Instantly share code, notes, and snippets.

@tolitius
tolitius / src.multi-method.clj
Created January 29, 2012 07:04
clojure bootcamp: "defmulti" example
;; inspired by suggestion in THE doc: http://java.ociweb.com/mark/clojure/article.html
(ns bootcamp.multi-method)
(defn measure-it [size]
(cond
(< size 3) :small
(< size 6) :medium
(< size 12) :large
:else :hard-to-measure ))
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@fredrick
fredrick / README.md
Created November 22, 2011 18:17
Graylog2 Upstart Jobs

#Graylog2 Upstart

A basic set of Upstart jobs to get Graylog2 up and running quickly. Assumes MongoDB and Graylog2 installed in /opt/. Tested on Ubuntu Server 10.04 LTS, MongoDB 2.0.0, graylog2-server-0.9.5p1, and graylog2-web-interface-0.9.5p2.

#Usage

Place job definitions in /etc/init/ and then use service [job] [command] to start/stop/restart/status the services manually. On boot, the services flow into each other, only starting if dependent services have started. For more on controlling jobs or Upstart in general (a replacement for System-V init), see the cookbook.

#Author

@MetaThis
MetaThis / server.js
Created August 25, 2011 22:03
Simple example of a Node.js proxy to CouchDB GET requests
var http = require('http'),
request = require('request'), // request module from https://github.com/mikeal/request
url = require('url');
http.createServer(function (req, res) {
var href = url.parse(req.url,true).href;
request('http://127.0.0.1:5984' + href).pipe(res);
}).listen(1337);
// now try something like http://127.0.0.1:1337/your_db_name/_all_docs/?limit=10
var gistPrefix = 'https://gist.github.com/',
cachedWrite = document.write,
body = $('body'),
gists = $('p.gist').map(function(n, p) {
p = $(p);
var a = $('a', p),
href = a.attr('href');
if (a.length && href.indexOf(gistPrefix) == 0) {
@chrismdp
chrismdp / bootstrap_chef.bash
Created June 15, 2011 07:12 — forked from michaelvobrien/bootstrap_chef.bash
Bootstrap Chef Solo on Ubuntu
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='git@example.com:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 )
# You will need to ensure that the ssh key is already set up on the server.
set -e
export CHEF_DIR="${HOME}/chef"
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
# This is a nginx config snippet showing how to inherit an http header
# or defaulting it to a specific value. This is useful because it allows
# upstream load balancers to set specific headers, but if they're missing
# the app LB will know how to default it.
# This will inherit the previously set X-Scheme variable, or otherwise
# default it to the current `$scheme`. Requires nginx 0.9.0+.
#
# Docs: http://wiki.nginx.org/HttpMapModule#map
map $http_x_scheme $x_scheme {
@stwalkerster
stwalkerster / sfnet2github.sh
Created May 17, 2011 17:18
SourceForge.net svn repo to github git repo import script

Licence (MIT Licence)

Copyright (c) 2011 Simon Walker

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:

@madrobby
madrobby / README.md
Created May 17, 2011 16:34 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000
@fredrick
fredrick / stub.py
Created March 15, 2011 17:07
Dynamically define object variables/methods at instantiation (quick mock)
class Stub(object):
def __init__(self, **kwargs):
for key in kwargs:
setattr(self, key, kwargs[key])