Skip to content

Instantly share code, notes, and snippets.

Richard Cornish richardcornish

Block or report user

Report or block richardcornish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:698166ad20783ec5f6795628fdeefa15
rm -r brokenews/_site/*
git clone -b gh-pages `git config remote.origin.url` _site
jekyll build
cd _site
git add .
git commit -m ''
git push
View gist:0533b67d85752a66f4e75a0357eda28a
git remote add upstream https://github.com/<user>/<repo>.git
git fetch upstream
git checkout master
git merge upstream/master
git push
@richardcornish
richardcornish / gist:ec833827a0612f1c311a02ec4b299612
Last active Jul 17, 2017
Create new Python package for PyPi
View gist:ec833827a0612f1c311a02ec4b299612
# Create environment
mkvirtualenv -p python3 mydjangopackage
pip install django sphinx sphinx-autobuild sphinx-rtd-theme
# Create demo environment
mkvirtualenv -p python3 mydjangopackagedemo
pip install django gunicorn psycopg2 whitenoise dj-database-url
# Create docs
mkdir docs
View lines.sh
#!/bin/bash
tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
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 / forms.py
Last active Jan 19, 2016
Breaking Django's form wizard (GenderFormBasic) out across views by manually hacking HiddenInput and RadioSelect
View forms.py
from __future__ import absolute_import
from django import forms
from django.contrib.auth import get_user_model
from django.utils.safestring import mark_safe
from utils.mixins import NoLabelSuffixMixin
from .utils import HiddenInput, RadioSelect
User = get_user_model()
@richardcornish
richardcornish / Django install
Last active Aug 24, 2016
The absolute bare minimum to run Django (requires Python, SQLite, pip, and virtualenv)
View Django install
virtualenv myproject
source myproject/bin/activate
pip install django
cd myproject/
django-admin startproject myproject
cd myproject/
python manage.py migrate
python manage.py runserver
@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 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 / 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
You can’t perform that action at this time.