Skip to content

Instantly share code, notes, and snippets.

View mikkoh's full-sized avatar

Mikko Haapoja mikkoh

View GitHub Profile
//POSSIBLE CONDITIONAL SYNTAX
node1.matchesWidthOf( layout )
.ifWidthGreaterThan( layout, 600 ).widthIsAPercentageOf( layout, 0.5 )
.ifWidthSmallerThan( layout, 200 ).widthIsAPercentageOf( layout, 0.2 );
//OTHER POSSIBLE CONDITIONAL SYNTAX
node1.matchesWidthOf( layout )
.is( layout ).widthGreaterThan( 600 ).widthIsAPercentageOf( layout, 0.5 )
.is( layout ).widthGreaterThan( 200 ).widthIsAPercentageOf( layout, 0.2 );
@mikkoh
mikkoh / gist:9561426
Created March 15, 2014 03:24
File Browser For Substacks Terminal-Menu
var fs = require( 'fs' );
var path = require( 'path' );
var terminalMenu = require( 'terminal-menu' );
var getUnderline = require( './getUnderline' );
var FileBrowser = function( settings, onFileSelect ) {
this.title = settings.title || 'Browse browse browse';
this.startIdx = 0;
//originally from https://github.com/mattdiamond/Recorderjs/blob/master/recorder.js
var url = (window.URL || window.webkitURL).createObjectURL(data);
var link = window.document.createElement('a');
link.href = url;
link.download = 'output.wav';
var click = document.createEvent("Event");
click.initEvent("click", true, true);
link.dispatchEvent(click);
plugin( req )
.model( require( '../model' ) )
.dataHBS( require( 'fs' ).readFileSync( './src/hbs/record.hbs', 'utf8' ) )
.then( modelstatic )
.then( handlebars )
.then( domappend )
.then( function( data ) {
var model = data.model;
@mikkoh
mikkoh / gist:af9c50d654825e07819c
Created December 12, 2014 15:42
JS Private and Public
module.exports = MyClass;
function MyClass() {
var myPrivatVariable = 10;
return {
publicMethod: function() {
@mikkoh
mikkoh / index.js
Created March 26, 2015 03:27
functional particles
var rafLoop = require('raf-loop');
var COUNT_PARTICLE = 100;
var MAX_VELOCITY = 5;
var FRICTION_MAGNITUDE = 0.07;
var els = array(COUNT_PARTICLE, createElement);
var positions = create(COUNT_PARTICLE, [window.innerWidth * 0.5, window.innerHeight * 0.5, 0]);
var velocities = create(COUNT_PARTICLE, [rand(-MAX_VELOCITY, MAX_VELOCITY), rand(-MAX_VELOCITY, MAX_VELOCITY), rand(-MAX_VELOCITY, MAX_VELOCITY)]);
@mikkoh
mikkoh / index.js
Created April 7, 2015 15:11
requirebin sketch
var fill = require('lodash/array/fill');
var arr = fill(new Array(10), function() { return 'test' });
var arr2 = fill(new Array(10), 'test');
document.body.innerHTML = JSON.stringify(arr) + JSON.stringify(arr2);
@mikkoh
mikkoh / index.js
Created May 14, 2015 18:07
requirebin sketch
var cssTransformToMatrix = require('css-transform-to-mat4');
var containerTest = document.createElement('div');
document.body.style[ 'text-align' ] = 'right';
document.body.style[ 'font-family' ] = 'Helvetica, sans serif';
document.body.style.width = '100%';
document.body.style.height = '100%';
document.body.style.margin = '0';
containerTest.style.height = window.innerHeight + 'px';
@mikkoh
mikkoh / gist:f8c5148871bb3ba57455
Created June 4, 2015 14:28
Converting between TypedArrays
/**
* To convert between typed arrays an ArrayBuffer can be used to create
* TypedArray's from one type to another. Each typed array has a property
* which is an ArrayBuffer.
**/
var uint16 = new Uint16Array([0x0102, 0x0304]);
var uint32 = new Uint32Array(uint16.buffer);
var uint8clamped = new Uint8ClampedArray(uint16.buffer);
var uint8 = new Uint8Array(uint16.buffer);
@mikkoh
mikkoh / gist:f8752d979f904d9c8690
Created June 5, 2015 16:02
Working with colors
var red = 0xFF; // 255
var green = 0x10; // 16
var blue = 0xCC; // 204
var alpha = 0xFF;
// 24 bit color (no alpha)
var color24 = red << 16 | green << 8 | blue;
// 32 bit color (alpha)
// note >>> 0 if this isn't done alpha overflows to negation bit