Skip to content

Instantly share code, notes, and snippets.

View musq's full-sized avatar
🌹
Public Key: tug.ro/key

Ashish Ranjan musq

🌹
Public Key: tug.ro/key
View GitHub Profile
@musq
musq / optimistic_concurrency_control_using_peewee.py
Last active August 28, 2023 20:41
Optimistic Concurrency Control using Peewee
import time
from contextlib import contextmanager
from peewee import CharField, IntegerField, Model, OperationalError, PostgresqlDatabase
from tenacity import (
RetryError,
Retrying,
retry_if_exception_type,
stop_after_attempt,
wait_incrementing,
@musq
musq / debug.py
Last active November 16, 2023 07:02
Datadog tracing 101 - Debug script, and Async tracing scripts
import requests
from ddtrace import patch_all as dd_patch_all
from ddtrace import tracer
tracer.configure(enabled=True)
dd_patch_all()
print(requests.get("https://example.org"))
@musq
musq / single_tenant_connection_pooling_with_peewee.py
Last active January 1, 2023 18:40
Single Tenant connection pooling with Peewee
import logging
import random
import sys
import time
from collections import OrderedDict
from contextlib import contextmanager
from functools import wraps
from typing import Callable
import numpy as np
@musq
musq / manual_connection_pooling_with_peewee.py
Created October 1, 2022 18:57
Manual connection pooling using Peewee - with an eject callback
import logging
import sys
import time
from collections import OrderedDict
from concurrent.futures import ThreadPoolExecutor, as_completed
from contextlib import contextmanager
from functools import wraps
from typing import Callable
from peewee import Database
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
shopt -s nullglob extglob
cd "`git rev-parse --git-path objects`"
search() {
@musq
musq / ocr.sh
Created August 20, 2019 18:39
Convert a scanned pdf file to txt using tesseract. Useful in paper-key for GPG private key retrieval
# Install commands
nix-env -iA nixpkgs.imagemagick7Big
nix-env -iA nixpkgs.tesseract4
# Convert `input.pdf` to `out-image.tiff`
convert -density 300 input.pdf -depth 8 -background white -alpha Off out-image.tiff
# Convert `out-image.tiff` to `output.txt`
tesseract out-image.tiff output
@musq
musq / server.txt
Last active July 8, 2019 20:02
Server setup instructions
## Server setup (run multiple times)
Create `wheel` user and group
- this user & group should be used as an alias to root
- modify /etc/sudoers file using visudo and add `%wheel ALL=(ALL) NOPASSWD: ALL`
- keep the group of any user to wheel, you want to give sudo access to
- use this user to run commands as root, apache, nginx, caddy
## Install packages as `wheel` (run multiple times)
@musq
musq / .git-commit-template.txt
Created June 15, 2019 19:22 — forked from adeekshith/.git-commit-template.txt
This commit message template helps you write great commit messages and enforce it across teams.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@musq
musq / a.sh
Last active September 28, 2018 09:44
gsettings get org.gnome.desktop.interface monospace-font-name
gsettings get org.gnome.desktop.interface document-font-name
gsettings get org.gnome.desktop.interface font-name
gsettings get org.gnome.desktop.wm.preferences titlebar-font