Skip to content

Instantly share code, notes, and snippets.

View jjmalina's full-sized avatar

Jeremiah Malina jjmalina

View GitHub Profile
@jjmalina
jjmalina / scale-canvas.js
Last active May 23, 2019 14:45
Scaling a 2D static canvas element
function scaleCanvas(canvas, options = {}) {
const imageData = canvas.toDataURL('image/png');
const context = canvas.getContext('2d');
const xScale = options.width !== undefined ? options.width / canvas.width : options.height / canvas.height;
const yScale = options.height !== undefined ? options.height / canvas.height : options.width / canvas.width;
const newWidth = Math.round(canvas.width * xScale);
const newHeight = Math.round(canvas.height * yScale);
canvas.width = newWidth;
canvas.newHeight = newHeight;
@jjmalina
jjmalina / earliest_commit.py
Created August 4, 2018 17:34
Get the first commit after a given date
#! /usr/bin/env python
import sys
from datetime import date
# pip install gitpython
from git import Repo
def get_earliest_commit_since(repo, dt):
@jjmalina
jjmalina / cop_ga_sessions.sh
Created November 14, 2016 20:33
Copy Google Analytics sessions data using BigQuery -> Google Cloud Storage -> Amazon S3
# usage
# ./copy_ga_sessions.sh <app> <ga_view> <day> <gcsbucket> <s3bucket>
app=$1
view=$2
day=$3
gcsbucket=$4
s3bucket=$5
format=NEWLINE_DELIMITED_JSON
tablename="$app:$view.ga_sessions_$day"
bucketname="$gcsbucket"
@jjmalina
jjmalina / debian-8-jessie-lenovo-x1-carbon-4th-gen.md
Last active July 6, 2021 17:45
Installing Debian 8.5 "jessie" on a Lenovo X1 Carbon 4th generation

Installing Debian 8.5 "jessie" on a Lenovo X1 Carbon 4th generation (20FB) - 2016

UPDATE 2018-02-24: I got a new Lenovo X1 Carbon 5th gen and tried to do the same setup with Debian 9.3.0. It was an utter failure because of some boot issues. I went with Xubuntu instead and everything works FLAWLESSLY. Xubuntu is beautiful.

I've had my mind on switching my development machine from a 13" MacBook Pro Retina to a Lenovo X1 Carbon running Linux for a while. The main reason is getting more familiar with Linux itself and also to have a more stable and minimal dev environment. So I finally got the machine and decided to install Debian 8.5 "jessie". Why Debian? Well, I tried installing Arch Linux once and couldn't get past getting wifi to work, and Ubuntu seemed like it added too much stuff. The choice was either Debian or Linux Mint. I went with Debian because it seems like it's the most stable.

Create a bootable USB stick

I followed the instructions at https://www.debian.org/releases/jessie/amd64/ch04s

@jjmalina
jjmalina / transducers.py
Last active October 24, 2015 22:55
Transducers in python
# -*- coding: utf-8 -*-
"""
transducers
~~~~~~~~~~~
Lazy evaluation of things over a stream. In this case we do a word count
"""
import types
import operator
@jjmalina
jjmalina / orders_source.py
Last active August 29, 2015 14:27
Coinbase Orders into Concord
# -*- coding: utf-8 -*-
"""
orders_source
~~~~~~~~~~~~~
Puts coinbase orders into Concord
"""
import time
import json
@jjmalina
jjmalina / coinbase.py
Created July 18, 2015 21:35
Real-time Coinbase orders and trades
# -*- coding: utf-8 -*-
"""
coinbase
~~~~~~~~
Real time Coinbase trades and orders using their Websocket Feed
https://docs.exchange.coinbase.com/?python#overview
"""
import asyncio
@jjmalina
jjmalina / datetime_to_epoch.py
Last active August 29, 2015 14:08
Because I keep forgetting this...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
datetime_to_epoch
~~~~~~~~~~~~~~~~~
Takes a (naive) UTC datetime and converts to epoch
"""
from calendar import timegm
@jjmalina
jjmalina / format_timedelta.py
Created April 23, 2014 20:00
Format a timedelta into the largest possible unit (weeks is the largest in this case)
def format_timedelta(td):
"""formats a timedelta into the largest unit possible
>>> from datetime import timedelta
>>> format_timedelta(timedelta(weeks=2))
'2w'
>>> format_timedelta(timedelta(weeks=2, minutes=2))
'20162m'
>>> format_timedelta(timedelta(days=2))
@jjmalina
jjmalina / gist:9492428
Last active August 29, 2015 13:57
Chef workflow
# modify the cookbook
knife spork bump <cookbook>
knife cookbook upload <cookbook>
knife spork promote <environment> <cookbook>
knife environment from file <environment>.json