Skip to content

Instantly share code, notes, and snippets.

View mattandrews's full-sized avatar

Matt Andrews mattandrews

View GitHub Profile
@mattandrews
mattandrews / hello-world.ts
Created February 22, 2024 14:54
Hello World in Typescript
let message: string = 'Hello, World!';
console.log(message);
const got = require('got'); // HTTP request client
const { CONTENT_API_URL, CONTENT_API_SANDBOX_URL } = require('./urls');
class ContentApiClient {
constructor() {
this.API_ENDPOINT = CONTENT_API_URL;
this.queryContentApi = null;
}
@mattandrews
mattandrews / averages.sql
Created July 8, 2019 11:36
Get average votes for yes, month-by-month
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
mattandrews / assetfix.js
Created March 1, 2019 15:59
Find hardlinked assets in SQL dumps and rename them
#!/usr/bin/env node
'use strict';
const _ = require('lodash');
const mysql = require('mysql');
require('dotenv').config();
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
@mattandrews
mattandrews / models.py
Created January 13, 2018 15:10
Django thumbnails for admin
def resize_images(image_field):
pathname, filename = path.split(image_field.path)
img_file = Image.open(image_field.path)
# 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
mattandrews / on-interact.scss
Created July 24, 2017 14:54
on-interact Sass mixin
// use this where you'd otherwise use '&:hover'
// to get accessible styling for keyboard navigation too
@mixin on-interact {
&:active,
&:focus,
&:hover {
@content;
}
}
#!/usr/bin/env python
import sys
import boto
import boto.ec2
import boto.ec2.elb
import boto.rds
import pprint
import argparse
var allStylesheets = document.styleSheets;
var classesUsed = [];
[].forEach.call(allStylesheets, function(sheet) {
for (var i = 0; i < allStylesheets.length; i++) {
try {
var sheet = allStylesheets[i];
for (var j = 0; j < sheet.cssRules.length; j++) {
classesUsed.push(sheet.cssRules[j].selectorText);
}
@mattandrews
mattandrews / main.js
Created December 10, 2015 16:01
Example usage of Web Audio API
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
mattandrews / audio.js
Created December 10, 2015 16:00
A Web Audio API example with code mostly taken from http://www.html5rocks.com/en/tutorials/webaudio/intro/ by Boris Smus
// original code from http://www.html5rocks.com/en/tutorials/webaudio/intro/
// with thanks to Boris Smus (https://twitter.com/borismus)
define([], function() {
var context;
var bufferLoader;
var BUFFERS_TO_LOAD;
var BUFFERS = {};
var SOURCES = {};
var maxGain = 1;