Skip to content

Instantly share code, notes, and snippets.

@affo
affo / clean.py
Created March 20, 2014 14:40
Script to order files by extension in a directory. Once run, directories named with files extensions will be created. Can be run periodically.
#!/usr/bin/python
import os
import logging
logging.basicConfig(filename='clean.log', filemode='w', level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(message)s')
wd = os.getcwd()
alll = os.listdir(wd)
files = []
dirs = []
@affo
affo / deco.py
Created October 31, 2014 16:52
Annotations (decorators) with @wraps or not in python
from functools import wraps
def logger_without_wrap(fn):
def _wrapper(*args, **kwargs):
print '# begin: ' + fn.__name__
fn(*args, **kwargs)
print '# end: ' + fn.__name__
return _wrapper
def logger_with_wrap(fn):
@affo
affo / config.py
Last active February 9, 2016 17:18
Python module for logging
import ConfigParser as cp
CONFIG_FILE = 'project.conf'
_CONF = cp.ConfigParser()
_CONF.readfp(open(CONFIG_FILE))
def get(opt, section='DEFAULT'):
return _CONF.get(section, opt)
@affo
affo / templater.bash
Created October 21, 2015 12:44
A templating script written in bash
#!/bin/bash
if [[ $# -eq 0 ]]; then
echo "Usage:"
echo " templater key=value ... inputfile"
echo
echo "Sample input file:"
echo " Hello \${name}, enjoy templater!"
echo
echo "Sample output:"
echo " $ ./templater name=Affo input"
@affo
affo / .gitignore
Last active December 14, 2015 13:49
Latex project scaffold
*.pdf
*.log
*.aux
*.fdb_latexmk
*.fls
*.toc
*.out
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
#define MAX 10
int f (int m[][N]) {
int a[N * N], cont = 0, in;
int i, j, k;
@affo
affo / grouped.py
Created June 15, 2016 14:17
Operations on GroupedObservables with RxPY
import random
import time
from rx.subjects import Subject
#### The System
# The entrypoint
s = Subject()
def produce(word):
s.on_next(word)
@affo
affo / rx_stateful.py
Last active June 23, 2016 08:54
Stateful operators in RxPY
import rx
class StatefulOperator(object):
def default(self, tup):
msg = 'Default method called with ' + str(tup)
return dict(message=msg)
def __call__(self, tup):
method_name = tup.pop('method_name', 'default')
return getattr(self, method_name)(tup)
@affo
affo / sequence_models.py
Last active July 28, 2016 09:28
Implementation for sequence models at LxMLS
import numpy as np
import lxmls.readers.simple_sequence as ssr
simple = ssr.SimpleSequence()
print simple.train, type(simple.train.seq_list)
print simple.test, type(simple.test.seq_list)
for s in simple.train.seq_list:
print s.x, s.y
@affo
affo / dish_classifier.py
Created July 26, 2016 17:11
Naive bayes dish classifier
import random
import numpy as np
# Ok, the point is now to create a naive
# bayes model and stop without accounting
# for the lab...
# We want to model for example the food.
# The food can be terrific, bad, not bad, good
# or awesome: