Skip to content

Instantly share code, notes, and snippets.

View liddiard's full-sized avatar
🙃

Harrison Liddiard liddiard

🙃
View GitHub Profile
@liddiard
liddiard / blank_template.html
Last active July 7, 2017 01:10
Blank starter validated HTML5 template. Features: UTF-8 encoding, meta description, Open Graph tags, favicon, Google Fonts, jQuery (pinned to a specific version), links to an external user-generated CSS and JavaScript file.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<title>Page title</title>
<meta name="description" content="Page description, shows up in search results. Should be no longer than 150-160 characters." />
{
"content_item": {
"id": 81424633,
"create_time": "2014-09-19T23:36:06Z",
"last_modified_time": "2014-09-20T22:58:13Z",
"expire_time": null,
"slug": "la-me-pc-gov-brown-disposes-of-bills-20140919",
"title": "Governor disposes of mandating diaper changing stations in men's rooms",
"display_time": "2014-09-20T00:02:00Z",
"ad_keywords": null,
@liddiard
liddiard / googleSheetsPrettify.js
Last active July 24, 2020 13:45
Make a JSON feed from Google Sheets more pretty to work with – removes "gsx$" key prefixes, un-nests unnecessarily nested objects. Make a GET request to a URL in this format: https://spreadsheets.google.com/feeds/list/126o06NkYz3rLRrIbzKAeLtrK-4a_Eosccmoser11hnk/od6/public/values?alt=json, and pass the resulting JSON to this function.
function prettifyGoogleSheetsJSON(data) {
for (var i = 0; i < data.feed.entry.length; i++) {
for (var key in data.feed.entry[i]) {
if (data.feed.entry[i].hasOwnProperty(key) && key.substr(0,4) === 'gsx$') {
// copy the value in the key up a level and delete the original key
data.feed.entry[i][key.substr(4)] = data.feed.entry[i][key].$t;
delete data.feed.entry[i][key];
}
}
}
@liddiard
liddiard / twidder_models.py
Last active August 29, 2015 14:12
Mock database design for Twidder, a social networking app that has nothing at all to do with a social networking app of a similar name.
from django.db import models
class User(models.Model):
# Django's auth framework provides its own very
# capable user model, but we'll make our own
# assuming English/Western-style names –
# first name/last name distinction doesn't apply in all cultures
first_name = models.CharField(max_length=64)
// Takes a year, month, and day number and outputs a string in the format "Dec 05, 2012".
// 'month' input parameter starts with zero.
function convertDateToEnglishString(day, month, year) {
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
try {
var monthName = monthNames[month];
} catch (e) {
alert('Invalid date');
return;
@liddiard
liddiard / hw02.cpp
Last active August 29, 2015 14:13
PIC 10A Homework 2
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
const int FIRST_COL_WIDTH = 20;
const int SECOND_COL_WIDTH = 10;
@liddiard
liddiard / init.coffee
Created February 10, 2015 23:28
GitHub Atom editor config scripts
# use two-space tabs for JavaScript
path = require 'path'
atom.workspaceView.eachEditorView (editorView) ->
editor = editorView.getEditor()
filepath = editor.getPath()
# set Tab Length for JS sources
if path.extname(filepath) is '.js'
function astContains(ast, nodeType) {
walk(ast, function(node) {
if (node.type === nodeType)
return true;
});
return false;
}
@liddiard
liddiard / cache_drf_list_view.py
Created April 23, 2015 22:28
Custom full-response caching setup for Django Rest Framework list view where keys are unique URLs. Opted to not continue with the invalidation on model save code cause cache invalidation is hard.
def list(self, request, *args, **kwargs):
# get the base url without any query params
url = request.path
params = []
# build a list of 2-value tuples which contains query params
for key, value in request.GET.iteritems():
params.append((key, value))
if params:
# sort the params so e.g., ?bunny=cute&fox=sly is treated as the
# same key as ?fox=sly&bunny=cute
var ALL_SPORTS = "[all sports]";
var ALL_YEARS = "[all years]";
var FilterableChampionshipList = React.createClass({
getInitialState: function() {
return {
viewingSport: ALL_SPORTS,
viewingYear: ALL_YEARS
};
},