Skip to content

Instantly share code, notes, and snippets.

@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 / svn-diff-color.sh
Created May 8, 2011 23:27
Wrapper for svn diff that sets --diff-cmd=colordiff
#!/bin/sh
# http://colordiff.sourceforge.net/
if tty -s; then
exec svn diff --diff-cmd=colordiff "$@" | less -R
else
exec svn diff --diff-cmd=colordiff "$@"
fi
@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 / x_forwarded_for.clj
Created June 12, 2012 15:06
[Clojure] Ring middleware for `X-Forwarded-For` [:remote-addr rewrite]
(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 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
@qerub
qerub / small-complaints-about-pocket.md
Last active October 7, 2015 11:58
Small Complaints about Pocket
@qerub
qerub / gist:3219854
Last active April 21, 2021 09:46
Representing [Clojure] code in JSON
; Context:
; http://stackoverflow.com/questions/3436216/how-to-map-clojure-code-to-and-from-json
(defn escape-string [x]
(clojure.string/replace x #"^[':\\]" "\\\\$0"))
(defn code-to-json [x]
(condp #(%1 %2) x
number? x
symbol? (str \' (name x))