Skip to content

Instantly share code, notes, and snippets.

View jussi-kalliokoski's full-sized avatar

Jussi Kalliokoski jussi-kalliokoski

View GitHub Profile
@jussi-kalliokoski
jussi-kalliokoski / even.js
Created July 2, 2014 07:00
Circular dependencies in CJS
"use strict";
module.exports = function (module, oddModule) {
module.exports = function even (n) {
return n == 0 || oddModule.exports(n - 1);
};
};
@jussi-kalliokoski
jussi-kalliokoski / example1.js
Last active August 29, 2015 14:02
Constructors?
// method as a constructor.
function MyClass () {
this.isInitialized = false;
}
MyClass.prototype.initialize = function () {
this.initialized = true;
};
@jussi-kalliokoski
jussi-kalliokoski / gulpfile.js
Last active August 29, 2015 14:01
wait for things to settle before running a task
"use strict";
var gulp = require("gulp");
var exec = require("gulp-exec");
var _ = require("lodash");
// This task will do nothing until it hasn't been triggered within 1s.
gulp.task("exec", _.debounce(function () {
return gulp.src(["..."], { read: false })
.pipe(exec("ctags -R"));
@jussi-kalliokoski
jussi-kalliokoski / createSentence.js
Last active August 29, 2015 14:01
Natural language constructs in JS
var createSentence = function () {
var names = [].slice.call(arguments);
var fn = names.pop();
if ( names.length === 0 ) {
return fn;
}
var name = names.shift();
@jussi-kalliokoski
jussi-kalliokoski / main.js
Last active August 29, 2015 14:01
Web Audio Worker Example - Messaging
class OffsetNode {
constructor (context) {
this.context = context;
this.worker = this.context.createAudioWorker("worker.js");
this.node = this.context.createScriptProcessor(this.worker);
this.initializeQueue();
}
initializeQueue () {
this.getOffsetQueue = [];
@jussi-kalliokoski
jussi-kalliokoski / main.js
Created May 12, 2014 07:45
Web Audio Worker Example - Shared Parallel
let context = new AudioContext();
let noiseWorker = context.createAudioWorker("worker.js");
let noiseNode1 = context.createScriptProcessor(noiseWorker);
let noiseNode2 = context.createScriptProcessor(noiseWorker);
let oscillator = context.createOscillator();
noiseNode1.connect(oscillator.detune);
noiseNode2.connect(context.destination);
@jussi-kalliokoski
jussi-kalliokoski / prepend.js
Last active August 29, 2015 14:00
Dealing with function function signatures with multiple arguments.
// The usual way
var prepend = function (string, prefix) {
return prefix.concat(string);
};
prepend("foo", "bar_"); // Wait, what? Is this "foobar_" or "bar_foo"? Not obvious without seeing the function signature.
// More natural language
var prepend = function (string) {
@jussi-kalliokoski
jussi-kalliokoski / used-functions.js
Created August 8, 2013 07:29
Detect which lodash/underscore functions your code is using.
var usedFunctions = function (_) {
"use strict";
var usedFunctions = [];
var isFunction = _.isFunction;
var contains = _.contains;
_.forOwn(_, function (func, name) {
if ( !isFunction(func) ) { return; }
_[name] = function () {
@jussi-kalliokoski
jussi-kalliokoski / example.js
Last active December 19, 2015 13:09
Web MIDI API with maps
var select = document.createElement('select');
var selectedPort = null;
var onMessage = function (event) {
// TODO: Use the message
};
var selectPort = function (id) {
var newPort = midiAccess.inputs.get(id);
@jussi-kalliokoski
jussi-kalliokoski / LICENSE.txt
Last active March 8, 2018 11:44 — forked from 140bytes/LICENSE.txt
A 140byt.es UUIDv4 generator.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jussi Kalliokoski <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE