Skip to content

Instantly share code, notes, and snippets.

View imbcmdth's full-sized avatar

Jon-Carlos Rivera imbcmdth

View GitHub Profile
@imbcmdth
imbcmdth / content
Last active December 17, 2015 16:19 — forked from pcamp96/content
var isMobile = {
tests:[
function() {
return navigator.userAgent.match(/Android/i);
},
function() {
return navigator.userAgent.match(/BlackBerry/i);
},
function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
AJAXRequest: function(url, action){
/* ----------------------
Small AJAX Library
------------------------- */
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
// check if the request is ready and the status is ok
if (xhr.readyState === 4 && xhr.status === 200){
var slots = [], num = 1000; for(var i = 0; i < num; i++) setTimeout(function(s, d, done){ slots[s] = Date.now() - d; done(); }, 1000, i, Date.now(), function(){ if(!--num) { console.log("Mean:", slots.reduce(function(p, c, i) { var d = c - p; return p + d / i; })); } });
(function(global){
var exeQueue = [];
exeQueue.insertOrdered = function(val) {
var l = this.length,
order = val.order;
while(l--) {
if(this[l].order > order) break;
}
@imbcmdth
imbcmdth / huh.js
Created May 15, 2013 21:49
Wisp vs Wisp's Idea of JavaScript vs real JavaScript
// Wisp:
(fn sum
"Return the sum of all arguments"
{:version "1.0"}
([] 0)
([x] x)
([x y] (+ x y))
([x & more] (more.reduce (fn [x y] (+ x y)) x)))
// ==UserScript==
// @name Tatoeba Flexible Linker
// @namespace http://userscripts.org/users/515236
// @description Inserts a box below a Tatoeba sentence that the user can fill with the number or URL of a sentence, as well as buttons that allow the user to visit the new sentence or link it to the first one. Extends Zifre's "Tatoeba Linker" script.
// @author AlanF_US
// @include http://tatoeba.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @version 1.0
// ==/UserScript==
// NOTE: All functions used in the script must be added to the line below
var width = null;
var height = null;
window.onload = function () {
var windowSize = getSize();
width = windowSize['width'];
height = windowSize['height'];
window.onscroll = function(){ alert("Hello"); }
};
@imbcmdth
imbcmdth / gist:3922630
Created October 20, 2012 08:02
JAMMING!
> jm???in
Here's what I found:
[ 'jamming' ]
>
@imbcmdth
imbcmdth / gist:3881651
Created October 12, 2012 21:35
Javascript this quiz
// current scope is global..
function Test(n) {
this.test = n;
var bob = function (n) {
this.test = n;
};
this.fn = function (n) {
@imbcmdth
imbcmdth / deepCopy.js
Created September 12, 2012 19:47
Robust deep copying of objects w/ support for cycles
var deepCopy = (function () {
var funcBlacklist = ['caller', 'arguments', 'prototype' ],
primitiveCloner = makeCloner(clonePrimitive),
cloneFunctions = {
'[object Null]': primitiveCloner,
'[object Undefined]': primitiveCloner,
'[object Number]': primitiveCloner,
'[object String]': primitiveCloner,
'[object Boolean]': primitiveCloner,
'[object RegExp]': makeCloner(cloneRegExp),