Skip to content

Instantly share code, notes, and snippets.

@qerub
qerub / null-guard.sjs
Created April 18, 2014 23:36 — forked from aaronpowell/null-guard.sjs
The ?. operator from C# for JavaScript via Sweet.js
// 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 August 29, 2015 14:02
Bash script to exec program in given working directory
#!/bin/bash
# Usage: cwd.sh /app /usr/bin/python example.py
cd $1 && exec "${@:2}"
@qerub
qerub / fancy-defn.clj
Last active August 29, 2015 14:07
[Clojure] fancy-defn: Proof of concept of schema.core/defn augmented with automatically generated clojure.core.typed annotations via circle.schema-typer
(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 August 29, 2015 14:08
Java 8: The Missing Parts, Chapter 1: 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 {
@qerub
qerub / textile+lhs2html.rb
Created November 29, 2009 22:05
textile+lhs2html
#!/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 April 5, 2011 22:56 — forked from EmmanuelOga/xmlindent.rb
XML prettyprinter (implemented with XSLT)
#!/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 23:30
Wrapper for TextMate's mate command that makes it easy to open a particular line
#!/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 19:53
Objective-R: Objective-C-like syntax for method calls in Racket
#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 / gist:2918167
Created June 12, 2012 15:23
The Difference between -> and ->> in Clojure
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))
@qerub
qerub / goto.md
Created July 7, 2012 22:08
[Clojure] Ring middleware for JSONP