Skip to content

Instantly share code, notes, and snippets.

View rocarvaj's full-sized avatar
🐀

Rodolfo Carvajal rocarvaj

🐀
View GitHub Profile
@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 / 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 / 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 / links-fgo.md
Last active May 14, 2018 15:31
Algunos links interesantes (o que por lo menos yo considero interesantes)
@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 / 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 / prename.pl
Created October 31, 2017 16:26
Perl version of the rename script
#!/usr/bin/perl
use strict;
use warnings;
=head1 NAME
rename - renames multiple files
=head1 SYNOPSIS
@rocarvaj
rocarvaj / pip-force.md
Last active November 22, 2017 13:56
Force pip to install (duplicate) package locally

Citing Marcus Smith (maintainer of pip):

If you think the global site is out of date, and want the latest in the user site, then use:

pip install --upgrade --user SomePackage

If the global site is up to date, and you really just want the same thing duplicated in --user, then use:

pip install --ignore-installed --user SomePackage

@rocarvaj
rocarvaj / best-of-read-write-as.md
Last active January 31, 2019 14:39
Best of read.write.as
@rocarvaj
rocarvaj / math.md
Last active July 25, 2022 23:23
This is a test

Hola, este es un test $$\sum_{i=1}^n$$.