Skip to content

Instantly share code, notes, and snippets.

@tmarthal
tmarthal / csvprocessor.py
Last active August 26, 2015 16:18 — forked from miku/csvprocessor.py
CSV processor examples for luigi. Can serialize *args to CSV. Can deserialize CSV rows into namedtuples if requested. -- "works on my machine".
from luigi.format import Format
import csvkit
class CSVOutputProcessor(object):
"""
A simple CSV output processor to be hooked into Format's
`pipe_writer`.
If `cols` are given, the names are used as CSV header, otherwise no
explicit header is written.
digits2alpha = {'1':('1'),
'2':('a','b','c'),
'3':('d','e','f'),
'4':('g','h','i'),
'5':('j','k','l'),
'6':('m','n','o'),
'7':('p','q','r','s'),
'8':('t','u','v'),
'9':('w','x','y','z'),
'0':('0')}
@tmarthal
tmarthal / gist:5248035
Created March 26, 2013 18:48
PowerSet Calculation in java
import java.util.HashSet;
import java.util.Set;
public class PowerSet {
private Set<Set<Object>> powerSet;
private void setCombinations(Set<Object> set) {
@tmarthal
tmarthal / gist:5286991
Last active December 15, 2015 16:09
Python time list filtering
import datetime
base = datetime.datetime.today()
dateList = [ base - datetime.timedelta(minutes=2*x) for x in range(0,48) ]
hour_ago = base - datetime.timedelta(hours=1)
# get the number of dates from less than an hour ago
len(filter(lambda x: x > hour_ago, dateList))
@tmarthal
tmarthal / Linear Dependent VAR
Last active December 21, 2015 09:49
Auto-Correlation of statsmodels VAR process with linear dependent timeseries.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@tmarthal
tmarthal / brush.js
Created September 27, 2013 00:30 — forked from enjalot/brush.js
if(!d3.chart) d3.chart = {};
d3.chart.brush = function() {
var g;
var data;
var width = 600;
var height = 30;
var dispatch = d3.dispatch(chart, "filter");
function chart(container) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tmarthal
tmarthal / crontab
Created October 26, 2013 21:20 — forked from tovbinm/crontab
# Nginx - logrotate & upload to S3
0 0 * * * /usr/sbin/logrotate /etc/logrotate.d/nginx
15 0 * * * s3cmd put /var/log/nginx/access.log-`date +"\%Y\%m\%d"`.gz s3://$LOGS_BUCKET_NAME/nginx-access/`date +"dt=\%Y\%m\%d"`/`hostname -s`.access.log-`date +"\%Y\%m\%d"`.gz
import binascii
# PyCryptodome, NOT pycrypto
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2
class AesCrypt256:
#Based on https://gist.github.com/pfote/5099161
BLOCK_SIZE = 16
def pkcs5_pad(self,s):
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.