Skip to content

Instantly share code, notes, and snippets.

View seemikehack's full-sized avatar

Michael Atkinson seemikehack

  • College Station, TX
View GitHub Profile
@seemikehack
seemikehack / linLogMapper.py
Created January 25, 2018 20:41
Calculate constants for use in mapping a linear scale to a logarithmic scale
import math
x1 = int(input('lin beg: '))
x2 = int(input('lin end: '))
y1 = int(input('log beg: '))
y2 = int(input('log end: '))
b = math.log( ( y2 / y1 ) / ( x2 - x1 ) )
a = y2 / math.exp( b * x2 )
@seemikehack
seemikehack / out.md
Created September 30, 2015 19:34
Expected SQL Output
id childId groupId sort type name
1 0 0 1 text Top field
2 0 0 2 mastergroup Child 1
3 0 2 3 text First Name
4 0 2 4 text Last Name
2 1 2 2 childgroup Child 2
3 1 2 3 text First Name
4 1 2 4 text Last Name
2 2 2 2 childgroup Child 3
@seemikehack
seemikehack / killEvent.js
Created May 5, 2015 04:22
Absolutely, positively squash an event in the most cross-browser-compatible way imaginable (thanks, IE8).
// see http://www.quirksmode.org/js/events_order.html for a fun read
// if you're wondering why all the type-coercion b.s., why not, since this function has to exist in the first place
function killEvent(e) {
e = e || window.event;
e.cancelBubble = true;
e.returnValue = !true;
return !!(e.stopPropagation && (e.stopPropagation() || e.preventDefault()));
}
@seemikehack
seemikehack / color-rule.js
Created April 29, 2015 19:55
Draw lines on the screen at absolute offsets
// draw a colored rule across the page
function drawRule(label, offset, options) {
// setting global color enum, step counter, and index
window.crColors = window.crColors || ['#000', '#f00', '#0f0', '#00f', '#ff0', '#0ff', '#f0f', '#fff'];
window.crStep = window.crStep || 0;
window.crOffset = window.crOffset || 0;
window.crOffsetScale = 200;
window.crIndex = window.crIndex || 9001
// set defaults or compute values
@seemikehack
seemikehack / Queue.js
Created April 22, 2015 18:33
Standard FIFO Queue, implemented with two stacks.
/**
* Standard FIFO Queue, implemented with two stacks.
* @typedef {Object} Queue
* @property {function} enqueue - add an item to the back of the queue
* @property {function} dequeue - remove an item from the front of the queue
* @property {function} isEmpty - check whether or not the queue is empty
*/
/**
* Standard FIFO Queue, implemented with two stacks.
@seemikehack
seemikehack / AssertException.js
Created April 22, 2015 18:32
Simple assertion library
// custom assertion library
function AssertException(msg) {
this.msg = msg || 'AssertException';
};
AssertException.prototype.toString = function () {
return 'AssertException: ' + this.msg;
};
function assert(exp, msg) {
if (!exp)
throw new AssertException(msg);
@seemikehack
seemikehack / generateUUID.js
Created April 22, 2015 18:30
Generate a v4 UUID, with seeding
// Source:
// http://stackoverflow.com/a/2117523 and
// http://stackoverflow.com/a/8809472
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c == 'x' ? r : (r&0x7|0x8)).toString(16);
});
@seemikehack
seemikehack / toUTF8Array.js
Created April 22, 2015 18:28
Convert from UTF-16 to UTF-8
// Source: http://stackoverflow.com/a/18729931
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bluebird/1.2.2/bluebird.js"></script>
<script src="https://rawgithub.com/keithwhor/audiosynth/master/audiosynth.js"></script>
<script id="jsbin-javascript">
@seemikehack
seemikehack / gist:ed605093b531fbb051fe
Created July 3, 2014 13:38
RequireJS Dependencies and Automatic Script Loading
define(function (require) {
var a = require('a'),
b = require('b');
// explicitly loading module
require('c');
});