Skip to content

Instantly share code, notes, and snippets.

View matbesancon's full-sized avatar

Mathieu Besançon matbesancon

View GitHub Profile
@matbesancon
matbesancon / config.fish
Last active January 17, 2021 18:46
micro editor config
# file ~/.config/fish/config.fish
# Based on clearance
# name: clearance
# ---------------
# Based on idan. Display the following bits on the left:
# - Current directory name
# - Git branch and dirty state (if inside a git repo)
function _git_branch_name
echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
@matbesancon
matbesancon / main.rs
Created August 23, 2018 14:27
Rust UUID minimal example to test result consistency
extern crate uuid;
use uuid::Uuid;
fn main() {
let refs = vec![&uuid::NAMESPACE_DNS, &uuid::NAMESPACE_OID, &uuid::NAMESPACE_URL, &uuid::NAMESPACE_X500];
let tags = vec!["NAMESPACE_DNS", "NAMESPACE_OID", "NAMESPACE_URL", "NAMESPACE_X500"];
let pairs = refs
.iter()
.zip(tags.iter())
.map(|(u,t)|
@matbesancon
matbesancon / Pair.java
Last active May 13, 2019 09:25
A simple pair class
public final class Pair<L, R> {
private L _left;
private R _right;
public Pair(L left, R right) {
this._left = left;
this._right = right;
}
public L left() {
@matbesancon
matbesancon / bench.jl
Last active June 20, 2019 07:59
Sampling mini-benchmark
# julia v1.1.1
import Random
using Distributions # v0.21.0
import RandomNumbers # v1.3.0
using BenchmarkTools # v0.4.2
function f(µ::T, rng::Random.AbstractRNG) where {T<:Real}
n = 0
Σx = zero(T)
X = Normal(µ, one(T))
@matbesancon
matbesancon / sort_by_degree.jl
Created July 10, 2019 08:26
Sort vertices by reversed degree order
function sort_by_degree(g::LightGraphs.AbstractGraph)
vs = vertices(g)
degrees = (degree(g, v) for v in vs)
vertex_pairs = collect(zip(vs, degrees))
sort!(vertex_pairs, by = p -> p[2], rev = true)
end
julia> sort_by_degree(path_graph(5))
5-element Array{Tuple{Int64,Int64},1}:
(2, 2)
@matbesancon
matbesancon / setindex.jl
Last active August 20, 2019 09:12
setindex boundchecked
julia> function setindex(x::Tuple, v, i::Integer)
Base.@_inline_meta
@boundscheck 1 <= i <= length(x) || throw(BoundsError(x, i))
Base._setindex(v, i, x...)
end
julia> using BenchmarkTools
julia> const t1 = (42, "", π)
(42, "", π = 3.1415926535897...)
@matbesancon
matbesancon / matrices.jl
Created October 2, 2019 13:18
Grow matrix versus pre-alloc
function expand_matrix(ms)
T = eltype(eltype(ms))
m2 = Matrix{T}(undef, 0, length(first(ms)))
for i in eachindex(ms)
m2 = [m2; ms[i]']
end
return m2
end
function prealloc_matrix(ms)
@matbesancon
matbesancon / .gitconfig
Last active January 28, 2020 14:43
Linux setup
[user]
name = Mathieu Besançon
[core]
autocrlf = true
[pager]
branch = false
@matbesancon
matbesancon / script.jl
Last active July 15, 2020 19:25
Dependencies on LightGraphs.jl
# This script assumes the Julia session is running at the root of the General repository
# https://github.com/JuliaRegistries/General
# Need these 3 installed
using LightGraphs, MetaGraphs, GraphPlot
import Pkg
function find_direct_deps(pkg_paths, source)
direct_deps = filter(pkg_paths) do pkg_path
deps_file = joinpath(pkg_path.path, "Deps.toml")
@matbesancon
matbesancon / anim_projection.jl
Created December 24, 2020 14:45
Javis projection
using Javis
nframes = 200
function ground(args...)
background("white") # canvas background
sethue("black") # pen color
end
function object(p=O, color="black", radius=12)