Skip to content

Instantly share code, notes, and snippets.

@leotac
leotac / gist:6030145
Created July 18, 2013 15:14
Git partial file stage (commit)
git add -p file.txt
@leotac
leotac / gist:5854827
Last active December 18, 2015 22:29
push to git remote branch if name !=
# Local and remote branches with different names
git checkout -b mybranch origin/remote_branch
git push origin mybranch:remote_branch
#There's a config option to tell git to push to remote tracking branches by default:
git config --global push.default tracking
#If with same name, push local branch to remote AND set it as upstream (push there by default)
@leotac
leotac / gist:5850623
Created June 24, 2013 14:53
upgrade gcc/++
sudo apt-add-repository ppa:ubuntu-toolchain-r/test/ubuntu
sudo apt-get update
sudo apt-get install gcc-4.6
sudo apt-get install g++-4.6
@leotac
leotac / gist:5845858
Last active December 18, 2015 21:18
Vim tricks/tips memo
Yank to register:
"+ y
Indenting:
v and then = (uniform the indentation)
v and then <
v and then >
Tricks for indenting more than once without selecting everything again:
@leotac
leotac / gist:5810168
Last active December 18, 2015 16:19
Write piecewise functions in LaTex
%http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics#The_cases_environment
\begin{cases}
\exp{x} & \text{if } x \geq 0 \\
1 & \text{if } x < 0
\end{cases}
@leotac
leotac / gist:5783816
Created June 14, 2013 17:41
process file to make latex table.
# switch second and third field
# input fields are separated either by "_" or by "\t"
# output fields will be separated by " & "
# add "\\" at end of line
awk 'BEGIN {{FS="[_|\t]"}{OFS=" & "}} NR<=2{next} {ORS="\\\\\n"}{t=$2; $2=$3; $3=t; print;}' $1 > $1_full.tab
@leotac
leotac / gist:5783795
Created June 14, 2013 17:37
plot columnb "timeCG" for all ".nfo" files with label "pricername" (tab separated files)
import pandas as pd
from pylab import *
import os
[plot(x.timeCG,label=x.pricername.max()) for x in (pd.read_csv(l,"\t") for l in os.listdir('.') if l.endswith("nfo"))]; legend(); show()
@leotac
leotac / gist:5735514
Last active December 18, 2015 05:49
Install and get postgres working on linux (via unix socket)
#Check release (e.g., precise)
lsb_release -c
sudo echo "deb http://apt.postgresql.org/pub/repos/apt/ <release>-pgdg main" > /etc/apt/sources.list.d/pgdg.list
#Authenticate repo
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql pgadmin3
# Then (http://blog.deliciousrobots.com/2011/12/13/get-postgres-working-on-ubuntu-or-linux-mint/)
sudo -u postgres psql postgres
@leotac
leotac / atlas.sh
Last active December 18, 2015 04:49
Build ATLAS + Numpy/Scipy on Ubuntu 12.04
#Following for the most part the instruction in http://www.scipy.org/scipylib/building/linux.html#building-everything-from-source-with-gfortran-on-ubuntu-nov-2010
sudo apt-get install build-essential python-dev swig gfortran python-nose
# If needed (check less /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor):
sudo apt-get install cpufrequtils
sudo cpufreq-set -c 0 -g performance #for each core, set freq scaling to performance
mkdir BUILD
cd BUILD