Skip to content

Instantly share code, notes, and snippets.

View julienr's full-sized avatar

Julien Rebetez julienr

View GitHub Profile
@julienr
julienr / bashrc_prompt_shortener
Created April 19, 2011 21:15
bashrc prompt pwd shortener
# prompt shortener : http://stackoverflow.com/questions/3497885/code-challenge-bash-prompt-path-shortener
_dir_chomp () {
local IFS=/ c=1 n d
local p=(${1/#$HOME/\~}) r=${p[*]}
local s=${#r}
while ((s>$2&&c<${#p[*]}-1))
do
d=${p[c]}
n=1;[[ $d = .* ]]&&n=2
((s-=${#d}-n))
#!/usr/bin/python3
# This is a simple pre-processor for a boustrophedonic dialect of the C
# programming language :
# http://en.wikipedia.org/wiki/Boustrophedonic
#
# A sample program is :
# #include <stdio.h>
# { )( niam tni
# printf("Hello dlrow\n");
@julienr
julienr / .Xresources
Created April 4, 2012 09:09
.Xresources for urxvt
URxvt.depth: 32
URxvt.scrollBar: off
URxvt.font: -*-terminus-medium-r-normal-*-*-*-*-*-*-*-*-*
URxvt.keysym.Control-Up: \033[1;5A
URxvt.keysym.Control-Down: \033[1;5B
URxvt.keysym.Control-Left: \033[1;5D
URxvt.keysym.Control-Right: \033[1;5C
URxvt.background: #300A24
URxvt.foreground: #ffffff
@julienr
julienr / npycat
Last active October 13, 2015 16:18
npycat : cat-like tool for numpy .npy files
#!/home/julien/tm/v2/venv/bin/python
"""
Cat-like utility for .npy files
"""
import numpy as np
import sys
def print_arr(a):
print 'dtype : ', a.dtype
print 'shape : ', a.shape
// g++ -o eigen_test eigen_sparse_solver.cc -I/home/julien/slash/include/eigen3 -I/usr/include/suitesparse -lumfpack -lamd -lblas
#include <cstdlib>
#include <cassert>
#include <Eigen/Eigen>
#include <Eigen/UmfPackSupport>
#include <vector>
#include <iostream>
using namespace Eigen;
using namespace std;
@julienr
julienr / pca_svds.py
Created December 23, 2013 12:31
PCA using scipy.sparse.linalg.svds (economy SVD decomposition)
def pca(X, npc):
n_samples, n_features = X.shape
Xmean = np.mean(X, axis=0)
U, s, Vt = scipy.sparse.linalg.svds(X - Xmean, k=npc)
order = np.argsort(-s) # sort s in descending order
# svds returns U, s, Vt sorder in ascending order. We want descending
s = s[order]
W = Vt[order,:]
@julienr
julienr / bisect.log
Last active August 29, 2015 13:59
tmux set-buffer crash
git bisect start
# bad: [57c514d2f85f9d1c81601bae32131f1cd2948422] Remove <vis.h>; not used on Linux.
git bisect bad 57c514d2f85f9d1c81601bae32131f1cd2948422
# bad: [1b083aa0fd2d8ac000504488135bf58e35c3361e] Update CHANGES and configure.ac for 1.8 release.
git bisect bad 1b083aa0fd2d8ac000504488135bf58e35c3361e
# good: [2b5c3fc49f9f96dd84fb26f75be7d634ea4c282c] Update NOTES, CHANGES, configure.ac for 1.7 release
git bisect good 2b5c3fc49f9f96dd84fb26f75be7d634ea4c282c
# good: [357da035b9d052b4cba8db806c6237272ade6673] Merge send-prefix into send-keys.
git bisect good 357da035b9d052b4cba8db806c6237272ade6673
# skip: [599dd2a56009300df999c54c73aa9e83268809e8] Create a new context when copying instead of using the input context. The input context may not exist yet. Fixes crash when copying from config file errors.
@julienr
julienr / convert_timestamp.py
Created April 28, 2014 12:42
convert_timestamp.py
"""Convert UTC timestamp to custom timezone"""
import datetime
import pytz
import sys
assert len(sys.argv) > 1, 'Usage : convert_timestamp <timestamp>'
utc = pytz.utc
zurich = pytz.timezone('Europe/Zurich')
utc_dt = datetime.datetime.fromtimestamp(float(sys.argv[1]), tz=utc)
dt = utc_dt.astimezone(zurich)
@julienr
julienr / OpenIterm2.app
Created June 4, 2014 20:44
Open iTerm2 here in OSX
-- Automator AppleScript to add a finder toolbar icon to "open iterm2 window here"
-- * Create an Automator application
-- * Add this script as Utilities/Run AppleScript
-- * Drag the application to the finder toolbar with command pressed
(* http://peterdowns.com/posts/open-iterm-finder-service.html *)
on run {input, parameters}
tell application "Finder"
set dir_path to POSIX path of (folder of the front window as alias)
end tell
CD_to(dir_path)
@julienr
julienr / tvtk_image_overlay.py
Last active April 23, 2018 04:02
TVTK 2D image overlay over 3D plot (python, mayavi.mlab and tvtk)
"""
Example of overlaying an image on a 3D view with tvtk
"""
##
import mayavi.mlab as mlab
import numpy as np
import pylab as pl
import vtk
from tvtk.api import tvtk
##