Skip to content

Instantly share code, notes, and snippets.

View nicolamontecchio's full-sized avatar

Nicola Montecchio nicolamontecchio

View GitHub Profile
@nicolamontecchio
nicolamontecchio / read_float_tsv.c
Created May 17, 2016 16:15
read a matrix of floats in tsv format
typedef struct _FloatMatrix {
uint32_t N;
uint32_t M;
float *data;
} FloatMatrix;
/* read matrix from tsv file */
/* matrix is allocated, will need to be freed */
def nesterov_optimizer(g, w0, alpha, mu):
dim = w0.shape[0]
w = w0
v = np.zeros(dim)
while True:
yield w
v = mu * v - alpha * g(w + mu * v)
w = w + v
# groups of `size` from an iterable `seq`
def group(seq, size):
it = iter(seq)
while True:
values = []
try:
for n in xrange(size):
values.append(it.next())
yield values
except:
@nicolamontecchio
nicolamontecchio / lr_by_term.py
Created August 25, 2014 19:50
template for logistic regression w/ graph and all from csv file
import numpy as np
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import SGDClassifier
from sklearn.metrics import precision_recall_curve
dfp = PATH_TO_FILE_HERE # format is csv with itemid,label,features
def readff(fpath):
trids, labs, feats = [], [], []
@nicolamontecchio
nicolamontecchio / compojure-ring-examples.clj
Last active August 29, 2015 14:03
clojure - compojure - ring
;; route destructuring
(POST "/login" {post-params :params session :session} (page-login-post post-params session))
;; session update
(assoc (response (html "whatever...") :session (assoc session :userid uid)))
;; show request map:
(GET "/profile" reqmap (str reqmap))
@nicolamontecchio
nicolamontecchio / -
Created July 1, 2014 14:25
clojure ZIP function
;; zip sequences:
(map vector v1 v2 v3 ...)
@nicolamontecchio
nicolamontecchio / -
Created February 11, 2014 15:34
fast cat of a lot of files
find . -name "*.dat" -exec cat {} \; > filename
@nicolamontecchio
nicolamontecchio / .emacs
Created January 17, 2014 18:15
emacs config as of 2014-01-17
;; ;; config using mac-port of emacs,
;; ;; see https://github.com/railwaycat/emacs-mac-port
;; ;; mac switch meta key
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'hyper)
(setq package-archives '(;;("gnu" . "http://elpa.gnu.org/packages/")
;;("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
@nicolamontecchio
nicolamontecchio / foo.c
Created January 16, 2014 04:00
template for python extension in C
#include <Python.h>
static PyObject* say_hello(PyObject* self, PyObject* args)
{
const char* name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
printf("Hello %s!\n", name);
package com.nicolamontecchio.chroma;
import java.io.*;
import javax.sound.sampled.*;
/**
* Read an audio file. Provided that the appropriate packages are in the classpath, mp3 and ogg should be readable too. The safest route is to read from a MONO, WAV file.
*/
public class AudioReader {