Skip to content

Instantly share code, notes, and snippets.

View nicolamontecchio's full-sized avatar

Nicola Montecchio nicolamontecchio

View GitHub Profile
@nicolamontecchio
nicolamontecchio / rplot.R
Created August 18, 2011 13:23
plot from STDIN with R
#!/usr/bin/Rscript
d <- as.matrix(read.csv2(file("stdin"), header=FALSE, sep=","))
ca <- commandArgs(trailingOnly=TRUE)
pdf(file=ca[1], width=12, height=6)
plot(d[,1:2], type='n')
lines(d)
dev.off()
@nicolamontecchio
nicolamontecchio / lastm_tags.py
Created March 25, 2011 18:16
simple method to get tags for a given artist/track
#!/usr/bin/env python
import urllib, urllib2, StringIO
from lxml import etree
apikey = 'YOUR APY KEY'
def getTags(artist,track) :
params = urllib.urlencode([('method','track.gettoptags'), ('artist',artist),('track',track),('api_key',apikey)])
url = 'http://ws.audioscrobbler.com/2.0/?' + params
root = etree.parse(urllib2.urlopen(url))
@nicolamontecchio
nicolamontecchio / clVectorPrintout.cpp
Created February 11, 2011 16:33
OPENCL - print a cl_mem vector to stdout; vector type is passed as template
// print out a vector of type T on stdout
template <typename T>
void printClVector(cl_mem &clVector, int length, cl_command_queue &commands, int printrowlen = -1)
{
T *tmp = new T[length];
int err = clEnqueueReadBuffer(commands, clVector, CL_TRUE, 0, sizeof(T) * length, tmp, 0, NULL, NULL );
if (err != CL_SUCCESS)
{
printf("Error: Failed to read output array! %d\n", err);
exit(1);
@nicolamontecchio
nicolamontecchio / mp3towav
Created January 19, 2011 18:28
convert an mp3 to wav using lame -- useful for converting whole directories
#!/usr/bin/env python
import os
import optparse
def processfile(fi, fo) :
print 'lame --decode --quiet %s %s' % (fi,fo)
if __name__ == '__main__':
# parse options
parser = optparse.OptionParser()
@nicolamontecchio
nicolamontecchio / wav2mono.cpp
Created October 12, 2010 14:42
convert a wav file to mono, using libsndfile
#include <iostream>
#include <sndfile.h>
using namespace std;
/**
* Convert an audio file to mono format (input in first arg, output in second)
*/
int main(int argc, char** argv)
{
if (argc != 3)