Skip to content

Instantly share code, notes, and snippets.

Matt Andrews mattandrews

Block or report user

Report or block mattandrews

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
mattandrews / averages.sql
Created Jul 8, 2019
Get average votes for yes, month-by-month
View averages.sql
select DATE_FORMAT(createdAt, "%Y-%m-01") AS month, count(choice) as votesTotal,
(SELECT count(choice)
FROM survey
WHERE choice = 'no'
AND YEAR(createdAt) = YEAR(month) AND MONTH(createdAt) = MONTH(month)
) AS numNoVotes,
(SELECT 100 - numNoVotes / count(choice) * 100) AS percentageVotedYes
from survey
GROUP BY DATE_FORMAT(createdAt, "%Y-%m-01")
mattandrews / assetfix.js
Created Mar 1, 2019
Find hardlinked assets in SQL dumps and rename them
View assetfix.js
#!/usr/bin/env node
'use strict';
const _ = require('lodash');
const mysql = require('mysql');
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
mattandrews /
Created Jan 13, 2018
Django thumbnails for admin
def resize_images(image_field):
pathname, filename = path.split(image_field.path)
img_file =
# Convert to RGB
if img_file.mode not in ('L', 'RGB'):
img_file = img_file.convert('RGB')
# Save a thumbnail file for each of the given dimensions,
# prefixed with med_, small_ etc
mattandrews / on-interact.scss
Created Jul 24, 2017
on-interact Sass mixin
View on-interact.scss
// use this where you'd otherwise use '&:hover'
// to get accessible styling for keyboard navigation too
@mixin on-interact {
&:hover {
#!/usr/bin/env python
import sys
import boto
import boto.ec2
import boto.ec2.elb
import boto.rds
import pprint
import argparse
View getClasses.js
var allStylesheets = document.styleSheets;
var classesUsed = [];
[], function(sheet) {
for (var i = 0; i < allStylesheets.length; i++) {
try {
var sheet = allStylesheets[i];
for (var j = 0; j < sheet.cssRules.length; j++) {
mattandrews / main.js
Created Dec 10, 2015
Example usage of Web Audio API
View main.js
define(['audio'], function (audio) {
var mp3s = {
'track1': 'foo/bar/1.mp3',
'track2': 'foo/bar/1.mp3',
'track3': 'foo/bar/1.mp3'
audio.init(mp3s, function() {
// this callback will fire when all the mp3s
mattandrews / audio.js
Created Dec 10, 2015
A Web Audio API example with code mostly taken from by Boris Smus
View audio.js
// original code from
// with thanks to Boris Smus (
define([], function() {
var context;
var bufferLoader;
var BUFFERS = {};
var SOURCES = {};
var maxGain = 1;
mattandrews / unique-chars.js
Created Nov 20, 2015
Get all unique characters on a webpage
View unique-chars.js
var chars = [];
var logCharacters = function(str) {
var letters = str.split('');
l = l.trim(); // we don't need spaces
if (chars.indexOf(l) === -1) {
mattandrews /
Last active Nov 20, 2016
Scale, crop and trim videos for Snapchat
# this script does four things:
# 1. detects any crop marks (black bars) on the source clip
# 2. uses those crop marks to trim the clip so it has no bars (semi-manual task)
# 3. scales the video up ands crops it (from the center) to snapchat size
# 4. trims the clip to 10s long (might make sense to do this step first?)
You can’t perform that action at this time.