- dom builder examples https://jsfiddle.net/crl/tfo58xmt/5/ https://jsfiddle.net/crl/7jo9zp5t/22/
- like
<input type="search">
but not https://jsfiddle.net/364Lbu1w/3/ - contenteditable https://jsfiddle.net/crl/eumxoudn/39/ react https://jsfiddle.net/crl/eumxoudn/11/
- designs address form | list | checkbox | increment buttons /5 | button | dropdown | circle nav
- fps-meter https://output.jsbin.com/banewul/
- play with unicodes https://jsfiddle.net/crl/s0xbrwv5/10/, golden ratio https://jsfiddle.net/crl/bveyL2uf/6/
- slot machine https://jsfiddle.net/crl/sbh0hrfu/
- canvas vs svg https://jsfiddle.net/crl/vbtbm83k/17/
- cancellable fetch https://jsfiddle.net/crl/8ns0abst/6/
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
create table foo ( | |
id bigserial primary key, | |
prev bigint | |
); | |
insert into foo(id, prev) values | |
(1, NULL), | |
(2, 1), | |
(4, 2), | |
(12, 4), |
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 | |
regexp='^[-+]?[0-9]*(\.[0-9]*)?$' | |
validateNumber() { | |
if [[ $1 == *[0-9]* && $1 =~ $regexp ]]; then | |
echo "$1" | |
else | |
printf >&2 '%s is not a valid number\n' "$1" | |
fi | |
} |
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
/** | |
This middleware enhances redux-thunk, to deal with asynchronous actions | |
conventions and usage: | |
- an action is a plain object `{type: TYPE_CONSTANT, value: ANY_VALUE}` or an array of those actions (handled by reducer) | |
- you can shape action creators as `queryArgs => promise` (where the promise returns an action) | |
- or `queryArgs => action` (where the action value is a promise). | |
examples: | |
const getProfile = id => ({ type: GET_PROFILE, value: fetchApi(`/profile/${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
import { graphql } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const TodoApp = ({ loading, error, data: { todos, refetch }, ...props }) => { | |
if (loading) return <p>Loading...</p>; | |
if (error) return <p>Error :(</p>; | |
return ( | |
<div {...props}> | |
<button onClick={() => refetch()}>Refresh</button> | |
<ul>{todos && todos.map(todo => <li key={todo.id}>{todo.text}</li>)}</ul> |
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 React from 'react'; | |
/** | |
* Simple HOC, taking a fetcher function (returning a promise) then a Component | |
* @returns Component accepting a ({ data, error, loading }) => {..} function as children | |
*/ | |
export default fetcher => Component => | |
class extends React.PureComponent { | |
state = { loading: true, data: [], error: undefined }; |
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 DIR = os.homedir() + '/.foo'; | |
// adapted from https://stackoverflow.com/a/24977085/3183756 | |
const downloadFromFs = (req, res) => { | |
const { name } = req.params; | |
const filePath = path.join(DIR, name); | |
fs.stat(filePath, (err, stats) => { | |
if (err) { | |
if (err.code === 'ENOENT') { | |
// 404 Error if file not found |
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
// ## like \1 but named: | |
/(?<fruit>apple|fig)==\k<fruit>/u.test('fig==fig') | |
// true | |
// ## named group captures: | |
'we can'.replace(/(?<subject>\w+) (?<verb>\w+)/u, '$<subject>...$<verb>') | |
//"we...can" | |
'yes, we can'.replace(/(?<w>\w+)[,\s]+/gu, '$<w>...') |
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
export default class BetterMap { | |
constructor(data) { | |
this.m = new Map(Array.isArray(data) || data instanceof Map ? data : Object.entries(data)); | |
} | |
set(k, v) { // return BetterMap | |
this.m.set(k, v); | |
return new SortableMap(this.m); | |
} | |
delete(k) { // return BetterMap | |
this.m.delete(k, v); |
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
mapTo: 428.186ms | |
mapTo2: 319.058ms | |
ord: 348.390ms | |
mapToMany: 786.141ms | |
mapToMany2: 780.661ms | |
ord agg: 31856.442ms |