Skip to content

Instantly share code, notes, and snippets.

@nkint
nkint / 1.js
Created November 6, 2018 08:50 — forked from getify/1.js
tag function for formatting console.log(..) statements
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;
}
@nkint
nkint / gist:3ea570bbc8ed4d42cc932a51249082f8
Last active September 27, 2018 12:29
Download canvas content as png
// 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()
}
@nkint
nkint / commatize-millions.js
Created September 22, 2018 10:36
commatize millions number
// 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
}
declare module 'measure-text' {
function measureText({
text,
fontFamily,
fontSize,
lineHeight,
fontWeight,
fontStyle,
canvas,
}: {
declare module 'draw-triangles-2d' {
function draw(
context: CanvasRenderingContext2D,
positions: Vec3[],
cells: Vec2[],
start?: number,
end?: number,
): void
export = draw
}
@nkint
nkint / o&#34; - li
Created April 27, 2018 10:27
Escape character &#34;
export function htmlDecode(input) {
var doc = new window.DOMParser().parseFromString(input, 'text/html')
return unescape(doc.documentElement.textContent)
}
@nkint
nkint / zip2topojson
Last active April 16, 2018 09:23
zip2topojson
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
@nkint
nkint / map.js
Last active April 12, 2018 15:29
map P5
/*
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));
}
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)
}
}
@nkint
nkint / gist:37ed3ba05a457bedeab4d6c723030f14
Created October 27, 2017 09:22
Test post sending via file via netcat/curl
# in one terminal
$ nc -l 9090
# in one another terminal
$ curl -X POST -v http://localhost:9090/ -F file=@../../Desktop/test-222.csv