Skip to content

Instantly share code, notes, and snippets.

Avatar

Ray Bellis raybellis

  • Oxfordshire, England
View GitHub Profile
@raybellis
raybellis / memoize_multi.js
Created Jul 31, 2020
Generic memoize function supporting multiple parameter key lookups
View memoize_multi.js
function memoize(factory, ctx, mapper) {
const cache = new Map();
return function(...keys) {
const key = mapper ? mapper(keys) : keys[0];
if (!cache.has(key)) {
cache.set(key, factory.apply(ctx, keys));
}
console.debug(cache);
return cache.get(key);
}
View MidiTunnel.swift
import Foundation
import CoreMIDI
let source = Int(CommandLine.arguments[1])!
let dest = Int(CommandLine.arguments[2])!
var owner = "uk.me.rb.thru" as CFString?
// dispose of any existing connections with the same owner
var obj = Data()
@raybellis
raybellis / random.js
Last active Oct 2, 2019
Emulation of java.util.Random in Javascript
View random.js
class UInt48 {
constructor(n) {
if (n instanceof UInt48) {
Object.assign(this, n);
} else if (typeof n === 'number') {
let w0 = n & 0xffff;
n /= 0x10000;
let w1 = n & 0xffff;
n /= 0x10000;
@raybellis
raybellis / merger.c
Created Mar 28, 2018
16-bit ROM merger
View merger.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
int main(int argc, char *argv[])
{
const size_t bufsize = 4096;
uint8_t buf_a[bufsize];
@raybellis
raybellis / jquery.memoize.js
Last active Dec 15, 2015
Non-persistent and Persistent memoized functions
View jquery.memoize.js
;(function($) {
"use strict";
$.memoize = function(factory, ctx) {
var cache = {};
return function(key) {
if (!(key in cache)) {
cache[key] = factory.call(ctx, key);
}
@raybellis
raybellis / jquery.classlist.js
Last active Dec 14, 2015
A shim for jQuery that uses the native "classList" property of an element for class modifications, if available.
View jquery.classlist.js
/*global jQuery */
;(function($) {
/*global document */
"use strict";
if (typeof document !== 'undefined' && ('classList' in document.createElement('a'))) {
var $ = jQuery;
@raybellis
raybellis / jquery.loop.js
Created Oct 15, 2012
jQuery loop plugin
View jquery.loop.js
(function($) {
$.loop = function(n, cb, ctx) {
for (var i = 0; i < n; ++i) {
if (cb.call(ctx, i) === false) break;
}
};
})(jQuery);
@raybellis
raybellis / jquery.queued.js
Created Oct 2, 2012
A jQuery plugin to allow any function to be queued (default 'fx' queue only)
View jquery.queued.js
(function($) {
$.fn.queued = function() {
var self = this;
var func = arguments[0];
var args = [].slice.call(arguments, 1);
return this.queue(function() {
$.fn[func].apply(self, args).dequeue();
});
}
}(jQuery));
You can’t perform that action at this time.