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 / 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="' '"/>