Skip to content

Instantly share code, notes, and snippets.

@oiao
oiao / retry.py
Last active March 14, 2022 13:21
python-snippets
"""
Retry a function after `sleep` secionds for a max of `maxtries`
"""
def retry(sleep=0.1, maxtries=10):
# wrapper for sleep-retrying a function call. use with `@retry()`
from time import sleep as _sleep
def wrap1(f):
def wrap2(*a, __count=0, **kw):
try:
@oiao
oiao / doi2bib.py
Last active October 27, 2021 12:19
Convert a list of DOIs to BibTex strings
#!/usr/bin/env python3
def get_json(doi:str) -> dict:
# get citation dict from doi string
import re
import urllib.request
from urllib.error import HTTPError
import json
from pprint import pprint
@oiao
oiao / display_off.md
Last active September 7, 2020 09:56
Ubuntu X11/Wayland: DIsplay off on lid close action
  • su

  • echo 'event=button/lid.*' >> /etc/acpi/events/lm_lid

  • echo 'action=/etc/acpi/lid.sh' >> /etc/acpi/events/lm_lid

  • Find out your session type: $XDG_SESSION_TYPE

  • vi /etc/acpi/lid.sh:

    Change USERNAME to your username (whoami)

    X11:

@oiao
oiao / miscs.sh
Created August 2, 2020 14:19
Miscs
# Encrypt archives
# https://askubuntu.com/questions/95920/encrypt-tar-gz-file-on-create
# Pack:
tar -cz FILENAMES | gpg -c -o ARCHIVE.tgz.gpg
# Unpack:
gpg -d your_archive.tgz.gpg | tar xz
####