Skip to content

Instantly share code, notes, and snippets.

@chocolateboy
chocolateboy / jvm-home.md
Last active June 8, 2018 10:08
Portably determine $GROOVY_HOME, $KOTLIN_HOME, $SCALA_HOME etc.
jvm-home() {
    JAVACMD=$(which echo) "$1" | tr -s '[:space:]' '\n' | grep -F "$1.home=" | cut -d= -f2
}
$ jvm-home groovy
/usr/share/groovy
@chocolateboy
chocolateboy / surprise.md
Last active May 30, 2023 04:41
JSON.stringify doesn't preserve object equivalence

I've even seen implementations that compare objects using JSON.stringify.

I would expect a memoizer and most hash code/table implementations to treat { foo: "bar", baz: "quux" } and { baz: "quux", foo: "bar" } as equivalent, but many implementations use JSON.stringify, which doesn't guarantee this:

$ node
> JSON.stringify({ foo: "bar", baz: "quux" })
'{"foo":"bar","baz":"quux"}'
> JSON.stringify({ baz: "quux", foo: "bar" })
'{"baz":"quux","foo":"bar"}'
@chocolateboy
chocolateboy / elvis.sjs
Last active August 29, 2015 14:15
sweet.js version of Groovy's Elvis operator
// Groovy's Elvis operator
//
// lhs ?: rhs
//
// is equivalent to:
//
// lhs == null ? rhs : lhs
//
// or:
//
@chocolateboy
chocolateboy / gft.vim
Last active August 29, 2015 14:09
GFT: GitHub-Flavored Text for Vim
" name: GitHub-Flavored Text for Vim
"
" description: highlight embedded code blocks with GitHub-Flavored Markdown code fences
"
" based on: http://vim.wikia.com/wiki/VimTip857
"
" keywords: syntax highlighting, single file, same file, multi, multiple, github flavoured text,
" github flavored vim, github flavoured vim, polyglot, guard, guards, fenced
"
" example: