This file contains 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
// Test it... | |
console.log( | |
expandBraces('test-{a,b,c}-test') | |
); | |
/* test-a-test test-b-test test-c-test */ | |
function expandBraces(str) { | |
let { preamble, expressionList, postscript } = parse(str); | |
return expressionList |
This file contains 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 { Observable } = require('rxjs/Observable'); | |
require('rxjs/add/operator/filter'); | |
require('rxjs/add/operator/switchMap'); | |
require('rxjs/add/operator/take'); | |
require('rxjs/add/operator/toPromise'); | |
const axios = require('axios'); | |
const online$ = createOnline$(); | |
//only make the network request when we're online |
This file contains 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
data_uri() { | |
if [[ "$#" -ne 1 ]] || [[ ! -f $1 ]]; then | |
echo "ERROR! Usage: ${FUNCNAME[0]} <file name>" | |
return 1 | |
fi | |
mime=$(file -b --mime-type "$1") | |
data=$(base64 "$1") | |
echo "data:$mime;base64,$data" | |
} |
This file contains 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
// Working example: https://jsfiddle.net/ccnokes/790xaw53/ | |
class Storage { | |
constructor(key = location.origin + '/cache-key-v1') { | |
this.KEY = key; | |
} | |
get(id) { | |
return caches.open(this.KEY) | |
.then(cache => cache.match(id)) |
This file contains 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 | |
number=$(echo $((1 + RANDOM % 20))) | |
msg="" | |
case $number in | |
1) msg="It is certain.";; | |
2) msg="It is decidedly so.";; | |
3) msg="Without a doubt.";; | |
4) msg="Yes - definitely.";; |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline';"> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<!-- All of the Node.js APIs are available in this renderer process. --> |
This file contains 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
import * as React from 'react'; | |
// see https://github.com/Microsoft/TypeScript/pull/13743 for what the typing in here's all about | |
type Constructor<T> = new (...args: any[]) => T; | |
const isMounted_Symbol = Symbol('isMounted'); | |
/** | |
* This is for when you're calling setState in uncancellable async callbacks. | |
* NOTE: Doing this can mask memory leaks so be careful |
This file contains 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
// dummy async task | |
function asyncTask(n) { | |
return new Promise(resolve => setTimeout(() => resolve(n), 500)); | |
} | |
// takes a flat array and returns a nested one, eg. chunkArray([1,2,3], 1) ==> [[1],[2],[3]] | |
function chunkArray(arr, chunkSize) { | |
return arr.reduce((aggr, item) => { | |
let lastArr = aggr[aggr.length - 1]; | |
if (lastArr.length < chunkSize) { |
This file contains 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
class Middleware { | |
private middlewares = []; | |
push(...middlewares) { | |
this.middlewares.push.apply(this.middlewares, middlewares); | |
} | |
run(...args) { | |
let i = 0; | |
const next = () => { | |
if (i < this.middlewares.length) { |
This file contains 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
import * as React from 'react'; | |
export default function withProps<InjectProps, Props = {}>(Component: React.ComponentType<Props & InjectProps>, props: InjectProps): React.ComponentClass<Pick<Props, Exclude<keyof Props, keyof InjectProps>>> { | |
return class extends React.Component<Props> { | |
static displayName = `withProps(${Component.displayName || Component.name})`; | |
static WrappedComponent = Component; | |
render() { | |
return <Component {...this.props} {...props} /> | |
} | |
} |