Skip to content

Instantly share code, notes, and snippets.

View darbicus's full-sized avatar

Darby Rathbone darbicus

  • Texas
View GitHub Profile
@darbicus
darbicus / peg.js
Created May 1, 2014 05:43
PEMDAS parser made using pegjs
module.exports = (function() {
/*
* Generated by PEG.js 0.8.0.
*
* http://pegjs.majda.cz/
*/
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
@darbicus
darbicus / HTMLtoJS
Created June 23, 2014 20:35
Simple way to convert HTML to JS
var htmlToElements = (function () {
var div = document.createElement('div');
return function (s) {
div.innerHTML = s;
return div.childNodes;
};
}());
console.dir(htmlToElements('<div><span>test</span></div>'));
@darbicus
darbicus / cereal.js
Created July 17, 2014 18:07
serialize javascript objects for get http requests that submit data
function cerealize(object) {
return Object.getOwnPropertyNames(object)
.filter(function (e) {
return typeof object[e] !== 'function' && object[e].toString
})
.map(function (n) {
return encodeURIComponent(n) + "=" + encodeURIComponent(object[n]);
})
.join("&")
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Pricing Calculator</title>
<script src='moment.js'></script>
<script type='text/javascript' src='jquery-git2.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
var _a = [
{"Period": "Off-Peak", "From": "4/21/2014", "To": "7/24/2014", "Nightly": 100, "Minimum Stay": "3 nights"},
{"Period": "Peak", "From": "7/24/2014", "To": "9/1/2014", "Nightly": 120, "Minimum Stay": "7 nights", "Price Based on": "4 guests"},
{"Period": "Off-Peak", "From": "9/1/2014", "To": "10/23/2014", "Nightly": 100, "Minimum Stay": "3 nights", "Price Based on": "4 guests"},
{"Period": "Peak", "From": "10/23/2014", "To": "11/3/2014", "Nightly": 120, "Minimum Stay": "7 nights", "Price Based on": "4 guests"},
{"Period": "Off-Peak", "From": "11/3/2014", "To": "12/18/2014", "Nightly": 100, "Minimum Stay": "3 nights", "Price Based on": "4 guests"},
{"Period": "Peak", "From": "12/18/2014", "To": "1/5/2015", "Nightly": 120, "Minimum Stay": "7 nights", "Price Based on": "4 guests"},
{"Period": "Off-Peak", "From": "1/5/2015", "To": "4/2/2015", "Nightly": 100, "Minimum Stay": "3 nights", "Price Based on": "4 guests"},
{"Period": "Peak", "From": "4/2/2015", "To": "4/20/2015",
@darbicus
darbicus / addEvent
Created August 29, 2014 23:00
Sometimes I wish addEventListener in javascript would return an object so that you can cancel the event without having to name the function. So I created one but instead of replacing the prototype function I just added a new function addEvent which takes the same arguments as the addEventListener function and it returns a function that removes t…
EventTarget.prototype.addEvent = function () {
var args = [].slice.call(arguments);
var remove = (function () {
this.removeEventListener.apply(this, args);
}).bind(this);
this.addEventListener.apply(this, arguments);
return remove;
};
@darbicus
darbicus / getElementCssStyleRules.js
Created September 4, 2014 21:45
getElementCssStyleRules is a function to return an array of the css rules that affect the element supplied to the function...
var getElementCSSStyleRules = function (f) {
var myElement = f;
var r = [];
[].slice.call(document.styleSheets).forEach(function (rules) {
[].slice.call(rules.rules).forEach(function (e) {
if ([].slice.call(document.querySelectorAll(e.selectorText)).indexOf(f) !== -1) {
e.toString = function(){return this.selectorText;};
r.push(e);
}
@darbicus
darbicus / mirc.ini
Created December 28, 2014 18:26
just find your mirc.ini file in C;/users/username/AppData/(local|Roaming)/Mirc/mirc.ini
[fonts]
fchannel=Lucida Sans Unicode,100,0,0,0,10
fquery=Lucida Sans Unicode,100,0,0,0,10
// look for something like this and repace it with this
@darbicus
darbicus / YouBlock.js
Last active August 29, 2015 14:25
Youblock is a greasemonkey script to block YouTube live streaming spammers by clicking flag for spam.
// ==UserScript==
// @name spammer filter
// @namespace spam
// @description created to filter people from youtube chat rooms
// @include https://www.youtube.com/*
// @version 1
// @grant none
// ==/UserScript==
var names = [
];