This gist is for my talk Faster JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://stackoverflow.com/questions/38090023/whats-the-lodash-fp-equivalent-of-ramdas-evolve-function/38425764#38425764 | |
| const mapValuesWithKey = _.mapValues.convert({cap: false}); | |
| function evolve(transformations) { | |
| return item => | |
| mapValuesWithKey((value, key) => { | |
| const transformation = _.getOr(_.identity)(key)(transformations); | |
| const type = typeof transformation; | |
| return type === 'function' ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xinput list --short | grep Logitech | awk '{print $5}' | cut -f2 -d"=" | xargs -I id xinput set-prop id "Device Accel Constant Deceleration" 0.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Async version of Array.prototype.reduce() | |
| * await reduce(['/foo', '/bar', '/baz'], async (acc, v) => { | |
| * acc[v] = await (await fetch(v)).json(); | |
| * return acc; | |
| * }, {}); | |
| */ | |
| export async function reduce(arr, fn, val, pure) { | |
| for (let i=0; i<arr.length; i++) { | |
| let v = await fn(val, arr[i], i, arr); | |
| if (pure!==false) val = v; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Async version of Array.prototype.reduce() | |
| * await reduce(['/foo', '/bar', '/baz'], async (acc, v) => { | |
| * acc[v] = await (await fetch(v)).json(); | |
| * return acc; | |
| * }, {}); | |
| */ | |
| export async function reduce(arr, fn, val, pure) { | |
| for (let i=0; i<arr.length; i++) { | |
| let v = await fn(val, arr[i], i, arr); | |
| if (pure!==false) val = v; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| language: node_js | |
| node_js: | |
| - "6" | |
| env: | |
| - CXX=g++-4.8 | |
| addons: | |
| apt: | |
| sources: | |
| - ubuntu-toolchain-r-test | |
| packages: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| function $_GET(name, url) { | |
| if (!url) { | |
| url = window.location.href; | |
| } | |
| name = name.replace(/[\[\]]/g, "\\$&"); | |
| const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"); | |
| const results = regex.exec(url); | |
| if (!results) { | |
| return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str.split(',') | |
| .map(section => section.split(';')) | |
| .map(([page, rel]) => [ | |
| Number(rxPage.exec(page)[1]), | |
| rxRel.exec(rel)[1] | |
| ]).reduce((acc, [ page, rel ]) => ( | |
| {...acc, [rel]: page}), {} | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void doSwitchToAP() { | |
| final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); | |
| final WifiApControl wifiApControl = WifiApControl.getInstance(this); | |
| if (wifiApControl.isEnabled()) { | |
| WifiConfiguration config = wifiApControl.getConfiguration(); | |
| if (config.SSID.equals(HOTSPOT_SSID) && config.preSharedKey.equals(HOTSPOT_PWD)) { | |
| Utilities.longToast("Already configured as hotspot!"); | |
| } | |
| } | |
| final WifiConfiguration apConfig = new WifiConfiguration(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const reduce = (reducer, initial, [head, ...tail]) => | |
| head // condition to go or stop | |
| ? reduce(reducer, reducer(initial, head), tail) // recursion | |
| : initial // stop | |
| const map = (mapper, [head, ...tail]) => | |
| head // condition to go or stop | |
| ? [ mapper(head), ...map(mapper, tail) ] //recursion | |
| : [] // stop |