Skip to content

Instantly share code, notes, and snippets.

@vorg
vorg / gist:9225975
Created February 26, 2014 08:48
Paper js scaling
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/paper.js"></script>
<script type="text/javascript" src="js/paper-error.js"></script>
<script type="text/javascript" src="js/paper-timeline.js"></script>
<script type="text/paperscript" canvas="myCanvas">
//scaling
heapdump = require('heapdump')
memwatch = require('memwatch')
memwatch.on 'leak', (info) -> console.log('leak', info)
memwatch.on 'stats', (stats) -> console.log('stats', stats)
if frame % 25 == 1
hd = new memwatch.HeapDiff()
if frame % 25 == 24
diff = hd.end()
@vorg
vorg / gist:9932300
Created April 2, 2014 11:25
ClojureScript hasmaps magic
;;make some complex hashmap with numbers, edges and complex structs
(def c {:from 0 :to 1 [0, 1] 3 #{0 {:x 2 :y 3} 1 {:x 0 :y 3}} 4})
;;test getting edge value
(get c #{0 {:x 2 :y 3} 1 {:x 0 :y 3}})
;;define points
(def p1 {:x 2 :y 3})
(def p2 {:x 0 :y 3})
@vorg
vorg / gist:4578bd0e01efb9122f94
Last active August 29, 2015 14:04
NPM Police - Tired with npm modules putting lot of junk into distributions here is a list of the guilty ones:
sha.js - test 700KB
https://github.com/dominictarr/sha.js/issues/5
esprima - test 700KB
https://github.com/ariya/esprima
https://code.google.com/p/esprima/issues/detail?id=573&thanks=573&ts=1406550115
browser-sync - cache 55MB
https://github.com/shakyShane/browser-sync/issues/212
@vorg
vorg / gist:d251e0ddf0d404b1d34c
Last active August 29, 2015 14:06
Split array into pairs of values
How would you partition array into pairs in Ramda? [0, 1, 2, 3, 4, 5] -> [[0,1], [2, 3], [4, 5]]
//@vorg - my solution
var hasEvenIndex = function(n, i) { return i % 2 == 0; };
var hasOddIndex = function(n, i) { return i % 2 == 1; };
function pairs(list) {
var evens = R.filter.idx(hasEvenIndex)(list);
var odds = R.filter.idx(hasOddIndex)(list);
return R.zip(evens, odds);
@vorg
vorg / gist:d362361011b4d6c733c1
Created October 6, 2014 16:53
Mapping edges to vertices with ramda
var R = require('ramda');
var list = ['a', 'b', 'c'];
var edges = [[0, 1], [1,2]];
var values;
//1
values = edges.map(function(edge) {
return [ list[edge[0]], list[edge[1]] ];
});
@vorg
vorg / gist:6e70eda9938553cc1e7d
Last active August 29, 2015 14:08
Beautiful code = Slow code :(
GeomUtils.center3 = function(points) {
var sum = new Vec3(0, 0, 0);
for(var i=0; i<points.length; i++) {
sum.add(points[i]);
}
sum.scale(1/points.length);
return sum;
}
GeomUtils.center3R = function(points) {
FXStage.prototype.drawFullScreenQuadAt = function (x, y, width, height, image, program) {
var regl = this.regl
program = program || this.fullscreenQuad.program
if (!this.blitCmd) {
this.blitCmd = regl({
// depth: { enable: false },
// viewport: { x: x, y: y, width: width, height: height },
attributes: this.fullscreenQuad.attributes,
elements: this.fullscreenQuad.elements,
vert: regl.prop('vert'),
/*
<p> This example shows how to draw a mesh with regl </p>
*/
const regl = require('regl')()
const mat4 = require('gl-mat4')
const bunny = require('bunny')
var vert = `
precision mediump float;
attribute vec3 position;
@vorg
vorg / index.js
Created September 22, 2016 16:39
regl vertex attribute size dependency
var regl = require('regl')()
regl.clear({
color: [0, 0, 0, 1],
depth: 1
})
// In regl, draw operations are specified declaratively using. Each JSON
// command is a complete description of all state. This removes the need to
// .bind() things like buffers or shaders. All the boilerplate of setting up