Skip to content

Instantly share code, notes, and snippets.

View wonderbeyond's full-sized avatar
🎯
Focusing

Wonder wonderbeyond

🎯
Focusing
View GitHub Profile
@wonderbeyond
wonderbeyond / env.py
Created October 18, 2020 12:28
A python context manager to set and revert environment variables automatically.
import os
import copy
from contextlib import contextmanager
@contextmanager
def env(**kw):
prev_env = os.environ.copy()
for k, v in kw.items():
os.environ[k] = v
@wonderbeyond
wonderbeyond / find-in-git-history.sh
Last active October 8, 2022 02:44
Traverse git history commits to find the last existence of a file.
#!/usr/bin/env bash
# Author: [email protected]
# Usage: find-in-git-history server.py main
main-branch-name () {
if git show-ref -q main; then
echo main
else
echo master
fi
@wonderbeyond
wonderbeyond / start.py
Created August 24, 2020 06:13
Enable python default warnings printing
import os
import sys
import warnings
if not sys.warnoptions:
warnings.simplefilter("default")
os.environ["PYTHONWARNINGS"] = "default"
@wonderbeyond
wonderbeyond / index.md
Last active July 8, 2020 02:56
Process long-running tasks with celery

Celery config

broker_url: redis://:@redis-host:6379/1
result_backend: redis://:@redis-host:6379/2
result_expires: 43200
task_soft_time_limit: 7200
worker_prefetch_multiplier: 1
worker_max_tasks_per_child: 1  ## ???
@wonderbeyond
wonderbeyond / index.md
Last active June 16, 2020 08:35
Docker common commands
docker run -d --name=myproj-postgres \
    -e POSTGRES_USER=myproj -e POSTGRES_PASSWORD=<secret> \
    -p 5436:5432 -v /var/lib/myproj/pgdata:/var/lib/postgresql/data postgres:13 \
@wonderbeyond
wonderbeyond / rabbitmq.md
Last active May 22, 2020 11:32
RabbitMQ Learning Notes

RabbitMQ Basic Concepts

  • Producer - Application that sends the messages

  • Consumer - Application that receives the messages

  • Queue - Buffer that stores messages

  • Message - Data sent from producer to consumer through RabbitMQ

@wonderbeyond
wonderbeyond / Dockerfile
Last active May 9, 2020 06:01
Dockerfile: create new conda environment as default
FROM <your-base-image>
ENV PYTHONUNBUFFERED 1
WORKDIR /code
# COPY condarc /root/.condarc
COPY . /code
ENV CONDA_DEFAULT_ENV=<your-conda-env-name>
ENV CONDA_PREFIX="/root/miniconda3/envs/$CONDA_DEFAULT_ENV"
@wonderbeyond
wonderbeyond / set-apt-proxy.md
Last active March 14, 2025 23:53
[ubuntu][socks5][proxy] Set proxy for apt

Writing an apt proxy conf file /etc/apt/apt.conf.d/proxy.conf as below.

Acquire::http::Proxy "socks5h://127.0.0.1:1080";
Acquire::https::Proxy "socks5h://127.0.0.1:1080";
Acquire::socks::Proxy "socks5h://127.0.0.1:1080";

And the proxy settings will be applied the next time we run apt.

@wonderbeyond
wonderbeyond / dconf-media-keys.dump
Created February 3, 2020 07:21
My dconf media keys (keyboard shortcuts)
[/]
custom-keybindings=['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/']
screenshot=''
[custom-keybindings/custom0]
binding='Print'
command='flameshot gui'
name='Start flameshot capture'
[custom-keybindings/custom1]