Skip to content

Instantly share code, notes, and snippets.

View imbcmdth's full-sized avatar

Jon-Carlos Rivera imbcmdth

View GitHub Profile
@imbcmdth
imbcmdth / gist:8817324
Created February 5, 2014 04:15
cheating at 10fastfingers
function foo(){var str = $('.highlight').text();$("#inputfield").val(str);str=str.split('');str.push(' ');bar(str);} function bar(str){var v=str.shift().charCodeAt(0);$("#inputfield").trigger($.Event( "keyup", {keyCode: v, charCode: v,which: v}));setTimeout(str.length?bar:foo,10+((Math.random()*70)|0),str);} foo();
@imbcmdth
imbcmdth / gist:8832780
Last active August 29, 2015 13:56
rAF shim
window.requestAnimFrame = (function(global) {
var callbackList = [],
timer,
nextTimeSlot = 0;
function processCallbacks () {
var localCBList = callbackList,
now = +(new Date), cb;
callbackList = [];
@imbcmdth
imbcmdth / fit-text.js
Last active August 29, 2015 13:56
resize text inside of a block level element to be as large as possible while still fitting completely inside another div without overflow
(function (root, factory) {
if (typeof exports === 'object') {
module.exports = factory(require('masala'));
} else if (typeof define === 'function' && define.amd) {
define(['masala'], factory);
} else {
root.fitText = factory(root.masala);
}
}(this, function (masala) {
var rectEnum = {
window.addEventListener('load', getRequestForEditor);
var events = ['change', 'contextmenu', 'select', 'keypress', 'dblclick', 'click', 'mousedown', 'mouseup', 'mousewheel', 'scroll'];
function bindEvent (eventName) {
this.addEventListener(eventName, getRequestForEditor);
}
events.forEach(bindEvent, document.getElementById("selContentType"));
events.forEach(bindEvent, document.getElementById("selTheme"));
@imbcmdth
imbcmdth / gist:07c7bf7ecc6883cbb476
Last active August 29, 2015 14:06
Browser performance - HDR image processing
Firefox 33
----------------------------------------------
HDRPNG - Reading and Parsing PNG: 279.62ms
HDRPNG - Convert LogLuv to rgb float: 716.98ms
HDRPNG - Generate Log2 Luminance: 156.1ms
HDRPNG - Generate Histograms: 326.97ms
Applying TMO: 159.38ms
Applying DMO: 231.71ms
-----------------------------------------------
Total: 1,870ms
@imbcmdth
imbcmdth / test.js
Created September 21, 2014 21:16
2D array to table
function appender (to, el) { to.appendChild(el); return to; }
function genElement (type, next) {
return next(document.createElement(type))
}
var genTextNode = document.createTextNode.bind(document);
function genElements (values, generator, parent) {
return values.map(generator)
@imbcmdth
imbcmdth / weighted.js
Created December 14, 2014 18:10
Weighted Sampling
function rand (max) { return Math.random() * max; }
function randomSample (array) {
var answer = array[0];
var totalWeight = array[0].w;
var left = array.slice(1);
left.forEach(function (element) {
var w = element.w;
var r = rand(totalWeight + w);
@imbcmdth
imbcmdth / weighted_generator.js
Created December 14, 2014 18:10
Weighted Sampling Generator
function rand (max) { return Math.random() * max; }
function *randomSample () {
var answer = yield;
var totalWeight = answer.w;
while (true) {
var next = yield answer;
var w = next.w;
var r = rand(totalWeight + w);
var a = 'Going down to brown town';
String.prototype.lerp = function(n){
var ai = Math.floor(n);
var t = n - ai;
var a = this.charCodeAt(ai);
var b = this.charCodeAt(ai + 1);
return String.fromCharCode(a + (b - a) * t);
}
@imbcmdth
imbcmdth / gist:c8f0490fd20d0392b408
Created March 7, 2015 20:28
Cleaner Stack Traces for Masala
>> BEFORE:
ReferenceError: _notDefined is not defined
at throwingFunction (J:\my_node_libs\masala\examples\exception.js:4:2)
at intermediateFunction (J:\my_node_libs\masala\examples\exception.js:8:9)
at sauce (J:\my_node_libs\masala\masala.js:126:17)
at intermediateFunction (eval at wrapFunctionWithArity (J:\my_node_libs\masala\masala.js:79:11), <anonymous>:2:11)
at callingContext (J:\my_node_libs\masala\examples\exception.js:19:7)
at Object.<anonymous> (J:\my_node_libs\masala\examples\exception.js:20:2)
at Module._compile (module.js:444:26)