Skip to content

Instantly share code, notes, and snippets.

View r3b's full-sized avatar

ryan bridges r3b

  • Atlanta, Georgia
View GitHub Profile
@r3b
r3b / divSwirl.js
Last active July 29, 2019 20:46
create a spinning vortex of randomly-colored divs on any page. handy if you need to create entropy or stress on a page. Now with stars!
(function(){
var db = document.body, //shortcut to document.body
r = 100, //initial radius of the circle
x = (db.clientWidth - r) / 2, //horizontal center
y = (window.pageYOffset || (db.parentNode || db).scrollTop) + ((window.innerHeight+r)/2), //offset from page top
o = 0.0, //angle offset
w = 0, //width of square
dl = 150, //number of divs
ai=Math.PI / dl, //pie slice width
divs=Array.prototype.map.call(new Int8Array(dl),function(){ //div array
var Loader = function () { }
Loader.prototype = {
require: function (scripts, callback) {
this.loadCount = 0;
this.totalRequired = scripts.length;
this.callback = callback;
for (var i = 0; i < scripts.length; i++) {
this.writeScript(scripts[i]);
}
@r3b
r3b / interaction-timing.js
Last active December 19, 2015 08:19
Testing web UI interaction response times with CasperJS
var colorizer = require('colorizer').create('Colorizer');
var casper = require('casper').create();
var totalTests=3;
casper.start('http://jqueryui.com/resources/demos/tabs/ajax.html', function(){
casper.viewport(1024, 768);
this.test.assertHttpStatus(200, "The page has loaded.");
this.test.assertSelectorExists('#tabs', "We got tabs.");
this.test.assertVisible('#tabs-1', "Content 1 is visible.");
this.capture('ui-id-1.png');
});
@r3b
r3b / rnd.go
Last active December 19, 2015 12:19
Go's Pseudo-random number generator isn't very pseudo. In fact, it's not random at all.
//https://code.google.com/p/go/issues/detail?id=4509
package main
import (
"fmt"
"time"
"math/rand"
)
var out = make(chan string, 3)
var done = make(chan bool)
func f(c chan<- string) {
@r3b
r3b / cssCheck.js
Last active November 24, 2016 07:41
Analyzing CSS Selectors with PhantomJS
#!/usr/bin/env phantomjs --web-security=false
var system = require('system')
, page = require('webpage').create();
var address=system.args[1];
if(address===undefined){
console.warn("USAGE: phantomjs --web-security=false cssCheck.js <http://your-site.com/index.html>")
phantom.exit();
}
page.onConsoleMessage = function (msg) {console.log(msg);};
@r3b
r3b / CircularDoublyLinkedList.js
Created August 16, 2013 17:56
Circular Doubly-Linked List, derived from Nicolas Zakas' Doubly-Linked List implementation.
/*
* Doubly Linked List implementation in JavaScript
* Copyright (c) 2009 Nicholas C. Zakas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@r3b
r3b / pollyfills.js
Created August 16, 2013 18:29
A collection of random polyfills. YMMV.
//Array
([].indexOf)||(Array.prototype.indexOf=[].indexOf||function(a,b,c,r){for(c=this,b=b|0,r=-1;b++<c.length&&!~r;r=c[b]===a?b:r);return r});
([].map)||(Array.prototype.map=function(a){for(var b=this,c=b.length,d=[],e=0,f;e<b;)d[e]=e in b?a.call(arguments[1],b[e],e++,b):f;return d});
([].filter)||(Array.prototype.filter=[].filter||function(a,b,c,d,e){for(b=this,d=0,c=[];d<b.length;d++)if(a.call(b,e=b[d]))c.push(e);return c});
([].isArray)||(Array.isArray||(Array.isArray=function(a){return{}.toString.call(a)=='[object Array]'}));
([].every)||(Array.prototype.every=[].every||function(a,b,c,d){for(c=0,d=this;c<d.length;c++)if(!a.call(b,d[c],c,d))return!1;return!0});
([].some)||(Array.prototype.some=[].some||function(a,b,c,d){for(c=0,d=this;c<d.length;c++)if(a.call(b,d[c],c,d))return!0;return!1});
([].unique)||(Array.prototype.unique=function(a){return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0}));
//Function
Function.prototype.bind=(function(){}).bind||function(a,b){b=this;re
@r3b
r3b / squeeze.js
Last active December 22, 2015 02:19
collapse vertical whitespace between stacked siblings in div
Function.prototype.debounce = function (threshold, execAsap) {
var func = this,timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap) func.apply(obj, args);
timeout = null;
};
if (timeout) clearTimeout(timeout);
else if (execAsap) func.apply(obj, args); // execute now
@r3b
r3b / gist:6718179
Created September 26, 2013 18:09
replace text in place
var iframe = document.getElementById('bannerContent_ifr')
function replaceQuotes(text){
return text.replace(/(.)/g,function($1){
var c=$1.charCodeAt(0), n=$1;
switch(c){
case 8220: case 8221:
n='"';
break;
case 8216: case 8217:
n="'";
@r3b
r3b / browser.js
Created November 18, 2013 19:42
Minimalist browser userAgent parsing based on data from https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
//Minimalist browser name/version parsing based on data from
//https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
function createBrowserRegex(browser){
return new RegExp('\\b('+browser+')\\/([^\\s]+)');
}
function createBrowserTest(userAgent, positive, negatives){
var matches = BROWSER_REGEX[positive].exec(userAgent);
negatives=negatives||[];
if(matches && matches.length && !negatives.some(function(negative){return BROWSER_REGEX[negative].exec(userAgent)})){
return matches.slice(1,3);