Skip to content

Instantly share code, notes, and snippets.

@mearns
mearns / .gitignore
Created April 10, 2019 16:59
Source map support for Babel and Mocha
node_modules/
build/
dist/
// `npm install --save build-object-better`
const bob = require('build-object-better')
const dayNamesInOrder = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const daysOfTheWeek = bob(dayNamesInOrder, (dayName, idx) => idx)
const studentGradeCache = bob(studentNames, lookupStudentGrade)
const perfectSquaresMemo = bob([
0, 1, 2, 3, 4, 5, 6
const dayNamesInOrder = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const daysOfTheWeek = dayNamesInOrder.reduce((obj, dayName, index) => {
obj[dayName] = index
return obj
}, {})
const studentGradeCache = studentNames.reduce((cache, studentName) => {
cache[studentName] = lookupStudentGrade(studentName)
return cache
}, {})
// Based on : https://github.com/aemkei/jsfuck/blob/master/jsfuck.js
_zero = +[] // 0
_false = !!+[] // false
_falseStr = !!+[]+[] // 'false'
_f = (!!+[]+[])[+[]] // 'f' <= 'false'[0]
_undefined = [][[]] // undefined <= [][''] (the property named '' on the array object, which is undefined (property accessors are always cast to strings))
_undefinedStr = [][[]]+[] // 'undefined'
import java.util.function.Consumer;
import java.util.function.Supplier;
public class CheckBox {
private Consumer<Boolean> mutable = this::setState;
private Supplier<Boolean> readOnlyView = this::getState;
/* ... */
}
public class CheckBox {
private MutableCheckbox mutable = null;
private ReadOnlyCheckbox readOnlyView = null;
/* ... */
// Provide the view interface for the Controller.
public MutableCheckbox getMutable () {
if (mutable == null) {
public class CheckBox {
private final MutableCheckbox mutable = this::setState;
private final ReadOnlyCheckbox readOnlyView = this::getState;
/* ... */
// Provide the view interface for the Controller.
public MutableCheckbox getMutable () {
return mutable;
public class CheckBox {
/* ... */
// Provide the view interface for the Controller.
public MutableCheckbox getMutable () {
return this::setState;
}
// Provide the read-only view interface.
public class CheckBox {
/* ... */
// Provide the view interface for the Controller.
public MutableCheckbox getMutable () {
return isChecked -> CheckBox.this.setState(isChecked);
}
// Provide the read-only view interface.
class CheckBoxSystem {
CheckBoxSystem () {
CheckBox checkBox = new CheckBox(false);
CheckBoxController controller = new CheckBoxController(checkBox);
CheckBoxViewer viewer = new CheckBoxViewer(checkBox);
// ...
}
}