Skip to content

Instantly share code, notes, and snippets.

View janosh's full-sized avatar

Janosh Riebesell janosh

View GitHub Profile
@janosh
janosh / auto_merge_bot_prs.py
Created July 4, 2022 20:10
Auto-merge bot PRs
import argparse
import subprocess
from typing import Literal
__author__ = "Janosh Riebesell"
__date__ = "2022-07-04"
description = """
Batch merge bot-created PRs. Uses the GitHub CLI (`brew install gh`) which must be
authenticated, i.e. `gh auth status` must exit 0. By default asks for confirmation
@janosh
janosh / compile-vasp-m1.md
Last active November 12, 2024 04:50
VASP M1 Mac Compilation Guide

Compiling VASP on M1 Mac

Written by Alex Ganose @utf and Janosh Riebesell @janosh. Published 2022-03-28. Last updated 2024-03-30.

  1. Install Xcode command line tools:

    xcode-select --install
@janosh
janosh / AutoCompletePlace.svelte
Last active July 4, 2021 15:29
Google Maps previously used for showing Studenten bilden Schüler chapters across Germany at https://studenten-bilden-schueler.de/standorte
<script>
// This component uses the Google Maps Places API to turn user text input into a
// formatted address and lat/lng coordinates.
import { onMount } from 'svelte'
import { session } from '$app/stores'
export let selectHandler
export let placeholder = ``
export let required = false
export let name = ``
@janosh
janosh / make_sequential_with_xmp.py
Last active November 2, 2020 14:34
Batch rename files sequentially while handling possible XMP sidecar files.
import os
import sys
_, dirname, prefix = sys.argv
os.chdir(dirname)
files = sorted(f for f in os.listdir() if not f.endswith(".xmp"))
@janosh
janosh / rollup-plugin-markdown.js
Created October 25, 2020 08:06
Rollup plugin for parsing markdown files
import marked from 'marked'
// Import and compile markdown files. Adapted from
// https://github.com/xiaofuzi/rollup-plugin-md/blob/master/src/index.js
export function markdown(options = {}) {
if (options.marked) marked.setOptions(options.marked)
return {
name: `markdown`,
transform(md, id) {
@janosh
janosh / argMinMax.js
Created October 18, 2020 06:45
argMin and argMax functions for JavaScript
const argFact = (compareFn) => (array) => array.map((el, idx) => [el, idx]).reduce(compareFn)[1]
const argMax = argFact((min, el) => (el[0] > min[0] ? el : min))
const argMin = argFact((max, el) => (el[0] < max[0] ? el : max))
argMin([42, -5, 3.14, 1e6]) // 1
argMax([42, -5, 3.14, 1e6]) // 3
@janosh
janosh / pyupgrade.sh
Last active August 14, 2021 18:42
Shell script to upgrade a Python 2 project to Python 3.
#!/bin/sh
# Shell script to upgrade a Python 2 project to Python 3.
# If it's a TensorFlow project consider running afterwards:
# tf_upgrade_v2 --intree . --outtree . --reportfile tf2_report.txt
# [ -x "$(command -v some_binary)" ] checks whether some_binary is
# in path and executable. See https://stackoverflow.com/a/26759734.
if [ -x "$(command -v 2to3)" ]; then
@janosh
janosh / tf.js
Created October 30, 2019 20:37
Dabbling with TensorFlowJS
import * as tf from '@tensorflow/tfjs'
export const tfMultivariateNormal = (mu, sigma) => {
[mu, sigma] = [tf.tensor(mu), tf.tensor(sigma)]
const [dim] = mu.shape
if (!sigma.shape.every(d => d === dim))
throw new Error(`dimension mismatch in tfMultivariateNormal()`)
const Z = ((2 * Math.PI) ** dim * tfDet(sigma).arraySync()) ** -0.5
return x => {
x = tf.tensor(x)
@janosh
janosh / pdfcompress.sh
Last active November 18, 2018 15:15
Bash script, accepts directory as single argument, recursively compresses all PDFs in there and subdirectories, uses ghostscript, appends -min to name of compressed file
#!/bin/bash
find "$1" -name "*.pdf" | while read file; do
path=${file%/*}
basename=${file##*/}
ext=${basename##*.}
filename=${basename%.*}
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -dQUIET -sOutputFile="$path/$filename-min.pdf" "$file"
done
@janosh
janosh / pdfpreviews.sh
Last active August 9, 2020 14:53
Bash script that accepts a directory as its single argument and creates small PNG previews of the first page of all PDFs using ImageMagick. Applies to PDFs in given directory and its subdirectories.
#!/bin/bash
find $1 -type f -iname "*.pdf" -exec sh -c 'convert -density 100 -flatten "$1"[0] "$1".png' x {} \;