Skip to content

Instantly share code, notes, and snippets.

@chocolateboy
chocolateboy / jvm-home.md
Last active Jun 8, 2018
Portably determine $GROOVY_HOME, $KOTLIN_HOME, $SCALA_HOME etc.
View jvm-home.md
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 Feb 5, 2020
JSON.stringify doesn't preserve object equivalence
View surprise.md

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 Aug 29, 2015
sweet.js version of Groovy's Elvis operator
View elvis.sjs
// Groovy's Elvis operator
//
// lhs ?: rhs
//
// is equivalent to:
//
// lhs == null ? rhs : lhs
//
// or:
//
@chocolateboy
chocolateboy / gft.vim
Last active Aug 29, 2015
GFT: GitHub-Flavored Text for Vim
View gft.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:
You can’t perform that action at this time.