Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Cornish richardcornish

View GitHub Profile
@richardcornish
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](https://itunes.apple.com/us/app/xcode/id497799835?mt=12)
@richardcornish
richardcornish / Mapbox Studio examples
Last active Aug 29, 2015
I fished these URLs out of the JSON requests in https://www.mapbox.com/design/
View Mapbox Studio examples
Space Station
https://a.tiles.mapbox.com/v4/examples.3hqcl3di/page.html?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q
Roadtrippers
https://a.tiles.mapbox.com/v4/examples.ra3sdcxr/page.html?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q
Assemblage (random)
https://a.tiles.mapbox.com/v4/saman.h6ek9086/page.html?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q
Wheatpaste
@richardcornish
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>.github.io 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 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
@richardcornish
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
# PHP
@richardcornish
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
View managers.py
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
http://www.movable-type.co.uk/scripts/latlong.html
@richardcornish
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
// https://github.com/h5bp/Front-end-Developer-Interview-Questions#jscode
// Usage:
// 1 = add(1)();
// 3 = add(1, 2)();
// 6 = add(1, 2)(3);
// 10 = add(1, 2)(3, 4);
// 0 = add()();
var add = function () {
View jquery.site.js
// 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
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
}