Skip to content

Instantly share code, notes, and snippets.

View typeof.js
typeof undefined // 'undefined'
typeof null // 'object'
View toString.js
({}).toString() // '[object Object]'
[].toString() // ''
View valueOf.js
({}).valueOf() // {}
[].valueOf() // []
View slice.js
[1,2,3].slice(0, null) // []
[1,2,3].slice(0, undefined) // [1,2,3]
@BohdanLevchenko
BohdanLevchenko / SafeJson.java
Created Oct 11, 2017
Json helper for nullable properties
View SafeJson.java
import javax.json.*;
/**
* Usage:
* class SomeClass {
* //...
* public JsonValue toJson() {
* return Json.createObjectBuilder().add("id", this.someId)
* .add("zipCode", SafeJson.nvl(this.someNullableInt))
* .add("phone", SafeJson.nvl(this.someNullableString))
View repeating-values.sh
> 0.1.toString(2)
'0.0001100110011001100110011001100110011001100110011001101'
> 0.2.toString(2)
'0.001100110011001100110011001100110011001100110011001101'