Skip to content

Instantly share code, notes, and snippets.

🐢

Jean-Gabriel Young jg-you

🐢
Block or report user

Report or block jg-you

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jg-you
jg-you / draw_nx_beautiful.py
Last active Jul 9, 2019
Beautiful networkx graph
View draw_nx_beautiful.py
import copy
import networkx
import matplotlib.pyplot as plt
# Generate a graph.
# Here I chose an ER graph.
g = nx.erdos_renyi_graph(20, 0.3)
# Get positions.
# Here I use the spectral layout and add a little bit of noise.
@jg-you
jg-you / main_master_slave.cpp
Last active Mar 5, 2019
Master / Slave example with boost::mpi
View main_master_slave.cpp
// STL
#include <cstdlib>
#include <iostream>
// boost::mpi
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/status.hpp>
namespace mpi = boost::mpi;
// Definitions
#define NUMBER_OF_JOBS 12
@jg-you
jg-you / bernstein.stan
Last active Oct 30, 2018
Evaluate a Bézier curve in Bernstein form at a point, using De Casteljau's algorithm, in the STAN language
View bernstein.stan
functions {
/**
* Computes the value of a Bernstein polynomial of degree N at point t,
* using De Casteljau's algorithm.
*
* @param t Point in [0, 1] where the the polynomial will be evaluated.
* @param beta Vector of the real N + 1 coefficients of the polynomial.
* @param N Degree of the polynomial.
*
* @return Value of the polynomial at point t.
@jg-you
jg-you / orbits.py
Last active Oct 28, 2018
Computing the number of orbits in a graph, with dreadnaut (nauty), in python
View orbits.py
# -*- coding: utf-8 -*-
"""
Wrapper around dreadnaut that computes the orbits of a graph.
NOTE: Must have installed `dreandaut`. The location of the binary can be passed
as an argument to `compute_automorphisms`.
Author: Jean-Gabriel Young <info@jgyoung.ca>
"""
import subprocess
@jg-you
jg-you / stateless_derivation_and_template.cpp
Last active Jan 12, 2018
How to use stateless class derived from a virtual base class in a templated class. A strategy I use in many code
View stateless_derivation_and_template.cpp
#include <iostream>
class master_virtual
{
public:
virtual void msg() {return;}
};
class derived_hi : public master_virtual
{
@jg-you
jg-you / inline_gt_fig.py
Last active Jul 19, 2017
Inline graph-tool figures in jupyter-notebook
View inline_gt_fig.py
# The newest version of graph-tool plots directly in a gtk window, by default.
# The following allow you to add inline plots in a jupyter-notebook (this was previously trivial).
# [The following code must appear in a notebook, obviously]
import graph_tool as gt
import graph_tool.draw
import graph_tool.collection
import matplotlib.pyplot as plt
@jg-you
jg-you / draw_graphon.py
Created Aug 25, 2016
Draw graphon Stochastic Block Models
View draw_graphon.py
import matplotlibt.pyplot as plt
import numpy as np
plt.figure(figsize=(5,4))
X, Y = np.meshgrid(np.linspace(0,1), np.linspace(0,1))
plt.pcolormesh(X,Y,graphon_val(X,Y,p,n))
plt.colorbar()
@jg-you
jg-you / mdown_toc.py
Last active Mar 19, 2016
Generate TOC for a markdown file
View mdown_toc.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: Jean-Gabriel Young <jean.gabriel.young@gmail.com>
"""Generate TOC for a markdown file."""
import re
# Match between 1 and 4 #
section = re.compile('^\s*(#){1,4}\s?')
strip_url = re.compile('[\W_]+', re.UNICODE)
@jg-you
jg-you / extraction.py
Last active Oct 14, 2015
Extract parts of a pdf file as a png (dirty hack)
View extraction.py
#!/usr/bin/env python3
# Author: Jean-Gabriel Young
# Email: jean.gabriel.young@gmail.com
# -*- coding: utf-8 -*-
import argparse
import subprocess
import os
from PIL import Image
@jg-you
jg-you / supersets.py
Last active Aug 29, 2015
Find all supersets of a collection
View supersets.py
collection = [{1, 2, 3, 4, 5},
{1, 2},
{1, 2, 3, 4, 5, 6},
{3, 4, 8},
{3, 4, 11},
{3},
{3},
{12},
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 7, 9},
You can’t perform that action at this time.