Skip to content

Instantly share code, notes, and snippets.

View reiddraper's full-sized avatar
🍹

Reid Draper reiddraper

🍹
View GitHub Profile
@shripadk
shripadk / gist:652819
Created October 29, 2010 03:10
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
function Nest(api_key) {
this.api_key = api_key;
}
Nest.prototype = {
analyzeFile: function(file, type, options) {
var form = new FormData();
form.append('api_key', this.api_key);
form.append('track', file);
form.append('filetype', type);
@tekacs
tekacs / show
Created April 20, 2011 17:55
This does something essentially equivalent to showoff.io if you have a publicly facing server...
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".tekacs.com"
REMOTE="$2$DOMAIN"
ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}

KV Operations

The following list illustrates how the Riak KV operations would be specified using different apis. The first sub-entry for each list member represents how the operation is specified in the existing api. The second sub-entry shows the operation in the new proposed api and the final sub-entry uses a shortened syntax of b for buckets and k for keys.

  1. List Buckets
@josephg
josephg / gist:1022202
Created June 13, 2011 01:34
Love coffeescript
# A synchronous processing queue. The queue calls process on the arguments,
# ensuring that process() is only executing once at a time.
#
# process(data, callback) _MUST_ eventually call its callback.
#
# Example:
#
# queue = require 'syncqueue'
#
# fn = queue (data, callback) ->
@pingles
pingles / bytes_to_int.clj
Created September 22, 2011 17:01
Clojure code to convert a byte array to an integer
(defn bytes-to-int
([bytes]
(bytes-to-int bytes 0))
([bytes offset]
(reduce + 0
(map (fn [i]
(let [shift (* (- 4 1 i)
8)]
(bit-shift-left (bit-and (nth bytes (+ i offset))
0x000000FF)
@amtal
amtal / rpn.erl
Created September 25, 2011 04:10
Simple interpreter using a monad for a "mutable" environment.
-module(rpn).
-export([eval/1, hypotenuse/2]).
-compile({parse_transform,do}).
-spec eval([Op]) -> stack_m(ok).
%% Interpreter for a simple stack-based language.
%%
%% Uses a custom stack_m monad, which is a trivial wrapper around state_m[1].
%% It exports:
%% -spec pop() -> stack_m(A).
@gfredericks
gfredericks / flex-config.clj
Created October 17, 2011 18:32
Flexible config via defn-macro
(def *config* nil)
(defn wrap-configged-fn
[f]
(fn [& [maybe-config :as args]]
(if (and *config* (not (identical? *config* maybe-config)))
(apply f *config* args)
(apply f args))))
(defmacro defn-with-config
@AlexBaranosky
AlexBaranosky / gist:1614509
Created January 15, 2012 05:36
Midje `formula`
;; This first swipe at generative-style testing in Midje was super easy:
;; first a use of it
(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
(formula [a (make-string) b (make-string)]
(str a b) => #(.startsWith % a))
@Pet3ris
Pet3ris / fsm.clj
Created January 25, 2012 13:27
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |