Skip to content

Instantly share code, notes, and snippets.

@qerub
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;
})($lhs)
}
}
@qerub
qerub / cwd.sh
Last active Aug 29, 2015
Bash script to exec program in given working directory
View cwd.sh
#!/bin/bash
# Usage: cwd.sh /app /usr/bin/python example.py
cd $1 && exec "${@:2}"
@qerub
qerub / fancy-defn.clj
Last active Aug 29, 2015
[Clojure] fancy-defn: Proof of concept of schema.core/defn augmented with automatically generated clojure.core.typed annotations via circle.schema-typer
View fancy-defn.clj
(ns fancy-defn
(:require [schema.core :as s]
[clojure.core.typed :as t]
[circle.schema-typer :as st]))
;; Schemas created with s/defn end up using this.
(defmethod st/convert schema.core.One [schema]
(assert (= false (:optional? schema))) ;; No support for optional arguments yet.
(st/convert (:schema schema)))
@qerub
qerub / Optionals.java
Last active Aug 29, 2015
Java 8: The Missing Parts, Chapter 1: Optionals.java
View Optionals.java
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
public class Optionals {
View textile+lhs2html.rb
#!/usr/bin/env ruby
#
# textile+lhs2html
#
# A script for transforming Literate Haskell
# with Textile-formatted text to HTML with
# the help of Ruby and RedCloth.
#
# Written by Christoffer Sawicki in 2009.
# Released into the public domain.
@qerub
qerub / xmlindent.rb
Created Apr 5, 2011 — forked from EmmanuelOga/xmlindent.rb
XML prettyprinter (implemented with XSLT)
View xmlindent.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
XSL = <<-EOXSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:param name="indent-increment" select="' '"/>
@qerub
qerub / mate-line.rb
Created May 8, 2011
Wrapper for TextMate's mate command that makes it easy to open a particular line
View mate-line.rb
#!/usr/bin/env ruby
ARGV.each do |arg|
name, line = arg.split(":")
system("mate", name, "--line", line)
end
@qerub
qerub / gist:969308
Created May 12, 2011
Objective-R: Objective-C-like syntax for method calls in Racket
View gist:969308
#lang racket ; Requires Racket >= 5.1.1
(provide (rename-out (objective-r-read read)
(objective-r-read-syntax read-syntax)))
(require syntax/stx)
(define (rewrite-method-calls stx)
(if (stx-list? stx)
(let ((stx* (stx-map rewrite-method-calls stx)))
@qerub
qerub / x_forwarded_for.clj
Created Jun 12, 2012
[Clojure] Ring middleware for `X-Forwarded-For` [:remote-addr rewrite]
View x_forwarded_for.clj
(ns ring.middleware.x-forwarded-for
(:use [clojure.string :only (split)]))
(defn wrap-x-forwarded-for [handler]
(fn [request]
(if-let [xff (get-in request [:headers "x-forwarded-for"])]
(handler (assoc request :remote-addr (last (split xff #"\s*,\s*"))))
(handler request))))
@qerub
qerub / gist:2918167
Created Jun 12, 2012
The Difference between -> and ->> in Clojure
View gist:2918167
user=> (use 'clojure.walk)
nil
user=> (macroexpand-all '(-> x (1 a) (2 b)))
(2 (1 x a) b)
user=> (macroexpand-all '(->> x (1 a) (2 b)))
(2 b (1 a x))
You can’t perform that action at this time.