Skip to content

Instantly share code, notes, and snippets.

View rocarvaj's full-sized avatar
🐀

Rodolfo Carvajal rocarvaj

🐀
View GitHub Profile
@rocarvaj
rocarvaj / dotgraph.tex
Created May 8, 2017 17:56
Dot graph paper in LaTeX
\documentclass{article}
\pagenumbering{gobble}
\usepackage[a4paper,hmargin={0mm,3mm},vmargin=5mm]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.5]
\foreach \x in {0,...,41}
\foreach \y in {0,...,57}
{
\fill[gray!75] (\x,\y) circle (0.06cm);
@rocarvaj
rocarvaj / slurm-tips.md
Last active May 6, 2020 18:54
Slurm is confusing, or I'm too dumb
  1. How to allocate resources?
    Suppose you need 16 cores. Here are some use cases:
  • you use mpi and do not care about where those cores are distributed: --ntasks=16
  • you want to launch 16 independent processes (no communication): --ntasks=16
  • you want those cores to spread across distinct nodes: --ntasks=16 and --ntasks-per-node=1 or --ntasks=16 and --nodes=16
  • you want those cores to spread across distinct nodes and no interference from other jobs:--ntasks=16 --nodes=16 --exclusive
  • you want 16 processes to spread across 8 nodes to have two processes per node: --ntasks=16 --ntasks-per-node=2
  • you want 16 processes to stay on the same node: --ntasks=16 --ntasks-per-node=16
  • you want one process that can use 16 cores for multithreadingi: --ntasks=1 --cpus-per-task=16
@rocarvaj
rocarvaj / links-fgo.md
Last active May 14, 2018 15:31
Algunos links interesantes (o que por lo menos yo considero interesantes)
@rocarvaj
rocarvaj / cython.md
Last active July 28, 2016 21:15
How to use Cython
  1. Create script my-script.pyx
  2. Create setup.py with
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("hello", ["hello.pyx"])]
@rocarvaj
rocarvaj / matplotlib-tips.py
Last active April 5, 2016 13:47
Plotting in pandas
# Subplots
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15,5))
average_change[['primal', 'primal_dsoff', 'dual', 'dual_dsoff']].plot(ax=axes[0])
axes[0].set_ylim(-0.0, 0.4)
axes[0].axhline(0.0, ls='dashed')
axes[0].xaxis.set_ticks(list(average_change.index))
axes[0].set_title("Improvement of bounds and gap of best clone")
axes[0].set_xlabel("Number of clones (k)")
axes[0].set_ylabel("Average improvement")
@rocarvaj
rocarvaj / useful_pandas_snippets.py
Last active August 3, 2016 20:07 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# Merging a pandas groupby result back into DataFrame
# Ref: http://stackoverflow.com/a/29642002/162264
df['maxval'] = df.groupby(by=['idn']).transform('max')
#Print full dataframe
def print_full(x):
pd.set_option('display.max_rows', len(x))
print(x)
pd.reset_option('display.max_rows')
@rocarvaj
rocarvaj / pandas-tips.md
Last active October 3, 2015 20:48
Things that I've learned about Pandas but that weren't easy to find (for me at least)
#!/bin/sh
#
# Usage: sleeper.sh [time]]
# default for time is 60 seconds
# -- our name ---
#$ -N Sleeper1
#$ -S /bin/sh
# Make sure that the .e and .o file arrive in the
# working directory
@rocarvaj
rocarvaj / presolve.cpp
Created June 25, 2015 17:34
Get presolved problem and solution with CPLEX
int GetPresolvedProblem(CPXENVptr env,
string problemfilename,
string solutionfilename,
CPXLPptr &presolvedproblem,
vector<double> &presolvedsolution,
double &presolvetime)
{
int status;
vector<double> originalsolution;
@rocarvaj
rocarvaj / bash-tips.md
Last active December 5, 2016 19:12
Bash/cli tips!

Print from line n on

tail -n +2 file.csv

From the man page:

-n, --lines=N
     output the last N lines, instead of the last 10
...