Skip to content

Instantly share code, notes, and snippets.


Richard Cornish richardcornish

View GitHub Profile
richardcornish / Modern setup
Last active Aug 29, 2015
Notes on installing and upgrading with modern web development tools
View Modern setup
# Paths
touch ~/.bash_profile
echo -e "#Paths\nexport PATH=/usr/local/bin:\$PATH\n"|cat - ~/.bash_profile > /tmp/out && mv /tmp/out ~/.bash_profile
source ~/.bash_profile
# Permissions
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/local
# Command line tools from [Xcode](
richardcornish / Mapbox Studio examples
Last active Aug 29, 2015
I fished these URLs out of the JSON requests in
View Mapbox Studio examples
Space Station
Assemblage (random)
richardcornish / GitHub pages branch
Last active Aug 29, 2015
Creates a gh-pages branch based on a gh-pages directory, and serves its contents as a <username> website
View GitHub pages branch
# First time
mkdir gh-pages
touch gh-pages/index.html
git add gh-pages
git commit -m "First commit of GitHub Pages branch"
git push origin master
# Subsequent times
# Edit, save, commit, push files inside gh-pages directory
git subtree push --prefix gh-pages origin gh-pages
View Sublime Text 2 command line shortcut
sudo ln -s "/Applications/Sublime Text" /usr/local/bin/subl
richardcornish / Local web server
Created Oct 15, 2014
Runs a local web server from an arbitrary directory
View Local web server
# Python 2.x
python -m SimpleHTTPServer 8000
# Python 3
python -m http.server
# Ruby
ruby -run -e httpd . -p 8000
richardcornish / JavaScript madness
Last active Aug 29, 2015
An incomplete list of bizarre failings of the JavaScript programming language
View JavaScript madness
- Prototypal inheritance forces an unstated empty object onto your object with key "prototype"
- functions can act as object constructors but with the same syntax
- empty array members break loops
- Infinity/-Infinity
- +0/-0
- null is an object
- testing NaN === NaN is *always false*
- typeof always returns "object" for all different reference types
- the type of NaN (not a number) is literally "number" but as a string
- void looks like a Java class but its only job is to return undefined
from decimal import Decimal
from django.db import models, connection
class LocationManager(models.Manager):
def find_nearby(self, latitude, longitude, radius, is_miles=True):
Uses Spherical Law of Cosines to determine places within a radial distance
richardcornish / Adder adder
Last active Aug 29, 2015
Uses variable-length arguments and closures to create an adding adding function
View Adder adder
// H5BP Front-end Developer Interview Questions
// Usage:
// 1 = add(1)();
// 3 = add(1, 2)();
// 6 = add(1, 2)(3);
// 10 = add(1, 2)(3, 4);
// 0 = add()();
var add = function () {
// One global variable for all your JavaScript
var MY_SITE = window.MY_SITE || {};
// Requires jQuery
// Global jQuery object is aliased to avoid polluting global namespace with "$"
MY_SITE = (function ($) {
'use strict';
var private_function;
richardcornish / Quest mode in Google Maps
Created Apr 20, 2012
How to add the Quest mode in Google Maps from April Fools Day 2012
View Quest mode in Google Maps
// Set map options
var mapOptions = {
center: new google.maps.LatLng(41.917142, -87.673837), // Or whatever
zoom: 15,
mapTypeId: "quest",
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, "quest"]
scrollwheel: false