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:5822980
Last active December 18, 2015 17:59
jQuery vs native
//ajax
$.ajax({
url: '/endpoint'
}).done(function(data){
// do something awesome
}).fail(function(xhr){
// sad little dance
});
var xhr = new XMLHttpRequest();
@toadkicker
toadkicker / gist:5827724
Created June 20, 2013 23:37
I wanted a way to have an inner gradient in a button with CSS3, and started working on input type="button"
<!DOCTYPE html>
<html>
<head>
<title>Fun with Buttons</title>
<style>
/*structure*/
.button, input[type="button"] {
box-shadow: .1em .2em .5em #aaa;
height: 22px;
display: block;
// Example:
JavaScript.load("/javascripts/something.js");
// With callback (that’s the good thing):
JavaScript.load("http://www.someawesomedomain.com/api.js", function() {
API.use(); // or whatever api.js provides ...
});
@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;
}