Skip to content

Instantly share code, notes, and snippets.

View dannycallaghan's full-sized avatar

Danny Callaghan dannycallaghan

  • London
View GitHub Profile
@dannycallaghan
dannycallaghan / SimpleWebServer
Created January 24, 2014 10:06
Simple web server on OSX
python -m SimpleHTTPServer 8000
@dannycallaghan
dannycallaghan / InstallHomebrew
Created January 24, 2014 10:05
Install Homebrew
// May ask you to install x-code command line tools
// If so, just follow the prompt
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@dannycallaghan
dannycallaghan / dannycustom.zsh-theme
Last active January 3, 2016 13:49
Custom theme for zsh. Heavily borrowed from Remy Sharp's set up.
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
#
@dannycallaghan
dannycallaghan / ShowHiddenFiles.sh
Created January 17, 2014 10:58
Show hidden files in OSX
// Show hidden files
$ defaults write com.apple.finder AppleShowAllFiles -boolean true
$ killall Finder
// Hide hidden files
$ defaults delete com.apple.finder AppleShowAllFiles
$ killall Finder
@dannycallaghan
dannycallaghan / Web Performance - Optimise Caching
Created December 5, 2013 09:14
Google Developers - Web Performance Best Practices - Optimise Caching. From https://developers.google.com/speed/docs/best-practices/caching
##### Optimise caching #####
### Leverage Browser Caching ###
- 'Expires' and 'Cache-Control: max-age'
Specify time period browser can use a local copy without checking for a newer version. Strong cache headers - will not issue a GET request until the expiry or max age is reached.
- 'Last-Modified' and 'ETag'
Specify some characteristic that the browser checks to see if the files are the same - 'Last-Modified' is always a date; 'ETag' is any value that uniquely identifies that resource, like version number or hash. Weak cache header - the browser applies a heuristic to determine whether to use a cahce copy or not (each browser uses a different heuristic). Uses a conditional GET though - don't return a full response unless the resource has changed (thus lower latency than full GETS).
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function () {
log.history = log.history || []; // store logs to an array for reference
log.history.push( arguments );
if ( this.console ){
console.log( Array.prototype.slice.call( arguments ) );
}
};
@dannycallaghan
dannycallaghan / Fast Max Min.js
Created October 17, 2013 11:24
Fast JavaScript Max/Min, John Resig. From http://ejohn.org/blog/fast-javascript-maxmin/
Array.max = function( array ){
return Math.max.apply( Math, array );
};
Array.min = function( array ){
return Math.min.apply( Math, array );
};
@dannycallaghan
dannycallaghan / Generic Namespace Function.js
Created October 11, 2013 08:23
Generic Namespace Function. From 'JavaScript Patterns' (O'Reilly) by Stoyan Stefanov.
/* Namespace Function */
var MYAPP = MYAPP || {};
MYAPP.namespace = function ( ns_string ) {
var parts = ns_string.split( '.' ),
parent = MYAPP, i;
if ( parts[ 0 ] === "MYAPP" ) {
parts = parts.slice( 1 );
}
@dannycallaghan
dannycallaghan / Currying - Partial Application.js
Created October 9, 2013 08:09
Currying / Partial Application From 'JavaScript Patterns' (O'Reilly) by Stoyan Stefanov.
/* Currying */
// Currying is making JavaScript functions understand and handle partial application
// A non-curried add functions
var add = function ( x, y ) {
return x + y;
};
// A curried add function
function add ( x, y ) {
@dannycallaghan
dannycallaghan / Memoization Pattern.js
Created October 9, 2013 08:08
Memoization Pattern From 'JavaScript Patterns' (O'Reilly) by Stoyan Stefanov.
/* Memoization Pattern */
// a single parameter example
var myFunc = function ( param ) {
if ( !myFunc.cache[ param ] ) {
var result = {};
// ... expensive operation ...
myFunc.cache[ param ] = result;
}
return myFunc.cache[ param ];