Skip to content

Instantly share code, notes, and snippets.

Jeremiah Malina jjmalina

Block or report user

Report or block jjmalina

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
@jjmalina
jjmalina / scale-canvas.js
Last active May 23, 2019
Scaling a 2D static canvas element
View scale-canvas.js
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 Aug 4, 2018
Get the first commit after a given date
View earliest_commit.py
#! /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 Nov 14, 2016
Copy Google Analytics sessions data using BigQuery -> Google Cloud Storage -> Amazon S3
View cop_ga_sessions.sh
# 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 Feb 25, 2018
Installing Debian 8.5 "jessie" on a Lenovo X1 Carbon 4th generation
View debian-8-jessie-lenovo-x1-carbon-4th-gen.md

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 Oct 24, 2015
Transducers in python
View transducers.py
# -*- 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 Aug 29, 2015
Coinbase Orders into Concord
View orders_source.py
# -*- coding: utf-8 -*-
"""
orders_source
~~~~~~~~~~~~~
Puts coinbase orders into Concord
"""
import time
import json
@jjmalina
jjmalina / coinbase.py
Created Jul 18, 2015
Real-time Coinbase orders and trades
View coinbase.py
# -*- 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 Aug 29, 2015
Because I keep forgetting this...
View datetime_to_epoch.py
#!/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 Apr 23, 2014
Format a timedelta into the largest possible unit (weeks is the largest in this case)
View format_timedelta.py
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 Aug 29, 2015
Chef workflow
View gist:9492428
# modify the cookbook
knife spork bump <cookbook>
knife cookbook upload <cookbook>
knife spork promote <environment> <cookbook>
knife environment from file <environment>.json
You can’t perform that action at this time.