Skip to content

Instantly share code, notes, and snippets.

@mrcoles
mrcoles / game.js
Last active January 5, 2018 17:35
Space creatures
'use strict';
// Space Creatures
// ===============
//
// Involves:
//
// * Needs a game screen
// * alien creatures (3 different types)
// * a defender
@mrcoles
mrcoles / rc_fastai_setup.sh
Created January 16, 2018 17:38
Setup script for fast.ai on an rc cluster machine
#!/usr/bin/env bash
# derived from https://github.com/fastai/courses/blob/master/setup/install-gpu.sh
# exit on failed commands also print all commands
set -ex
cd $HOME
@mrcoles
mrcoles / make_imgs.py
Created January 17, 2018 22:16
Convert the MNIST CSV dataset from Kaggle to png images
#!/usr/bin/env python3
import csv
import os
import pathlib
import imageio
import numpy as np
@mrcoles
mrcoles / pause-gifs.css
Created February 15, 2018 18:22
A lightweight approach to pausing gifs on a webpage.
/** .pause-gif */
.wrap-pause-gif {
position: relative;
text-align: center;
}
.pause-gif {
visibility: hidden;
}
@mrcoles
mrcoles / offset.js
Created June 18, 2018 22:27
Compute the offset of a DOM element taking into account CSS transforms and scrolled parents.
export const computeOffset = elt => {
let rect = elt.getBoundingClientRect();
let width = rect.width;
let height = rect.height;
let left = 0;
let top = 0;
let offsetParent = elt;
while (offsetParent) {
left += offsetParent.offsetLeft;
@mrcoles
mrcoles / fill-mixed-text.js
Last active February 14, 2023 13:15
A simple function for writing mixed color and/or font text on an HTML5 Canvas object.
// # HTML5 Canvas: Fill Mixed Text
//
// ctx: CanvasRenderingContext2D
// args: array of objects of form
// { text: string, fillStyle?: string, font?: string }
// x: number
// y: number
//
const fillMixedText = (ctx, args, x, y) => {
let defaultFillStyle = ctx.fillStyle;
@mrcoles
mrcoles / console-group-decorator.d.ts
Last active March 22, 2021 01:49
A decorator for wrapping a function in a `console.group(msg)` -> `console.groupEnd()` call.
export function groupCollapsedFn<F extends Function>(
msg: any, func: F,
): F;
export function groupFn<F extends Function>(
msg: any, func: F, isCollapsed?: boolean
): F;
@mrcoles
mrcoles / index.html
Created October 5, 2018 16:26
redux-undo@1.0.0-beta-9.9.7 filter inconsistency
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Redux Undo Filter Test</title>
</head>
<body>
<p>See info in JS console</p>
<script src="store.js"></script>
</body>
@mrcoles
mrcoles / AsyncStripeProvider.js
Last active December 8, 2020 14:28
A react provider abstraction for loading the stripe.js file asynchronously to use with Stripe Elements
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { StripeProvider } from 'react-stripe-elements';
export default class AsyncStripeProvider extends Component {
static propTypes = {
apiKey: PropTypes.string.isRequired
};
// constructor
@mrcoles
mrcoles / compress-video.sh
Last active September 15, 2022 12:15
Script for compressing a video to .mp4 and .webm with ffmpeg
#!/usr/bin/env bash
# inspired by: https://gist.github.com/Vestride/278e13915894821e1d6f
INPUT=$1
OUTDIR="out/"
if [ -z "$INPUT" ]; then
echo "No file specified"
exit 1