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 / cassandra-install.sh
Last active July 3, 2017 18:59
install cassandra test instance
//Adapted from https://www.digitalocean.com/community/articles/how-to-install-cassandra-and-run-a-single-node-cluster-on-a-ubuntu-vps
USER=cassandra
GROUP=cassandra
mkdir ~/temp
cd ~/temp
wget http://www.us.apache.org/dist/cassandra/1.2.16/apache-cassandra-1.2.16-bin.tar.gz
tar -xvzf apache-cassandra-1.2.16-bin.tar.gz
mv apache-cassandra-1.2.16 ~/cassandra
sudo mkdir /var/lib/cassandra
sudo mkdir /var/log/cassandra
@r3b
r3b / module.js
Created February 12, 2014 06:04
A nice, simple module container for the browser or Node.
//noinspection ThisExpressionReferencesGlobalObjectJS
(function (global) {
var name = 'MyModule',
short = '_m',
_name = global[name],
_short = (short !== undefined) ? global[short] : undefined;
function Module() {
/* put code in here */
@r3b
r3b / defib.js
Created February 12, 2014 06:01
Turn a constant, erratic method execution into a nice, steady pace.
function defib(fn, space, scope) {
space || (space = 1000);
var queue = [], timer;
function start() {
if (queue.length) {
var exec = queue.shift(),
context = exec.context,
args = exec.args;
fn.apply(context, args);
} else {
@r3b
r3b / KeyStore.html
Created February 4, 2014 21:27
Playing with IndexedDB
<html>
<head>
<meta charset="utf-8">
<title>IndexedDB Tests</title>
<script>
function isFunction(f) {
return (f && f !== null && typeof(f) === 'function');
}
</script>
<script src="KeyStore.js"></script>
@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);
@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 / 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 / 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 / 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 / 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);};