Skip to content

Instantly share code, notes, and snippets.

View knthls's full-sized avatar
🏹
hunting typos

Christian Knauth knthls

🏹
hunting typos
  • L21s, Citywalx
  • Berlin
View GitHub Profile
@knthls
knthls / consul-semaphore-demo.sh
Last active September 10, 2022 19:58
A demo implementation to use consus distributed semaphore system. No guarantees of whatsoever are given. Feel free to use and modify.
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] -s my_service/semaphore -t my-distributed-task
@knthls
knthls / isolate-set-seed.R
Created April 3, 2020 09:11
Isolate code execution in seperate environment in R (particularly calls to set seed)
# Isolate execution of set.seed (or anything else) in own env
s1 <- .GlobalEnv$.Random.seed
draw <- function(){
eval({
set.seed(12)
samples = runif(10)
}, envir = new.env())
samples
@knthls
knthls / inspect_docx.sh
Created February 25, 2020 12:13
Inspect document xml for docx file
#/bin/bash
wd=$(mktemp -d)
docx_file=$1
if [ -z $docx_file ]; then
echo "Usage: inspect_docx.sh []"
fi
@knthls
knthls / rm_corr.py
Created October 17, 2017 12:00
remove correlated columns in pandas DataFrame
# remove low variance columns
rna_data = rna_data.loc[:, (rna_data.var() > 0.5)]
# remove correlated columns
vars = rna_data.var()
tbd = []
# from each pair of highly correlated columns, remove columns with lower variance
for i, j in zip(*np.where(np.corrcoef(rna_data.values.T) > 0.5)):
"""
Basic Idea taken from http://stackoverflow.com/a/8111621/6420372
"""
import os
import socket
import subprocess
from select import select
import time
import contextlib
import os
import socket
import subprocess
from select import select
import time
import contextlib
import settings
try:
import winreg