Skip to content

Instantly share code, notes, and snippets.

@qerub
qerub / small-complaints-about-pocket.md
Last active October 7, 2015 11:58
Small Complaints about Pocket
@qerub
qerub / gist:3786700
Created September 26, 2012 08:01
Run `mvn clean compile` on `git checkout`
$ cat .git/hooks/post-checkout
#!/bin/sh
mvn clean compile
@qerub
qerub / sequel_reconnector.rb
Last active October 11, 2015 03:07
Rack middleware that makes sure requests don't get a dead Sequel connection
require "sequel/extensions/connection_validator"
# https://github.com/jeremyevans/sequel/blob/master/lib/sequel/extensions/connection_validator.rb
module Rack
class SequelConnectionValidator
def initialize(app, db)
@app = app
@db = db
@db.extension(:connection_validator)
@qerub
qerub / gist:4137421
Created November 23, 2012 21:38
Simple Futures in Ruby with Lambdas and Threads
def future # :block:
thread = Thread.new do
Thread.current.abort_on_exception = false
yield
end
lambda { thread.value }
end
def compose(proc) # :block:
@qerub
qerub / char-sequence.clj
Created February 18, 2013 14:57
[Clojure] CharSequence adapter for seqables of chars
(defn char-sequence [char-seqable]
(let [char-seq (seq char-seqable)]
(reify CharSequence
(charAt [this i] (nth char-seq i))
(length [this] (count char-seq))
(toString [this] (String. (char-array char-seq)))
; (subSequence [this start end] ...)
)))
@qerub
qerub / Example.scala
Last active December 15, 2015 07:29
An internal "DSL" in Scala for setting up authorization rules programmatically in ActiveMQ
def authorizationPlugin: BrokerPlugin = {
val dsl = new AuthorizationDSL; import dsl._
val system = Set(User("system"))
entry(Queue(">"), r = system, w = system, a = system)
entry(Topic(">"), r = system, w = system, a = system)
Seq("test").foreach { basename =>
val client = Set(User(basename + "-client"))
@qerub
qerub / gist:5474835
Last active December 16, 2015 18:00
Follow-File for PowerShell
function Follow-File([string] $path) { Get-Content -Path $path -Wait -Tail 10 }
@qerub
qerub / throwf.clj
Created April 28, 2013 13:51
throwf (throw . format) macro for Clojure
(defmacro throwf [class-name format & args]
`(throw (new ~class-name (format ~format ~@args))))
; Before:
(throw (IllegalArgumentException. (format "Invalid value: %s" value)))
; After:
(throwf IllegalArgumentException "Invalid value: %s" value)
@qerub
qerub / cons.cs
Created May 8, 2013 19:06
Cons (i.e. prepend) for IEnumerable in C#
public static IEnumerable<T> Cons<T>(T head, IEnumerable<T> tail)
{
yield return head;
foreach (var t in tail) yield return t;
}
@qerub
qerub / js-lisps.rkt
Last active December 17, 2015 17:29
Having fun with Racket, Rackjure and a list of JavaScript Lisps
#lang rackjure
(require net/url)
(define js-lisps*
(~>> "https://gitorious.org/moritz-stuff/js-lisps/blobs/raw/master/js-lisps.sxml"
string->url
get-pure-port
read))