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 logger(strings,...values) { | |
var str = ""; | |
for (let i = 0; i < strings.length; i++) { | |
if (i > 0) { | |
if (values[i-1] && typeof values[i-1] == "object") { | |
if (values[i-1] instanceof Error) { | |
if (values[i-1].stack) { | |
str += values[i-1].stack; | |
continue; | |
} |
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
// TODO: does not handle `URL.revokeObjectURL` | |
function downloadCanvasContent(canvas: HTMLCanvasElement, filename: string) { | |
const link = document.createElement('a') | |
link.href = canvas.toDataURL() | |
link.download = filename | |
link.click() | |
} | |
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
// taken actually from https://github.com/adamwdraper/Numeral-js/blob/master/src/numeral.js#L241 | |
function commatizeMillions(number, lang) { | |
const str = (number).toFixed(0).toString() | |
const separator = lang === ITA ? '.' : ',' | |
const out = str.replace(/(\d)(?=(\d{3})+(?!\d))/g, `$1${separator}`) | |
return out | |
} |
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
declare module 'measure-text' { | |
function measureText({ | |
text, | |
fontFamily, | |
fontSize, | |
lineHeight, | |
fontWeight, | |
fontStyle, | |
canvas, | |
}: { |
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
declare module 'draw-triangles-2d' { | |
function draw( | |
context: CanvasRenderingContext2D, | |
positions: Vec3[], | |
cells: Vec2[], | |
start?: number, | |
end?: number, | |
): void | |
export = draw | |
} |
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 function htmlDecode(input) { | |
var doc = new window.DOMParser().parseFromString(input, 'text/html') | |
return unescape(doc.documentElement.textContent) | |
} |
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
zip2topojson() { | |
NAME=$(basename $1 .zip) | |
OUTPUT="$2" | |
unzip -o $NAME.zip -d $NAME | |
cd $NAME/ | |
[ -f $NAME.geo.json ] && rm $NAME.geo.json | |
ogr2ogr -f GeoJSON -s_srs $NAME.prj -t_srs EPSG:4326 $NAME.geo.json $NAME.shp |
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
/* | |
FAMOUS MAP FUNCITON FROM PROCESSING.ORG PROGRAMMING LANGUAGE | |
Taken from: https://stackoverflow.com/a/17135426 | |
*/ | |
export function map(value, istart, istop, ostart, ostop) { | |
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)); | |
} |
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
class Node { | |
constructor(id, prev, isValid) { | |
this.id = id | |
this.prev = prev | |
this.isValid = isValid | |
} | |
disabled() { | |
return this.isValid && (this.prev ? this.prev.disabled() : true) | |
} | |
} |
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
# in one terminal | |
$ nc -l 9090 | |
# in one another terminal | |
$ curl -X POST -v http://localhost:9090/ -F file=@../../Desktop/test-222.csv |