Skip to content

Instantly share code, notes, and snippets.

@Gabriel-p
Gabriel-p / col_align
Created November 19, 2014 17:29
Align columns in a text file
# See:
# http://stackoverflow.com/questions/14095011/using-awk-to-align-columns-in-text-file
# for more info.
head -1 file.dat; tail -n+2 file.dat | rev | column -t | rev > out.dat
@Gabriel-p
Gabriel-p / fill_empty_cols
Last active August 29, 2015 14:09
Fill empty spaces in aligned columns file
# See:
# http://unix.stackexchange.com/questions/164207/insert-missing-string-in-multiple-ordered-columns
#
# The string of numbers after 'FIELDWIDTHS' indicate the end position of each column in the file
# The column numbers should be counted *starting from 0*.
gawk -vFIELDWIDTHS="4 7 4 6 8 8 6 8 8 8 7 5 4" -vOFS= '{for (i=1;i<=NF;i++) sub(" $","--",$i);}1' file.dat > out.dat
@Gabriel-p
Gabriel-p / vers_check.py
Last active August 14, 2016 14:23
Check version number of python and several packages
import sys
print 'Versions\n'
print 'python', sys.version
try:
import numpy
print 'numpy', numpy.__version__
@Gabriel-p
Gabriel-p / latexdiff.sh
Last active November 6, 2015 14:16
Automatize latexdiff application
#!/bin/bash
#
# Script to generate a PDF with all differences marked
# via the latexdiff package, between two .tex files.
# See: http://www.ctan.org/pkg/latexdiff
#
# All output is stored in a diff/ sub-folder that is
# created if it doesn't exist.
#
# Run with:
@Gabriel-p
Gabriel-p / git_cheat_sheet.rst
Last active August 29, 2015 14:10
Git cheat sheet
@Gabriel-p
Gabriel-p / eos_annoy_fix.md
Last active August 29, 2015 14:20
Fix elementary OS annoyances with Chrome and Dropbox

Double Google Chrome icon in Planck.

Taken from here:

sudo leafpad /usr/share/applications/google-chrome.desktop

You'll find 3 entries in this file, [Desktop Entry], [NewWindow Shortcut Group] and [NewIncognito Shortcut Group]. Make sure that under each group there's the following line, it doesn't matter where in the group it is.

StartupWMClass=Google-chrome-stable

import matplotlib.pyplot as plt
import numpy as np
def plt_f_chart(fig, x_name, y_name, coord, x_zmin, x_zmax, y_zmin,
y_zmax, x_data, y_data, st_sizes_arr, labels, center_cl,
clust_rad, mps):
'''
Zoom on x,y finding chart.
@Gabriel-p
Gabriel-p / get_ellipse.py
Created May 27, 2015 15:57
Generate an ellipse through the MVEE method
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
# import time
# http://stackoverflow.com/questions/14016898/port-matlab-bounding-ellipsoid-code-to-python
# http://stackoverflow.com/questions/1768197/bounding-ellipse/1768440#1768440
import numpy as np
import matplotlib.pyplot as plt
def cluster_stars(N, min_v, max_v):
'''
'''
mu = np.random.uniform(min_v, max_v)
sigma = np.random.uniform(max_v / 10., min_v / 10.)
import numpy as np
from scipy.ndimage.filters import maximum_filter
from scipy.ndimage.filters import gaussian_filter
from scipy.ndimage.morphology import generate_binary_structure, binary_erosion
from scipy import stats
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.offsetbox as offsetbox
# from mpl_toolkits.axes_grid1 import make_axes_locatable