Skip to content

Instantly share code, notes, and snippets.

View RGBz's full-sized avatar
🌿

Anton RGBz

🌿
View GitHub Profile
@RGBz
RGBz / example.js
Created October 26, 2021 16:02
Deleting from an optional chain
const x = { y: 1 };
// Delete a key that doesn't exist from an optional chain
delete x?.y?.z;
// This results in:
// > {"y":1}
console.log(JSON.stringify(x));
@RGBz
RGBz / truncate-abbr
Created December 22, 2011 17:20
Grails truncate tag with abbr
def truncate = { attrs, body ->
if (body().length() > attrs.maxlength.toInteger()) {
out << """<abbr title="${body()}">${body()[0..attrs.maxlength.toInteger() - 1]}...</abbr>"""
} else {
out << body()
}
}