Skip to content

Instantly share code, notes, and snippets.

@mg98
mg98 / plotting.R
Last active August 4, 2025 09:42
Rscript for printing plot in LaTeX/tikz
library(tidyverse)
library(tikzDevice)
library(RColorBrewer)
print_plot <- function(plot, name, width=3.5, height=2.5){
tex_name <- sprintf("results/fig/%s.tex", name)
png_name <- sprintf("results/fig/%s.png", name)
tex_width <- width; tex_height <- height
png_width <- tex_width * 4; png_height <- tex_height * 4
@mg98
mg98 / tikzplotlib fix.py
Last active February 9, 2025 21:37
Quick fix for tikzplotlib
"""
As the library `tikzplotlib` is not maintained anymore, errors may arise due to incompatibility.
I don't know to which Python or matplotlib version this solution extends, but I verified this code to work with
- Python 3.9
- matplotlib==3.63
- tikzplotlib==0.10.1
- webcolors==1.12
"""
import matplotlib.pyplot as plt
@mg98
mg98 / psi-poc.ipynb
Created September 11, 2023 17:35
Proof-of-Concept: Private Set Intersection
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mg98
mg98 / post-merge
Last active September 26, 2022 11:17
Detect newly added vars in .env.example and automatically merge them into .env
#!/bin/bash
addedVars=$(git diff ORIG_HEAD HEAD --exit-code -- .env.example | tail -n +6 | grep '^\+' | sed '/^\+/ s/^\+//' | sed '/^[[:space:]]*$/d')
new=$(echo "$addedVars" | while read v; do
if [[ !$(cat .env | grep ^$v=) ]]; then
echo $v
fi
done)
if [[ "$new" ]]; then
@mg98
mg98 / set.go
Last active January 27, 2023 16:54
Implementation of a generic Set type in Go (1.18+)
// Set is a collection of unique values.
type Set[T comparable] struct {
elements map[T]bool
}
// NewSet creates a new empty set.
func NewSet[T comparable]() *Set[T] {
return &Set[T]{elements: map[T]bool{}}
}