Skip to content

Instantly share code, notes, and snippets.

View jepio's full-sized avatar
🏠
Working from home

Jeremi Piotrowski jepio

🏠
Working from home
View GitHub Profile
@jepio
jepio / qsort.erl
Last active August 29, 2015 14:02
A/The quicksort implementation in erlang. What a fun language.
-module(qsort).
-export([sort/1,start/0,part/2,qsort/1]).
%% usage: erlc qsort.erl && erl -run qsort -run init stop -noshell
%% easiest way to write a quick sort %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sort([Pivot|T]) ->
sort([ X || X <- T, X < Pivot]) ++
[Pivot|[Pivot|| X <- T,X == Pivot]] ++
sort([ X || X <- T, X > Pivot]);
@jepio
jepio / rev.erl
Last active August 29, 2015 14:02
Rev(erse) a list. erse ends up appending all elements once it gets to the end, while erse_tail will reverse as it goes.
-module(rev).
-export([start/0,erse/1,erse_tail/1]).
%% recursion with appending
erse([First|Rest]) -> erse(Rest)++[First];
erse([]) -> [].
%% tail recursion
erse_tail(L) -> erse_tail(L,[]).
erse_tail([],New) -> New;
@jepio
jepio / backupper.sh
Last active August 29, 2015 14:02
Use rsync to archive your home folder.
#!/usr/bin/env bash
rsync -av --delete /home/user user@host:/home/user/backup/
# copy over ssh, with partial (interruption) support, progressbar
rsync -avPh --rsh='ssh' src dest
@jepio
jepio / tarbar.sh
Last active August 29, 2015 14:02
Progress bar while tar'ing.
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Specify one folder to compress"
exit 1
fi
if [[ -d $1 ]]; then
folder=`basename $1`
size=`du -sb $1 | cut -f 1`
tar cfp - $1 | pv -perbt -s $size | bzip2 -c > $folder.tar.bz2
@jepio
jepio / compile-flags.sh
Last active August 29, 2015 14:02
Check what flags are enabled by march=native.
gcc -### -march=native -x c++ -
# or
gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
# or better yet
gcc -march=native -Q --help=target
@jepio
jepio / tex-plots.md
Last active August 29, 2015 14:02
A brief instruction on how to generate tex plots and include them in tex documents.

TeX Plots

Generating using ROOT

To generate a plot start by setting the paper size. I have found that sometimes the default canvas size (in pixels) will show, so consider also creating a canvas with a specified size (aspect ratio) beforehand. Next, draw the plot and save it with a .tex extension.

gStyle->SetPaperSize(7.,4.);
plot->Draw();
gPad->Print("plot.tex");

The source file of the plot can be editted after it has been saved - you can change the axis labels, add unicode or latex characters and even change colors/sizes of every element if you're proficient in tikz.

Including in LaTeX.

@jepio
jepio / patch.sh
Last active August 29, 2015 14:03
Create and apply a patch
diff -u file file_updated > file.patch # creates a patch describing the changes between two files
patch < file.patch # applies the patch to file, making it the same as file_updated (won't change the filename)
@jepio
jepio / watch
Last active August 29, 2015 14:03
Refresh a command to see what changes
watch --color --exec --interval 0.5 df
@jepio
jepio / Makefile
Last active August 29, 2015 14:03
A short OpenMP example showing how you can make your code parallel with minimal effort.
CC=gcc
# Without the fopenmp flag the program will normally still work and be
# completely serial. In this case however it won't because I used omp.h
CFLAGS=-fopenmp -Wall
LDFLAGS=$(CFLAGS)
all: omp_example
omp_example: omp_example.o
#ifndef __GPU_TIMER_H__
#define __GPU_TIMER_H__
#include <cuda_runtime.h>
struct GpuTimer
{
cudaEvent_t start;
cudaEvent_t stop;