Skip to content

Instantly share code, notes, and snippets.

View johnhunter's full-sized avatar
🔋
Working on net-zero energy 🔋⚡️📈

John Hunter johnhunter

🔋
Working on net-zero energy 🔋⚡️📈
View GitHub Profile
@johnhunter
johnhunter / gist:2437138
Created April 21, 2012 13:45
Add a local repo to a remote
Create a git repo and push to remote:
mkdir new_git_repo
cd new_git_repo
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@my.remote.com/new_git_repo.git
git push -u origin master
@johnhunter
johnhunter / String.subs.js
Created April 17, 2012 11:33
Simple string interpolation
// use: String.subs('There is no ${foo} foo', { foo: 'bar' })
String.subs = String.subs || function (str, props) {
return str.replace(/\$\{([^{}]*)}/g, function (a, b) {
var r = props[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
});
};
@johnhunter
johnhunter / html-template.html
Created March 14, 2012 06:56
Basic html template
<!DOCTYPE html>
<!--[if lte IE 6 ]><html class="ie ie6 non-js"><![endif]-->
<!--[if IE 7 ]><html class="ie ie7 non-js"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8 non-js"><![endif]-->
<!--[if gte IE 9 ]><html class="ie ie9 non-js"><![endif]-->
<!--[if !IE]>-->
<html class="non-js">
<!--<![endif]-->
@johnhunter
johnhunter / useful-mixins.less
Created January 22, 2012 10:24
Less mixins
/*
Less mixins (http://css-tricks.com/snippets/css/useful-css3-less-mixins/)
*/
.text-shadow (@string: 0 1px 3px rgba(0, 0, 0, 0.25)) {
text-shadow: @string;
}
.box-shadow (@string) {
-webkit-box-shadow: @string;
-moz-box-shadow: @string;
box-shadow: @string;
@johnhunter
johnhunter / app.js
Created December 10, 2011 21:53
Nodejs chat with socket.io
/*
Websockets using http://socket.io/
Also with express web mvc framework http://expressjs.com/
*/
var app = require('express').createServer(),
io = require('socket.io').listen(app),
port = 88;
@johnhunter
johnhunter / gist:1438452
Created December 6, 2011 14:50
Have Alfed search the jquery API docs
alfredapp://customsearch/Search%20JQuery%20API/jquery/ascii/url=http://api.jquery.com/?s={query}
@johnhunter
johnhunter / gist:1362075
Created November 13, 2011 12:46
Example JavaScript Pseudo-class
// Example Pseudo-class
var Animal = (function() {
function Animal(name) {
this.name = name;
}
Animal.prototype.getName = function () {
return this.name;
};
@johnhunter
johnhunter / jquery.minmax.js
Created November 3, 2011 18:53
Run min / max over a JQuery object to equalise heights etc.
/*
min, max - jQuery plugins which set css properties to min/max value for the collection
@author John Hunter
created 2011-11-03
use: $('li.tabs').max('height');
*/
(function ($) {
$.fn.max = function (prop) { return foldProp(this, Math.max, prop); };
$.fn.min = function (prop) { return foldProp(this, Math.min, prop); };
@johnhunter
johnhunter / gist:1297920
Created October 19, 2011 10:29
Weinre mobile remote debug booklarklet
javascript:(function(e,h){h=prompt('Enter hostname (return for localhost)');h=h||'localhost';e.setAttribute("src","http://"+h+":8081/target/target-script-min.js#anonymous");document.getElementsByTagName("body")[0].appendChild(e);}(document.createElement("script")));
@johnhunter
johnhunter / modules.html
Created October 10, 2011 18:42
Files that acompany the JavaScript workshop on 10th Oct 2011
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>Modules</title>
</head><body><script>