Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
ryanlaws / getClassesAndIds.js
Created March 5, 2016 13:08
Get all classes and IDs of DOM elements given a parent element
function getClassesAndIds(parent, memo) {
if (typeof memo === 'undefined')
memo = {classes: [], ids: []};
if (parent.className)
parent.className.split(' ').forEach(function (className) {
if (className && !~memo.classes.indexOf(className))
memo.classes.push(className)
});
// No error checking or anything! Use with caution!
function addCombos(list, combos=[], dict={}) {
if (!list.length)
return combos.concat(dict);
let item = list[0];
let possibilities = getPossibilities(item);
possibilities.forEach(possibility => {
let subDict = addKvp(dict, item, possibility);
// Usage:
// -----
// import html from './html-tagged-temp-lit.js'
// html`<div>${"Hello World"}</div>`
const joinIfArray = (maybeArray) =>
Array.isArray(maybeArray) ? maybeArray.join('') : maybeArray
const html = (literals, ...vars) => {
return Array.from(literals).reduce((output, literal, i) => {
@ryanlaws
ryanlaws / partial.js
Created October 2, 2018 13:40
Partial function application
const partial = (f) =>
(...args) =>
(args.length >= f.length)
? f(...args)
: partial(f).bind(this, ...args)
@ryanlaws
ryanlaws / babbys-first-audiobuffer.js
Created April 25, 2019 13:57
Playing around with the web AudioBuffer API
{
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const sr = audioCtx.sampleRate;
const hzInc = 1 / sr;
const noteToHz = (midiNote) => Math.pow(2, midiNote/12) * 8.17570643783345;
class Accumulator {
constructor() {
this.oscs = [];
{
const props = ['a', 'b', 'c'];
// Manufacture
const makeObj = (name) => {
const obj = {};
props.forEach(prop =>
Object.defineProperty(obj, prop, {
get: () => `this is ${name}'s ${prop}`
}));
-- based on @okyeron's hid_demo/hid-events.lua
-- check MIDI Devices list printed below to REPL for which port to choose
-- change these to suit your needs
local midi_port_id = 1 -- especially this one
local midi_channel = 1 -- and probably this one
local midi_velocity = 100
function init()
-- print some device data to REPL
//////// sunset 2020
(Ndef(\reverb, {|wet=0.85, dry=0.15, size=10|
var input = \in.ar([0, 0]);
var primes = (2..13).nthPrime;
var reverb = Mix.ar(primes.collect({|i|
var delay = SinOsc.ar(0.02.rrand(0.1), 0, 0.02.rand, i/100);
AllpassL.ar(input, 1/2, delay, size, 1/primes.size)
}));
(wet*(reverb + input)) + (dry*input);
});
@ryanlaws
ryanlaws / fake-wavetable-thing.scd
Created June 15, 2021 04:09
just a really janky wavetable in SuperCollider
// your keycodes may vary
~ctrl = 105;
// recording params - 12 sec for no particular reason
~bufferSeconds = 12;
// do this first and then wait
~buf = Buffer.alloc(s, s.sampleRate * ~bufferSeconds, 2);
(Ndef(\seekWt, { |offset=0,freq=55, gain=1, seekLag=5, curve=0, probability = 1, rate=1|
@ryanlaws
ryanlaws / fc2-working-set.scd
Last active July 11, 2021 00:24
FC2 working set
//JUNK
s.quit;
s.boot;
(~stopwatch = Routine { var ct = 0;
loop { ct.postln; 1.wait; ct = ct + 1 }
}.play;)
~stopwatch.stop;
Ndef.clear
s.options.recHeaderFormat = 'wav'
s.prepareForRecord