Skip to content

Instantly share code, notes, and snippets.

View TimonLukas's full-sized avatar

Timon Lukas TimonLukas

  • Germany
View GitHub Profile
@TimonLukas
TimonLukas / VoiceRecognition.js
Created October 23, 2017 12:30
A wrapper around the native webkit speech recognition, giving better and faster results.
const recognition = new webkitSpeechRecognition(); // eslint-disable-line
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = 'en-US';
recognition.onstop = () => {
console.log('Stopping recognition');
};
export default (resetCallback, callback) => {
@TimonLukas
TimonLukas / script.sh
Created September 29, 2019 00:16
Auto-activate venv
function cd() {
builtin cd "$@"
if [[ -z "$VIRTUAL_ENV" ]] ; then
if [[ -d ./venv ]] ; then
source ./venv/bin/activate
fi
else
parentdir="$(dirname "$VIRTUAL_ENV")"
if [[ "$PWD" =~ $parentdir ]] ; then
@TimonLukas
TimonLukas / script.sh
Created November 28, 2019 09:16
Register custom glob-based cd commands
typeset -A custom_cd_commands
custom_cd_commands=(ws "~/WebstormProjects/" xc "~/XcodeProjects" py "~/PycharmProjects")
function custom_cd() {
FOLDER="$(find ${1} -name "*${2}*" -type d -maxdepth 1 | head -n 1)"
if [ -n "$FOLDER" ]; then
cd "$FOLDER"
fi
}
@TimonLukas
TimonLukas / prepare_terminal.py
Created February 26, 2020 09:30
Sets an iterm2 terminal window up in a useful way
#!/usr/bin/env python3.7
import iterm2
import asyncio
async def run(cmd: str) -> str:
process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
@TimonLukas
TimonLukas / ws-client.ts
Created August 12, 2023 19:06
TRPC custom message encoding in WebSocket
export class WsClient {
#socket: WebSocket
#listeners: {
open: ((event: Event) => any)[]
close: ((event: CloseEvent) => any)[]
error: ((event: Event) => any)[]
message: ((event: MessageEvent) => any)[]
} = {
open: [],
close: [],
@TimonLukas
TimonLukas / ws-client.ts
Last active August 13, 2023 14:40
TRPC custom message encoding in WebSocket w/ ID negotiation
export class WsClient {
#socket: WebSocket
#listeners: {
open: ((event: Event) => any)[]
close: ((event: CloseEvent) => any)[]
error: ((event: Event) => any)[]
message: ((event: MessageEvent) => any)[]
} = {
open: [],
close: [],
@TimonLukas
TimonLukas / test-int-subclass.py
Last active August 13, 2023 23:14
Python nominal typing (with beartype)
from beartype import beartype
class MyInt(int):
...
def process_int_without(bar: int):
print(f"process_int_without({bar} [type={type(bar)}])")
def process_myint_without(bar: MyInt):
print(f"process_myint_without({bar} [type={type(bar)}])")