Skip to content

Instantly share code, notes, and snippets.

View jjmalina's full-sized avatar

Jeremiah Malina jjmalina

View GitHub Profile
@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
@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 / 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 / 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 / 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 / pre-commit
Last active October 1, 2015 11:17
Git pre-commit hook stolen from Yipit's blog
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@jjmalina
jjmalina / storage.py
Created March 5, 2012 22:57
storage.py
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
@jjmalina
jjmalina / columns.py
Created November 20, 2012 04:35
Columns
def columns(size, columns=30):
"""
Return the number of items in each of X columns given a number.
Basically the idea is to find exact or next largest rectangle of a given
number and given amount of columns. Then fill each column evenly.
"""
nearest_rect = 0
column_items = [0 for i in xrange(columns)]
for index in xrange(columns):
@jjmalina
jjmalina / shouts.js
Created November 30, 2012 23:17
Pin Shout
$(document).ready(function() {
var API_URL = "http://3n7g.localtunnel.com";
function newMap(lat, lng) {
var prevMap = $("#map img");
prevMap.css("z-index", 2);
@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