Skip to content

Instantly share code, notes, and snippets.

@rebelliard
rebelliard / flatten.js
Created July 27, 2016 03:09
Flatten array in JavaScript
// Input:
// [[1,2,[3]],4]
// Output:
// [1,2,3,4]
Array.prototype.flatten = function() {
return this.reduce(function(previousValue, currentValue) {
let value = Array.isArray(currentValue) ? currentValue.flatten() : currentValue;
return previousValue.concat(value);
}, new Array());
}
@rebelliard
rebelliard / .flowconfig
Created April 6, 2017 17:35
Generated .flowconfig on react-native 0.43.1 with only an updated flow-bin version at 0.43.1
[ignore]
; We fork some components by platform
.*/*[.]android.js
; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/
; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*
@rebelliard
rebelliard / cycle_mouse_on_display.py
Last active December 7, 2017 20:36
[Ubuntu] Cycle the mouse between displays
#!/usr/bin/python3
'''
[Ubuntu] Cycle the mouse between displays.
Suggestion: setup keyboard shortcuts such as:
- "super + tab" to "cycle_mouse_on_display.py"
- "super + shift + tab" to "cycle_mouse_on_display.py --reverse"
- Tested on Ubuntu 17.04.
@rebelliard
rebelliard / flatten.js
Created February 2, 2018 13:45
Flatten array
/**
* Recursively flatten an array.
* @example
* input: [[1,2,[3]],4]
* output: [1,2,3,4]
**/
function flatten(current) {
let accumulator = []
if (Array.isArray(current)) {
// Process the nested array.