Skip to content

Instantly share code, notes, and snippets.

qerub / null-guard.sjs
Created Apr 18, 2014 — forked from aaronpowell/null-guard.sjs
The ?. operator from C# for JavaScript via Sweet.js
View null-guard.sjs
// This version allows LHS to be any expression
// (and makes sure it's only evaluated once by storing the result)
let (?.) = macro {
rule infix { $lhs:expr | $rhs:ident } => {
(function ($tmp) {
return $tmp === null ? null : $tmp.$rhs;
qerub /
Last active Feb 27, 2018
Servlet filter for forcing HTTPS when behind a SSL termination proxy that sends X-Forwarded-Proto
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static java.lang.String.format;
public class HttpsFilter implements Filter {
qerub / sum-time-durations.clj
Created Jan 18, 2014
Summing time durations (given as a string) with Clojure and Joda-Time
View sum-time-durations.clj
;; lein try joda-time org.clojure/algo.generic
;; Let's first shave the parsing yak:
(import (org.joda.time.format PeriodFormatterBuilder))
(def h:m-formatter
(-> (PeriodFormatterBuilder.)
(.appendSeparator ":")
qerub / spiped-ssh.plist
Created Dec 19, 2013
Piping sshd through spiped running as an OS X launch daemon
View spiped-ssh.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
qerub / string-split-benchmarks-result.txt
Last active Dec 31, 2015
[Clojure/Java] Benchmarks of different ways of splitting a string by a char
View string-split-benchmarks-result.txt
# Benchmarking (.split test-input "\\.")
Evaluation count : 72101040 in 60 samples of 1201684 calls.
Execution time mean : 828.458928 ns
Execution time std-deviation : 29.055494 ns
Execution time lower quantile : 800.771006 ns ( 2.5%)
Execution time upper quantile : 895.752028 ns (97.5%)
Overhead used : 2.778847 ns
Found 5 outliers in 60 samples (8.3333 %)
qerub / ScalazLight.scala
Created Dec 18, 2013
Scalaz Light (The Good[^W]Indispensable Parts)
View ScalazLight.scala
import scalaz._
trait ScalazLight
extends std.AllInstances
with syntax.std.ToOptionIdOps
with syntax.std.ToOptionOps
with syntax.ToEqualOps
with syntax.ToIdOps
qerub / StringExtensions.scala
Created Dec 18, 2013
Bringing Perl's (main) regex operators to [Scala] (just for fun)
View StringExtensions.scala
implicit class StringExtensions(val _value: String) extends AnyVal {
def =~(r: Regex): Boolean = _value match {
case `r`() => true
case `r`(xs @ _*) => throw new IllegalArgumentException("Regex must not contain captures")
case _ => false
def !~(r: Regex): Boolean = !(this =~ r)
qerub / for-map-benchmarks.clj
Created Nov 27, 2013
[Clojure] Benchmarks for different implementations of `for-map`
View for-map-benchmarks.clj
;; Benchmarks for different implementations of `for-map`
;; Can be run with `lein try proteus criterium`
;; See
;; for some relevant discussion.
(defn pairs-to-map-without-transient [pairs]
(reduce (fn [m [k v]] (assoc m k v)) {} pairs))
qerub /
Created Nov 27, 2013
Augmenting JRuby Complete with Bundler: a full JRuby installation in a single JAR file
set -ex
curl -o $jar$version/jruby-complete-$version.jar
qerub / exception_with_a_cause.rb
Created Nov 26, 2013
[Ruby] Exception with a cause :)
View exception_with_a_cause.rb
class ExceptionWithACause < StandardError
attr_reader :cause
def initialize(message = nil, cause = nil)
@message = message
@cause = cause
You can’t perform that action at this time.