Skip to content

Instantly share code, notes, and snippets.

View nicolamontecchio's full-sized avatar

Nicola Montecchio nicolamontecchio

View GitHub Profile
@nicolamontecchio
nicolamontecchio / gist:7416413
Last active December 28, 2015 00:49
general wisdom
Force git to overwrite local files on pull (fixed homebrew w/ this)
git fetch --all
git reset --hard origin/master
find ip address from cmdline
wget -qO- http://ipecho.net/plain ; echo
@nicolamontecchio
nicolamontecchio / gist:7141034
Created October 24, 2013 17:01
generally useful stuff

avoiding cmd line buffering between pipes or such

brew install homebrew/dupes/expect

unbuffer ./blablabla | ... | ...

@nicolamontecchio
nicolamontecchio / gist:5758728
Created June 11, 2013 17:10
sample discrete distrib in python
def sample_discrete(probabilities):
bins = np.add.accumulate(probabilities)
return np.digitize([random.random()], bins)
@nicolamontecchio
nicolamontecchio / gist:3984652
Last active October 12, 2015 06:28
cmake template, for c++11
cmake_minimum_required(VERSION 2.6)
project(ml)
add_library(boost_po STATIC IMPORTED)
set_property(TARGET boost_po PROPERTY
IMPORTED_LOCATION /usr/local/lib/libboost_program_options.a)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
@nicolamontecchio
nicolamontecchio / gist:3915046
Created October 18, 2012 22:04
maven "uberjar"
add this stuff:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.nicolamontecchio.gnappo.Gnappo</mainClass>
@nicolamontecchio
nicolamontecchio / gist:3831176
Created October 4, 2012 02:44
mac universal binary stuff
merge two libs:
lipo -create libfftw3f-i386.a libfftw3f-ppc.a -output libfftw3f.a
@nicolamontecchio
nicolamontecchio / ctypes_stuff.py
Created August 6, 2012 19:34
python ctypes - array conversion
#let's say f_TI is something like
#void blabla(int *data, int data_length);
#then
f_TI.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.c_int]
lll = [4,7,2,8]
lll_c = (ctypes.c_int * len(lll))(*lll)
f_TI(lll_c, len(lll))
@nicolamontecchio
nicolamontecchio / useful_python_stuff.py
Last active April 22, 2020 00:56
useful stuff in python
# list of lists:
import itertools
list(itertools.chain.from_iterable(a))
# logging stuff
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
@nicolamontecchio
nicolamontecchio / gist:1611295
Created January 14, 2012 12:42
r common plotting stuff
# subplots:
layout(matrix(c(1,2), 2, 1, byrow = TRUE)) # first matrix defines "occupancy"
# then do all the plot() commands, one per figure
dev.new(width,height)
# FONT STUFF
par(family="serif")
plot(x,y, log="x", type='l', xlab='blabla', ylab='blabla', axes=FALSE)
@nicolamontecchio
nicolamontecchio / linearfilter.py
Created November 7, 2011 15:32
quick (almost-untested) hack - linear filter in python (uses numpy)
class Filter(object):
""" Linear Filter, notation is similar to matlab's filter function """
def __init__(self, b, a, xinit, yinit):
self.b = np.array(b)
self.a = np.array(a)
self.x = np.array(xinit)[::-1]
self.y = np.array(yinit)[::-1]
def tick(self, x) :