Skip to content

Instantly share code, notes, and snippets.

@nkint
nkint / gist:c7f4828149bb2bf2d2e1
Created January 13, 2016 15:48
node.js proxy cors
// from https://github.com/dbertella/cheap-flights/blob/master/proxy/server.js
var http = require('http'),
httpProxy = require('http-proxy');
var port = 3000;
var proxy = httpProxy.createProxyServer();
http.createServer(function(req, res) {
@nkint
nkint / gist:ce08c57d97631da514bf
Created February 1, 2016 14:25
node.js test coverage with istanbul nom script
{
"name": "test coverage example",
...
"scripts": {
"test": "NODE_ENV=test mocha --colors build/spec --timeout 5000",
"coverage": "NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -R spec"
},
"dependencies": {
@nkint
nkint / index.html
Created October 25, 2016 17:26
Not working zoom buttons
<!DOCTYPE html>
<meta charset="utf-8">
<svg width="960" height="500"></svg>
<div id="gui"></div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
transform = d3.zoomIdentity;
@nkint
nkint / gist:a53f536faac80ceecf2bc16040ac62ff
Created December 5, 2016 19:31
regl - basic render to texture
// thanks to https://gitter.im/mikolalysenko/regl
import createRegl from 'regl'
const mat4 = require('gl-mat4')
const cubePosition = [
[-0.5, +0.5, +0.5], [+0.5, +0.5, +0.5], [+0.5, -0.5, +0.5], [-0.5, -0.5, +0.5], // positive z face.
[+0.5, +0.5, +0.5], [+0.5, +0.5, -0.5], [+0.5, -0.5, -0.5], [+0.5, -0.5, +0.5], // positive x face
[+0.5, +0.5, -0.5], [-0.5, +0.5, -0.5], [-0.5, -0.5, -0.5], [+0.5, -0.5, -0.5], // negative z face
@nkint
nkint / pointTowards
Created December 12, 2016 11:29
Rotate mesh points towards a direction vector with stack-gl / regl
// inspired by toxiclibs
// https://bitbucket.org/postspectacular/toxiclibs/src/44d9932dbc9f9c69a170643e2d459f449562b750/src.core/toxi/geom/mesh/TriangleMesh.java?at=default&fileviewer=file-view-default#TriangleMesh.java-703
const vec3 = require('gl-vec3')
const mat3 = require('gl-mat3')
const mat4 = require('gl-mat4')
const quat = require('gl-quat')
function transform(matrix, v) {
const temp = mat3.create()
@nkint
nkint / pointTowards.vertex
Created December 12, 2016 11:32
Rotate mesh points towards a direction vector with vertex shader
// quaternion code from https://github.com/stackgl/gl-quat
// rotation from https://twistedpairdevelopment.wordpress.com/2013/02/11/rotating-a-vector-by-a-quaternion-in-glsl/
precision mediump float;
uniform mat4 projection, view;
uniform vec3 translate;
uniform vec3 scale;
attribute vec3 normal;
@nkint
nkint / pickWithRenderBuffer
Last active October 17, 2020 08:56
Regl and picking with off-screen render buffer
import createRegl from 'regl'
import createCamera from 'regl-camera'
import bunny from 'bunny'
import normals from 'angle-normals'
const regl = createRegl()
const camera = createCamera(regl, {
minDistance: 0.01,
distance: 20,
maxDistance: 30,
@nkint
nkint / ES6 d3 word wrap
Created January 26, 2017 13:31
ES6 port of famous mbostock's word wrap for d3 SVG text label
// ES6 port of famous mbostock's word wrap https://bl.ocks.org/mbostock/7555321
export function wrap(_text, width, lineHeightEm = 1.1) {
_text.each(function () {
const text = select(this)
const words = text.text().split(/\s+/).reverse()
const y = text.attr('y')
const dy = parseFloat(text.attr('dy')) || 0
let tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('dy', dy + 'em')
let line = []
@nkint
nkint / regl-load-image-texture
Created April 29, 2017 23:08
load image from url into a regl.texture object
const emptyTextureDimension = {
width: 512,
height: 512,
channels: 3,
}
function loadImageIntoTexture(url, texture) {
const image = new Image()
image.crossOrigin = 'anonymous'
image.src = url
@nkint
nkint / gist:66db01619e3a15b57e7b78ce9b1b85d4
Created May 2, 2017 22:05
Vertex shader with 4 texture (tiling satellite image)
precision mediump float;
uniform sampler2D satellite0;
uniform sampler2D satellite1;
uniform sampler2D satellite2;
uniform sampler2D satellite3;
uniform sampler2D elevation;
varying vec2 vUv;