Skip to content

Instantly share code, notes, and snippets.


Roger Qiu CMCDragonkai

View GitHub Profile
CMCDragonkai /
Created Apr 16, 2019
Decorators in Python #python
import functools
def prepost(func=None, *, prefix=''):
def prepost_(func):
def wrapper(*args, **kwargs):
print(f'{prefix} start')
result = func(*args, **kwargs)
print(f'{prefix} end')
return result
CMCDragonkai /
Last active Apr 15, 2019
Delete files/directories within a range of Unix timestamps #shell
#!/usr/bin/env sh
# basically we go into a directory
# we list all immediate files/directories
# then we filter it by a numeric (timestamp) range
# and then we perform a deletion on them
unixtime-gc () {
find "$1" \
-maxdepth 1 \
CMCDragonkai /
Created Apr 5, 2019
Run subprocess while connecting STDERR to Python logging system #python
import io
import subprocess
import threading
import logging
def subprocess_with_logger(logger, check=False, *args, **kwargs):
def log_stream(pipe, logger):
# by default stderr will be a binary stream
# we wrap it into a text stream
CMCDragonkai /
Last active Apr 3, 2019
Nix Store Queries #nix
#!/usr/bin/env sh
# show the output paths of a derivation
nix-store --query --outputs $(nix-instantiate)
# show the immediate dependencies of a derivation
nix-store --query --references $(nix-instantiate)
# show the transitive dependencies of a derivation
nix-store --query --requisites $(nix-instantiate)
# show the dependers of a store-path
nix-store --query --referrers $(nix-instantiate)
CMCDragonkai / haskell_exceptions.hs
Last active Apr 9, 2019
Haskell Exceptions (only to be used with IO) #haskell
View haskell_exceptions.hs
-- safe-exceptions Control.Exception.Safe > exceptions Control.Monad.Catch > base Control.Exception
import Control.Exception.Safe
import Control.Monad.IO.Class (MonadIO, liftIO)
data WhatException = ThisError
| ThatError
deriving (Show)
instance Exception WhatException
CMCDragonkai /
Last active Mar 20, 2019
Python Logging #python

Python Logging


JSON Schema Relative References

You may need this:

parameters_schema_resolver = jsonschema.RefResolver(
    base_uri='file://{}/'.format(current_dir), referrer=parameters_schema)


The basic idea is that right now when pinning Nixpkgs, you pin into specific tar archives of Nix commits.

If instead you could just point to some virtual address that resolved to a checkout of a specific commit.

Then each NixOS system would just maintain a nixpkgs checkout. And then you could just address an arbitrary commit. And it would virtually hand over all the files.

A git virtual filesystem would be needed. Right now each NixOS already sort of synchronizes against the nixpkgs.

But as channels instead of commit based, and not actually using Git at all.

CMCDragonkai /
Last active Mar 17, 2019
Managing the gpg-agent #nix #gpg

Managing the gpg-agent

These are the standard commands:

gpgconf --list-dirs
gpgconf --kill gpg-agent
gpgconf --reload gpg-agent
You can’t perform that action at this time.