See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope> is optional
| const all = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a && b, true) | |
| const any = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a || b, false) | |
| const oneOf = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a ? !b : b, false) | |
| const has = (prop) => (obj) => obj[prop] !== undefined | |
| const not = (pred) => (obj) => !pred(obj) | |
| const equals = (prop, val) => (obj) => obj[prop] === val | |
| const implies = (f, g) => (obj) => !f(obj) || g(obj); | |
| const validate = all(implies(has('selectedIndex'), equals('isOpen', true))) |
| require('crypto').randomBytes(48, function(err, buffer) { var token = buffer.toString('hex'); console.log(token); }); |
| #!/bin/bash | |
| # file: ttfb.sh | |
| # curl command to check the time to first byte | |
| # ** usage ** | |
| # 1. ./ttfb.sh "https://google.com" | |
| # 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com" | |
| curl -o /dev/null \ | |
| -H 'Cache-Control: no-cache' \ | |
| -s \ |
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
// see: https://github.com/chadoe/docker-cleanup-volumes
$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
| type BatchLoadFn<K, V> = (keys: Array<K>) => Promise<Array<V | Error>>; | |
| type LoadAllFn<K, V> = () => Promise<Array<[K, V]>>; | |
| type Options<K, V> = { | |
| batch?: boolean, | |
| cache?: boolean, | |
| cacheMap?: CacheMap<K, Promise<V>>, | |
| cacheKeyFn?: (key: any) => any | |
| }; |
| function weightedRandom(ar) { | |
| var ar = ar.sort(x => x.w); | |
| var sum = ar.reduce((p, c) => p + c.w, 0); | |
| // normalise | |
| var soFar = 0; | |
| ar.map(o => { | |
| o.w = o.w / sum; | |
| o.w += soFar; | |
| soFar += o.w; | |
| }); |
| #!/usr/bin/env python3 | |
| import sys | |
| import os | |
| def curl_to_ab(curl_cmd: list, num: int=200, cur: int=4) -> str: | |
| """ | |
| Translate a cURL command created by Chrome's developer tools into a | |
| command for ``ab``, the ApacheBench HTTP benchmarking tool. |
React introduced shallow rendering in 0.13. This is an excellent feature that I wish was included earlier in React. It aims to solve the problem of unit testing components without going through a real, or jsdom mocked, DOM. I couldn't find any info online about what lifecycle events it actually fires. So I did some testing of my own. To reproduce, put component.js and test.js into a folder and run node test.js.
TLDR; shallow rendering only invokes the following lifecycle hooks (in order):
getDefaultPropsgetInitialStatecomponentWillMount stops here until re-rendercomponentWillReceivePropsshouldComponentUpdatecomponentWillUpdate| var mediaJSON = { "categories" : [ { "name" : "Movies", | |
| "videos" : [ | |
| { "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ], | |
| "subtitle" : "By Blender Foundation", | |
| "thumb" : "images/BigBuckBunny.jpg", | |
| "title" : "Big Buck Bunny" | |
| }, | |
| { "description" : "The first Blender Open Movie from 2006", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ], |