Skip to content

Instantly share code, notes, and snippets.

View georg-wolflein's full-sized avatar

Georg Wölflein georg-wolflein

View GitHub Profile
@georg-wolflein
georg-wolflein / rambomb.py
Created April 1, 2024 15:34
Hacky script to occupy and then release RAM in order to flush disk cache (easier to run this than annoy the sysadmin to run `sync`).
"""Hacky script to occupy and then release RAM in order to flush disk cache (easier to run this than annoy the sysadmin to run `sync`)."""
import psutil
import gc
from tqdm import tqdm
def get_available_ram():
"""
Get the total available RAM in bytes.
@georg-wolflein
georg-wolflein / convert_bibtex_author_list_to_paperpile.py
Created September 9, 2023 13:18
Convert a list of authors from bibtex format to paperpile format
def convert_bibtex_author_list_to_paperpile(authors, last_name_indicators=("el", "van", "vaan", "de")):
"""
Convert a list of authors in bibtex format to paperpile format.
:param authors: list of authors in bibtex format
:param last_name_indicators: list of words that indicate the start of a last name
:return: list of authors in paperpile format
Example:
>>> bibtex_authors = "Georg Wölflein and Ludwig van Beethoven and Johann Sebastian Bach"
>>> convert_bibtex_author_list_to_paperpile(bibtex_authors)
@georg-wolflein
georg-wolflein / drawio-tex-to-png.Makefile
Created November 22, 2022 13:47
Convert drawio file using TeX to PNG
DRAWIO = /Applications/draw.io.app/Contents/MacOS/draw.io
INKSCAPE = /Applications/Inkscape.app/Contents/MacOS/inkscape
DIR = .
INPUTS = $(wildcard $(DIR)/*.drawio)
OUTPUTS = $(INPUTS:.drawio=.png)
.PHONY : all
all : $(OUTPUTS)
@georg-wolflein
georg-wolflein / gpuinfo.sh
Last active August 21, 2022 09:32
For each GPU, list used memory by process (and find associated docker container)
#!/bin/bash
for i in $(nvidia-smi --query-gpu=index --format=csv,noheader); do
echo GPU "#$i": $(nvidia-smi --query-gpu=memory.used --format=csv,noheader -i $i) used
while IFS="," read -r pid name used; do
pid_container_name=
for container in $(docker ps -q); do
if [[ $(docker top $container | awk '{print $2}'| grep $pid) ]]; then
pid_container_name=$(docker inspect $container --format '{{.Name}}')
@georg-wolflein
georg-wolflein / findpid.sh
Created July 26, 2021 13:15
Get the docker container ID containing a specified PID (useful to identify GPU-intensive processes when running nvidia-smi)
#/bin/bash
if [ -z "$1" ]
then
echo "Supply a PID as an argument!"
exit 1
fi
for i in $(docker ps -q)
do
@georg-wolflein
georg-wolflein / listify.py
Last active September 27, 2021 12:41
Decorator to convert Python generator functions to lists or dicts. Also supports asynchronous functions.
from functools import wraps, partial
import inspect
def _ify(func, factory=list):
if inspect.isasyncgenfunction(func):
@wraps(func)
async def new_func(*args, **kwargs):
return factory([x async for x in func(*args, **kwargs)])
else:
@georg-wolflein
georg-wolflein / merge-sort.js
Created December 22, 2017 14:04
A JS implementation of the merge sort algorithm.
let merge = (array1, array2) => {
let output = [];
while (array1.length != 0 && array2.length != 0) {
if (array1[0] == array2[0]) {
output.push(array1[0]);
array1 = array1.slice(1, array1.length);
output.push(array2[0]);
array2 = array2.slice(1, array2.length);
} else {
if (array1[0] < array2[0]) {
@georg-wolflein
georg-wolflein / git-proxy.ps1
Created December 30, 2014 10:33
Force GitHub for Windows to use a proxy. Type this in the Git PowerShell.
git config --global http.proxy http://<proxy>:3128
git config --global https.proxy http://<proxy>:3128
@georg-wolflein
georg-wolflein / non-selectable-text.css
Created February 25, 2014 22:31
Keep the user from selecting text of class "non-selectable".
.non-selectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: default;
}
@georg-wolflein
georg-wolflein / FormRound.cs
Created February 9, 2014 15:33
A round Windows Form that moves along the mouse when pressed. Based on my previous gist: https://gist.github.com/georgw777/8900639.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;