Skip to content

Instantly share code, notes, and snippets.

View imbcmdth's full-sized avatar

Jon-Carlos Rivera imbcmdth

View GitHub Profile
var not = function(fn){ return function(){ return !fn.apply(this, arguments); }; };
var nullOrUndefined = function(e){ return this[e] == null; };
var notNullOrUndefined = not(nullOrUndefined);
var existsIn = function(e){ return this.indexOf(e) != -1; };
var doesntExistIn = not(existsIn);
var merge = function(dest, source){
var validKeys = Object.keys(source).filter(notNullOrUndefined, source);
var slice = Array.prototype.slice;
var call = Function.prototype.call;
var toArray = function () { return call.apply(slice, arguments); }
// Usage:
toArray(arguments); //=> make an array from all arguments
toArray(arguments, 1, 3); //=> make an array from arguments[1] to arguments[2]
// Script# Core Runtime
// More information at http://projects.nikhilk.net/ScriptSharp
//
window.isUndefined=function(o){return(o===undefined);};
window.isNull=function(o){return(o===null);};
window.isNullOrUndefined=function(o){return(o===null)||(o===undefined);};
window.__scriptsharp='0.5.5.0';
document.getElementsBySelector=function(cssSelector,root){
var all=root?root.getElementsByTagName('*'):document.getElementsByTagName('*');
var matches=[];
@imbcmdth
imbcmdth / fast_math.js
Last active June 26, 2021 05:54
Fast Approximate Functions for JavaScript based on https://code.google.com/p/fastapprox/
var Approx = {
fastlog2: (function () {
var a = new ArrayBuffer(4),
i = new Int32Array(a),
f = new Float32Array(a);
return function fasterLog2 (number) {
f[0] = number;
var t = i[0] * 1.1920928955078125e-7;
return t - 126.94269504;
@imbcmdth
imbcmdth / later.js
Last active December 29, 2015 22:59
later function
var later = Function.bind.bind(window.setTimeout, window);
// Usage
element.addEventListener('click', later(foo, 1000));
// On click, `foo` will be executed after 1 second with the usual event parameters passed along
var x = event.pageX - screen.offsetLeft;
var y = event.pageY - screen.offsetTop;
function distance(x, y) {
return Math.sqrt(x * x + y * y);
}
var d = distance(x - targetX, y - targetY);
if (d <= tolerance) {
@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"));