Skip to content

Instantly share code, notes, and snippets.

View smokey42's full-sized avatar

Christoph Rauch smokey42

  • Germany
View GitHub Profile
@smokey42
smokey42 / zzat
Created September 16, 2023 13:41
A utility to find the location(s) of an executable in the PATH environment variable.
#!/usr/bin/env python3
"""A utility to find the location(s) of an executable in the PATH environment variable.
This script searches for an executable specified as a command-line argument
in the directories listed in the PATH environment variable. It supports
options to display symbolic links.
Usage:
zzat executable_name [-l|--links]
@smokey42
smokey42 / screen-lock-notify
Last active April 16, 2020 08:50
Set Slack status when locking screen under Linux
# put under ~/.config/screen-lock-notify
#
# Obtain one here: https://api.slack.com/legacy/custom-integrations/legacy-tokens
#
# Beware: New tokens will only be issued until May.
#
SLACK_LEGACY_TOKEN="xoxp-..."
# Figure out the interface by issuing:
#
@smokey42
smokey42 / with_database.py
Last active December 19, 2017 11:01
Decorator to give a new db session/engine to a function and handle the commit automatically.
import contextlib
import functools
import inspect
@contextlib.contextmanager
def simple_transaction(session, close=False, commit=True):
"""
Simple transaction manager, commits on success, rolls back on exception.
@smokey42
smokey42 / kill-the-worker.py
Created December 18, 2017 15:25
Let a worker process tell the Linux kernel to kill it first.
import os
def _oom_adj_self():
oom_adj = '/proc/%d/oom_adj' % os.getpid()
if os.path.exists(oom_adj):
with open(oom_adj, 'w') as oom:
# OOM killer, please kill this process first.
oom.write('15')

Keybase proof

I hereby claim:

To claim this, I am signing this object: