Skip to content

Instantly share code, notes, and snippets.

@dvnoble
dvnoble / triathlon.py
Last active July 12, 2018 19:47
Triathlon Scheduling (solution from Kleinberg and Tardos' book on algorithm design)
#!/usr/bin/env python3
from itertools import permutations
from random import randint
def tournamentTime(person_list):
""" Computes how much a tournament will last according to the order of
persons in 'person_list'
Assumes a person is described as a 3-tuple of positive integers (ts, tb, tr)
where:
@dvnoble
dvnoble / dot2pdf.sh
Last active February 11, 2021 10:15
Simple bash script to batch convert graphs descriptions (dot format) into a pdf. It requires graphviz.
#!/bin/bash
for GFILE in *.dot;
do
GNAME="${GFILE%.*}";
GTYPE=$(head -n 1 $GFILE);
case "$GTYPE" in
*digraph*) dot -Teps $GFILE -o "$GNAME.eps";;
*graph*) neato -Teps $GFILE -o "$GNAME.eps";;
esac
ps2pdf -dCompatibilityLevel=1.4 -dEmbedAllFonts=true -dSubsetFonts=true \
@dvnoble
dvnoble / svg2pdf.sh
Last active September 10, 2018 15:51
Simple bash script to batch convert svg files into pdfs. It doesn't mess with your fonts and requires rsvg-convert.
#!/bin/bash
# rsvg-convert is inside librsvg2-bin in ubuntu
for SVGFILE in *.svg;
do
SVGNAME="${SVGFILE%.*}";
rsvg-convert -f eps -o "$SVGNAME.eps" "$SVGFILE"
ps2epsi "$SVGNAME.eps"
ps2pdf -dCompatibilityLevel=1.4 -dEmbedAllFonts=true -dSubsetFonts=true -dEPSCrop "$SVGNAME.epsi" "$SVGNAME.pdf";
done
wait
@dvnoble
dvnoble / latexmkrc
Last active December 9, 2019 17:51
Latexmkrc configuration file.
# Generate auxialiary files
$recorder = 1;
# The output file dir
$out_dir = "./build";
$pdf_mode = 2; # Ensure that dvi and ps file are created (POWERDOT)
#$pdf_mode = 1; # Ensure that pdflatex is used (USUAL)
$view = "pdf"; #
@dvnoble
dvnoble / simple_sample.tex
Last active August 2, 2018 21:55
Latex minimal template (pt-br)
\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[brazilian]{babel}
\usepackage{microtype}
\usepackage[alf]{abntex2cite} % adds abnt alfnumeric citation style
\title{Título aqui}
@dvnoble
dvnoble / edges2dot.py
Created April 18, 2019 00:43
edges2dot
#!/usr/bin/env python3
""" This script converts a graph formatted as an edge list
to a dot file.
"""
import argparse
parser = argparse.ArgumentParser(description='Converts an edge list file to a respective graphviz dot file.')
parser.add_argument('--directed', action='store_true', default=False,
graph AFD1 {
rankdir=LR;
node [color="#1f3656", fontcolor="#1f3656", shape=circle, penwidth=1.5, fontsize=16,nodesep=0.5];
edge [color="#1f3656", fontcolor="#e54a45", penwidth=1.5, fontsize=16, minlen=1];
graph [bgcolor=transparent, splines=true];
center = 1;
//node [shape = doublecircle]; qf;
@dvnoble
dvnoble / linkedin_background_generator.py
Created April 19, 2023 01:00
My background generator for Linkedin background picture.
import networkx as nx
import matplotlib.pyplot as plt
# Generate a random graph with 6 communities
size1= 150
size2= 150
G = nx.stochastic_block_model([size1, size2], [[0.03,0.001],[0.001,0.02]])
node_colors = [ '#01f2ab'] * size1 + ['#f20148'] * size2
node_outline= [ '#01a675'] * size1 + ['#a60131'] * size2