Skip to content

Instantly share code, notes, and snippets.

View chrisjhoughton's full-sized avatar

Chris Houghton chrisjhoughton

  • Beacon
  • London, UK
View GitHub Profile
var ucFirst = function (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
};
@chrisjhoughton
chrisjhoughton / wait-global.js
Created December 10, 2013 13:02
Wait for a global variable to exist on the page.
var waitForGlobal = function(key, callback) {
if (window[key]) {
callback();
} else {
setTimeout(function() {
waitForGlobal(key, callback);
}, 100);
}
};
@chrisjhoughton
chrisjhoughton / cookie.js
Last active December 30, 2015 21:50
Generic cookie functions
@chrisjhoughton
chrisjhoughton / foreach.js
Created December 10, 2013 13:04
Foreach from MoutJS. Never write a for loop again!
var forEach = function(arr, callback, thisObj) {
if (arr === null) {
return;
}
var i = -1,
len = arr.length;
while (++i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (callback.call(thisObj, arr[i], i, arr) === false) {
@chrisjhoughton
chrisjhoughton / average.js
Created December 10, 2013 13:05
Very basic max, min, average functions. All depend on forEach: https://gist.github.com/chrisjhoughton/7890274
var average = function (arr) {
var total = 0;
forEach(arr, function (number) {
total += number;
});
return total / arr.length;
};
@chrisjhoughton
chrisjhoughton / wait-el.js
Last active October 6, 2023 09:46
Wait for an element to exist on the page with jQuery
var waitForEl = function(selector, callback) {
if (jQuery(selector).length) {
callback();
} else {
setTimeout(function() {
waitForEl(selector, callback);
}, 100);
}
};
@chrisjhoughton
chrisjhoughton / indexOf.js
Created December 10, 2013 13:07
Cross-browser compatible indexOf
var indexOf = function(arr, item, fromIndex) {
fromIndex = fromIndex || 0;
if (arr === null) {
return -1;
}
var len = arr.length,
i = fromIndex < 0 ? len + fromIndex : fromIndex;
while (i < len) {
// we iterate over sparse items since there is no way to make it
@chrisjhoughton
chrisjhoughton / keenio-iframe.js
Created December 18, 2013 14:13
Load Keen.io JavaScript data collection SDK in a local iframe. The primary use-case for this is if you're tracking across multiple client sites and do not wish to pollute global name-spacing.
// Sample options to pass to Keen.configure
// {
// projectId: "your_project_id",
// writeKey: "your_write_key",
// }
var loadKeen = function (options, cb) {
var iframe = document.createElement("iframe");
iframe.style.display = "none";
@chrisjhoughton
chrisjhoughton / snippet.js
Last active January 2, 2016 07:39
The Sauce JavaScript snippet.
window.Sauce = {
isReady: false,
options: {},
object: {},
describe: function (type, data) {
this.object[type] = data;
@chrisjhoughton
chrisjhoughton / proxy.apache.conf
Last active April 26, 2024 06:26
Sample Nginx reverse proxy to Apache set up for Wordpress.
<VirtualHost *:{PORT}>
ServerName www.yourdomain.com
ServerAdmin mail@domain.com
DocumentRoot /var/www/yourdir/
<Directory /var/www/yourdir>
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny