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
export default n => Math.random().toString(35).slice(2, !n || n >= 1097 ? 1099 : n+2) |
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
#!/bin/bash | |
alias lsfiles='for f in *; do [[ -f "$f" ]] && ls -- "$f"; done' | |
alias lsf=lsfiles |
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
'use strict' | |
const serve = require('koa-static') | |
new (require('koa'))() | |
.use(serve(`${__dirname}`)) | |
.use(function* (next) { | |
return this.body = yield new Promise((resolve, reject) => { | |
require('fs').readFile(`${__dirname}/index.html`, 'utf8', | |
(err, body) => resolve(body)) |
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
<div ng-app="app" ng-controller="Controller as vm" directive="directive" promise="vm.promise"></div> |
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
export default function copy(text) { | |
const textArea = document.createElement(`textarea`) | |
textArea.value = text | |
textArea.style.width = `2em` | |
textArea.style.height = `2em` | |
textArea.style.background = `transparent` | |
document.body.appendChild(textArea) | |
textArea.select() | |
const success = document.execCommand(`copy`) | |
document.body.removeChild(textArea) |
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
export default function isEventWithin(e, element) { | |
const rect = element.getBoundingClientRect() | |
return ( | |
rect.top <= e.clientY && | |
e.clientY <= rect.top + rect.height && | |
rect.left <= e.clientX && | |
e.clientX <= rect.left + rect.width | |
) | |
} |
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
^((?!SOME_STRING).)*$ |
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 md = mdColors() | |
const LIGHT = false | |
module.exports = { | |
config: { | |
fontSize: 12, | |
fontFamily: `"Fira Code", "Droid Sans Mono", "DejaVu Sans Mono", "Lucida Console", monospace`, | |
// `BEAM` for |, `UNDERLINE` for _, `BLOCK` for █ | |
cursorShape: `BEAM`, |
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 { Suite } = require('benchmark') | |
const test = (specs = {/*name:fn*/}) => { | |
const suite = new Suite() | |
Object.keys(specs).forEach(name => suite.add(name, specs[name])) | |
suite.on('cycle', e => console.info(String(e.target))) | |
suite.on('complete', () => console.info(`Fastest is ${suite.filter('fastest').map('name')}`)) | |
suite.run({ async: false }) | |
} | |
// // EXAMPLE: |
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
function chunk(array, chunkSize) { | |
if (!chunkSize) throw new Error('chunkSize must be greater than 0') | |
return array.reduce((chunked, value, i) => { | |
if (!(i % chunkSize)) chunked.push([]) | |
chunked[chunked.length - 1].push(value) | |
return chunked | |
}, []) | |
} |