Skip to content

Instantly share code, notes, and snippets.

View asawilliams's full-sized avatar

Asa Williams asawilliams

View GitHub Profile
@asawilliams
asawilliams / perfTest.js
Created July 7, 2011 15:09
JavaScript function for comparing performance of multiple functions. Pass in an object in this format {name: functionName, ...}
function perf(fo) {
var results = [];
// perform test
for(key in fo) {
var f = fo[key];
var start = new Date().getTime();
for(var j=0;j<10000;j++) {
f();
}
var end = new Date().getTime();
@asawilliams
asawilliams / globalProps.js
Created July 7, 2011 15:11
Finds all the global functions and variables. Tries to not count the native browser functions and variables but does not catch all of them
var numf=0; var nump=0;
for(var p in this) {
if(typeof(this[p]) == "function" && this[p].toString().indexOf('[native code]') === -1 ){
numf+=1;
console.log(p+"()");
} else if(typeof this[p] != 'undefined' && this[p] && this[p].toString().indexOf('[native code]') === -1){
var cont = false;
if(typeof this[p] === 'object') {
for(op in this[p]) {
if(p[op] && p[op].toString().indexOf('[native code]') === -1){
@asawilliams
asawilliams / delayed_image_loading.css
Created November 2, 2011 15:18
Delays the background image displaying until loaded. After loaded it will then fade out the overlay to display the background image. This is used for larger image file sizes. This code represents a proof of concept.
#bg-overlay {
position: absolute;
top: 0;
height: 100%;
width: 100%;
background-color: #444; /* What ever you want to the default background to look like before the image is displayed */
z-index: -1;
}
.bg-img {
background-image: url('http://www.location/of/really/big/image.jpg');
@asawilliams
asawilliams / redirect.js
Created December 21, 2011 00:13
This is to be used with History.js. It removes all the hash stuff added when a user uses an HTML4 browser
var hashUrl = window.location.hash;
if(hashUrl !== '') {
var url = hashUrl.replace('#',''); // remove #
var redirectUrl = window.location.protocol+'//'+window.location.host;
var path = window.location.pathname;
url = url.split('_suid')[0]; // remove everything after this
// if there are no vars, remove the ?&
if(url.indexOf('?') <= (url.length+2)) {
@asawilliams
asawilliams / analyze.js
Created February 6, 2012 19:38
Find all the occurrences of every string in a JS file.
var analyze = function() {
var scriptData,
strings,
occurances;
/*
* Analyze a single script to determine
* how often a string is used.
* s: html script object.
@asawilliams
asawilliams / bracket_to_dot
Created June 6, 2012 23:03
chnages the format of a serialized object to use dot notation instead of brackets
// params is serialized object
params.replace(/%5B([a-zA-Z]+)%5D/g, '.$1');
@asawilliams
asawilliams / gist:3188939
Created July 27, 2012 16:16
performance timer
var performance = {
map: {},
start: function(key) {
this.map[key] = {};
this.map[key].start = Date.now();
},
end: function(key) {
this.map[key].end = Date.now();
},
display: function(key) {
@asawilliams
asawilliams / section.sublime-snippet
Created October 19, 2012 03:06
css style guide topics and css section snippets for sublime text
<snippet>
<content><![CDATA[
/* ==========================================================================
${1:Section comment block}
========================================================================== */
${2}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>/*=</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->