Skip to content

Instantly share code, notes, and snippets.

View medihack's full-sized avatar

Kai Schlamp medihack

  • Thoraxklinik Heidelberg
  • Germany
View GitHub Profile
@medihack
medihack / parse_search_string.py
Last active May 15, 2024 13:45
A pyparsing parser that parses Googe like search strings
import pyparsing as pp
from typing import Literal
class TermNode:
def __init__(self, term_type: Literal["WORD", "PHRASE"], value: "Node"):
self.term_type = term_type
self.value = value
def __repr__(self):
return f"TermNode({self.term_type}, {self.value})"
@medihack
medihack / microI18n.ts
Last active October 10, 2023 22:32
A fully typed i18n micro library
/**
* A fully typed i18n micro library. The react import is optional for the hook (see below).
*
* Idea from https://dev.to/halolab/implementing-the-translate-function-with-typescript-5d8d
*
* TODO: check if we can get i18n-ally working: https://github.com/lokalise/i18n-ally/issues/678#issuecomment-947338325
*/
import { useEffect, useState } from "react"
type PathKeys<T> = T extends string
@medihack
medihack / async_debounce.py
Created April 23, 2023 10:07
A python decorator to debounce async functions
import asyncio
from functools import wraps
def async_debounce(wait):
def decorator(func):
task = None
@wraps(func)
async def debounced(*args, **kwargs):
nonlocal task
@medihack
medihack / rate_limit2.py
Created December 9, 2021 12:57 — forked from josiahcarlson/rate_limit2.py
Regular and sliding window rate limiting to accompany two blog posts.
'''
rate_limit2.py
Copyright 2014, Josiah Carlson - josiah.carlson@gmail.com
Released under the MIT license
This module intends to show how to perform standard and sliding-window rate
limits as a companion to the two articles posted on Binpress entitled
"Introduction to rate limiting with Redis", parts 1 and 2:
@medihack
medihack / .tmux.conf
Last active April 28, 2021 11:01
For tmux version 3.x
# C-b is not acceptable -- Vim uses it
set-option -g prefix C-a
setw -g xterm-keys on
# Fix colors tmux + vim
# if this still does not work then put this in your .bashrc:
# alias tmux='tmux -2'
set -g default-terminal "screen-256color"
@medihack
medihack / modify_dicoms.py
Last active November 15, 2020 00:50
Modify DICOM files
import argparse
import os
import pydicom
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('input_folder', help='The DICOM input folder.')
parser.add_argument('output_folder', help='The DICOM output folder.')
parser.add_argument('-m', '--modify_dicom_tag', help='Modifies a DICOM tag.', type=str, nargs=2, action='append')
@medihack
medihack / settings.json
Created November 10, 2020 21:31
Visual Studio Code Workspace Settings
{
"editor.formatOnSave": true,
"html.format.enable": false,
"prettier.tabWidth": 4,
"prettier.disableLanguages": ["html", "django-html"],
"python.formatting.provider": "black",
"python.linting.pylintEnabled": true
}
@medihack
medihack / settings.json
Last active November 12, 2020 08:05
Visual Studio Code Remote Settings
{
"python.experiments.optInto": ["DeprecatePythonPath - experiment"],
"python.venvPath": "~/.cache/pypoetry/virtualenvs",
}
@medihack
medihack / settings.json
Created November 10, 2020 21:28
Visual Studio Code User Settings
{
"git.autofetch": true,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"python.formatting.provider": "black",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.renderControlCharacters": false,
"editor.renderWhitespace": "none",
"prettier.disableLanguages": ["django-html"],
@medihack
medihack / RxTextView.kt
Created June 6, 2019 18:26
Make a Android TextView (EditText) observable in RxJava
/**
* Adapted (and translated in Kotlin) from https://gist.github.com/FrantisekGazo/d1a62fcddd0c97453ee6d57efef17916
* Nice usage scenario https://www.novatec-gmbh.de/en/blog/building-android-components/
*/
object RxTextView {
private val textViewObservables = HashMap<TextView, Observable<CharSequence>>()
@JvmStatic
fun textChanges(view: TextView): Observable<CharSequence> {
val observable = textViewObservables[view]