Skip to content

Instantly share code, notes, and snippets.

View toadkicker's full-sized avatar
🏠
Let's fix some stuff

Todd Baur toadkicker

🏠
Let's fix some stuff
View GitHub Profile
@toadkicker
toadkicker / gist:6003393
Created July 15, 2013 20:56
DOM searching for a string
var search = document.evaluate('//text()[contains(., \"username\")]',
document, null, XPathResult.ANY_TYPE, null);
@toadkicker
toadkicker / gist:6016984
Created July 17, 2013 01:42
check for element and stop checking when done
var checkExist = setInterval(function() {
if ($('#the-canvas').length) {
console.log("Exists!");
clearInterval(checkExist);
}
}, 100);
@toadkicker
toadkicker / gist:6031104
Created July 18, 2013 17:14
Convert old ruby hash syntax to new
find . -type f -iname '*.rb' | xargs ruby -i -pe 'gsub(/(?<!:):(\w+)\s*=>\s*/, "\\1: ")
# Automatic create and set html hidden field
# base on Bootstrap buttons radio values
# Javascript/Coffeescript plugin
#
# Html/Slim
# .btn-group data-toggle='buttons-radio' data-field='offer[type]' data-init-val=@offer.type
# a.btn href='#' data-val='flat' Flat
# a.btn href='#' data-val='house' House
#
# Usage

Project

Description: What does this project do and who does it serve?

Project Setup

How do I, as a developer, start working on the project?

  1. What dependencies does it have (where are they expressed) and how do I install them?
  2. How can I see the project working before I change anything?
@toadkicker
toadkicker / array.first.js
Last active December 21, 2015 09:59
Stop writing for loops
if (!Array.prototype.first)
{
Array.prototype.first = function(predicate)
{
"use strict";
if (this == null)
throw new TypeError();
if (typeof predicate != "function")
throw new TypeError();
@toadkicker
toadkicker / gist:6311772
Created August 22, 2013 19:34
Does a variable exist?
Scope.prototype.find = function(name, options) {
if (this.check(name, options)) {
return true;
}
this.add(name, 'var');
return false;
}
String.prototype.isValidEmail = function() {
var filter = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
if (!filter.test(this)) {
return false;
} else {
return true
}
}
@toadkicker
toadkicker / isValidPhone
Created September 3, 2013 21:06
Validate phone numbers
String.prototype.isValidPhone = function() {
var filter = /^[0-9a-zA-Z\s.:#\(\)\+\-]+$/;
if (!filter.test(this)) {
return false;
} else {
return true
}
}
(function(){
//allowed domains
var whitelist = ["foo.example.com", "www.example.com"];
function verifyOrigin(origin){
var domain = origin.replace(/^https?:\/\/|:\d{1,4}$/g, "").toLowerCase(),
i = 0,
len = whitelist.length;