Skip to content

Instantly share code, notes, and snippets.

View DavidSanwald's full-sized avatar

David Sanwald DavidSanwald

View GitHub Profile
// interviewer: what will the following code output?
const arr = [10, 12, 15, 21];
for (var i = 0; i < arr.length; i++) {
setTimeout(function() {
console.log('Index: ' + i + ', element: ' + arr[i]);
}, 3000);
}
<source>
@type forward
@id http_input
port 24224
</source>
## match tag=myapp.** and forward and write to file in local
<match jina.**>
@type elasticsearch
{
"Primary": {
"50": "#e1f2f4",
"100": "#b3e0e2",
"200": "#82ccd0",
"300": "#4eb8bb",
"400": "#26a9ab",
"500": "#009999",
"600": "#008c8b",
"700": "#027c7a",
@DavidSanwald
DavidSanwald / .block
Last active June 28, 2019 17:21 — forked from mbostock/.block
Brush & Zoom
license: gpl-3.0
@DavidSanwald
DavidSanwald / pythonic code
Created February 1, 2019 18:41
Python hints, tricks and useful links...
//
https://docs.python-guide.org/writing/style/
@DavidSanwald
DavidSanwald / scales.js
Created September 26, 2018 12:37
do not directly apply scales to data, compose them with accessor functions instead
// accessor functions to decouple from data shape
const x = d => d.date
const y = d => d.score
const xScale = d3.scaleTime()
.range([0, width])
.domain(xExtent)
const yScale = d3.scaleLinear()
.range([height, 0])
@DavidSanwald
DavidSanwald / data-join.js
Created September 26, 2018 12:06
saving individual parts of data join
// create single idempotent container that is appended to the DOM only once
const container = selection.selectAll('.lines').data([null]).enter().append('g').attr('class', 'lines')
// bind data, create and save the update selection
let update = container.selectAll('.line')
.data(data, d => d.id)
// create and save the exit selection
let exit = update.exit()
@DavidSanwald
DavidSanwald / debug.js
Last active September 26, 2018 13:46
Prototyping D3 charts inside React
const peek = ({ color = 'red', text = 'logged value:', weight = 'bold' } = {}) => x => {
const logContent = `%c ${text} ${x}`
const style = `color: ${color}; font-weight: ${weight};`
console.log(logContent, style)
return x
}
const peekGreen = peek({color: 'green'})
@DavidSanwald
DavidSanwald / config.js
Created May 3, 2017 13:30
storybook config
import { configure, setAddon, addDecorator } from '@kadira/storybook';
import infoAddon from '@kadira/react-storybook-addon-info';
import centered from '@kadira/react-storybook-decorator-centered';
import {withKnobs} from '@kadira/storybook-addon-knobs';
setAddon(infoAddon);
addDecorator(withKnobs);
addDecorator(centered);
@DavidSanwald
DavidSanwald / props.js
Created April 28, 2017 17:08
StyledPadProps
StyledPad.propTypes = {
state: PropTypes.oneOf(['idle', 'playing', 'selected']).isRequired,
onClick: PropTypes.func.isRequired,
width: PropTypes.string,
height: PropTypes.string,
timing: PropTypes.string,
}
StyledSquare.defaultProps = {