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 / 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="' '"/>
You can’t perform that action at this time.