Skip to content

Instantly share code, notes, and snippets.

@nkint
nkint / regs-camera.js
Created May 31, 2017 13:58
Sketch of new regl camera
import { projectionMatrix, viewMatrix } from './turntable-camera'
import mouseChange from 'mouse-change'
import mouseWheel from 'mouse-wheel'
import identity from 'gl-mat4/identity'
import key from 'key-pressed'
// const isBrowser = typeof window !== 'undefined'
const getStartingState = (initialStatePlusOptions) => ({
view: identity(new Float32Array(16)),
import defined from 'defined'
const TO_PX = 35.43307
const DEFAULT_SVG_LINE_WIDTH = 0.03
export function shapesToSVG(shapes, opt = {}) {
const dimensions = opt.dimensions
if (!dimensions) throw new TypeError('must specify dimensions currently')
const decimalPlaces = 5
@nkint
nkint / gist:c9c05d8a0de4d736f27036d594645fd0
Created September 22, 2017 12:49
Wrap text on canvas
export function wrapTextCanvas(context, text, x, y, maxWidth, lineHeight, drawFlag = true) {
const cars = text.split('\n')
for (let ii = 0; ii < cars.length; ii++) {
let line = ''
const words = cars[ii].split(' ')
for (let n = 0; n < words.length; n++) {
const testLine = line + words[n] + ' '
const metrics = context.measureText(testLine)
@nkint
nkint / index.js
Last active October 4, 2017 09:07
React + d3 + hover band
// install prot globally https://github.com/mattdesl/prot
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { scaleTime } from 'd3-scale'
import format from 'd3-time-format'
function VerticalLine({ x, height, stroke="#888" }) {
return <line
x1={x}
@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
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 / 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));
}
@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 / 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)
}
declare module 'draw-triangles-2d' {
function draw(
context: CanvasRenderingContext2D,
positions: Vec3[],
cells: Vec2[],
start?: number,
end?: number,
): void
export = draw
}