Skip to content

Instantly share code, notes, and snippets.

View rhom6us's full-sized avatar

Thomas Butler rhom6us

  • Butler Software
  • Atlanta, GA
View GitHub Profile
@rhom6us
rhom6us / Map.prototype.toObject.js
Last active July 24, 2016 02:11
Map.prototype.toObject
/**
* This will be an instance member, Observable#publish.
* @memberof Map.prototype
* @param {Object} [target] - The object that the properties derived from the map's key/value pairs will be created on.
* @returns {Object}
*/
Map.prototype.toObject = function(target = Object.create(null)) {
let props = [...this].map(kvp => {
let [key, value] = kvp;
@rhom6us
rhom6us / Array.prototype.toMap.js
Last active June 24, 2023 20:30
Array.prototype.toMap
/**
* @param {Function} kvpFn - The function used to create the mapping. Return either the value to be used as key and the entire item will be set as the value, or return a key/value pair in the format [key, value] to specify both explicitely.
* @returns {Map}
*/
Array.prototype.toMap = function (kvpFn){
const input = this.map(kvpFn);
if(!input.every(p => Array.isArray(p) && p.length === 2) {
throw new TypeError('kvpFn must return a two element array tuple');
}
return new Map(input);
@rhom6us
rhom6us / css tooltips.html
Created October 21, 2016 10:47
css tooltip
<!DOCTYPE html>
<html>
<style>
[fu] {
position:relative;
}
[fu]::before,[fu]::after {
visibility: hidden;
@rhom6us
rhom6us / AnonymousType.fs
Created April 1, 2017 23:02
F# Object Expression (Anonymous Type)
printfn "%A" { new System.Object() with member x.ToString() = "F########" }
@rhom6us
rhom6us / fsharp.records.default_values.fs
Created April 1, 2017 23:04
F# Records - Default Values
// Rather than use [<DefaultValue>], define a default record.
type MyRecord = {
field1 : int
field2 : int
}
let defaultRecord1 = { field1 = 0; field2 = 0 }
let defaultRecord2 = { field1 = 1; field2 = 25 }
// Use the with keyword to populate only a few chosen fields
@rhom6us
rhom6us / webaudio-transition-tivial.js
Last active May 22, 2024 04:27
simple song transition
var songInfos = [{
url: "https://fuckingdj.blob.core.windows.net/test/Swedish%20House%20Mafia%20-%20Save%20The%20World%20(Zedd%20Remix).mp3",
}, {
url: "https://fuckingdj.blob.core.windows.net/test/Jewelz%20%26%20Scott%20Sparks%20feat.%20Quilla%20%E2%80%93%20Unless%20We%20Forget%20(Original%20Mix).mp3",
}];
var song1toSong2TransitionData = {
startTime: 72.556,
skipBeginning: 45.824,
};
var context = new AudioContext();
using System.Collections.Specialized;
using System.Linq;
using JetBrains.Annotations;
// ReSharper disable CheckNamespace -- be available where Dictionary<,> is
namespace System.Collections.Generic
{
/// <summary>
/// System.Collections.Specialized.OrderedDictionary is NOT generic.
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
// Start Visual Studio
// File->New->Project->C#->WPF Application
// Replace MainWindow.Xaml.cs with this code
@rhom6us
rhom6us / Tuple.ino
Created January 21, 2019 03:07
Arduino-compatable Tuple implementation (not std compatable). Need to make a proper adruino lib for this.
#include <ArduinoSTL.h>
#include <iostream>
// helpers
template <typename T>
struct id { using type = T; };
template <typename T>
using type_of = typename T::type;
@rhom6us
rhom6us / draw-audio-buffer.js
Created February 25, 2021 22:58
Draw an audio buffer to a canvas
function drawBuffer( width, height, context, buffer ) {
var data = buffer.getChannelData( 0 );
var step = Math.ceil( data.length / width );
var amp = height / 2;
for(var i=0; i < width; i++){
var min = 1.0;
var max = -1.0;
for (var j=0; j<step; j++) {
var datum = data[(i*step)+j];
if (datum < min)