Skip to content

Instantly share code, notes, and snippets.

☄️
Lucid

Roger Qiu CMCDragonkai

View GitHub Profile
@CMCDragonkai
CMCDragonkai / decorators.py
Created Apr 16, 2019
Decorators in Python #python
View decorators.py
import functools
def prepost(func=None, *, prefix=''):
def prepost_(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
print(f'{prefix} start')
result = func(*args, **kwargs)
print(f'{prefix} end')
return result
@CMCDragonkai
CMCDragonkai / unixtime-gc.sh
Last active Apr 15, 2019
Delete files/directories within a range of Unix timestamps #shell
View unixtime-gc.sh
#!/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
CMCDragonkai / subprocess_with_logger.py
Created Apr 5, 2019
Run subprocess while connecting STDERR to Python logging system #python
View subprocess_with_logger.py
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
CMCDragonkai / nix_store_queries.sh
Last active Apr 3, 2019
Nix Store Queries #nix
View nix_store_queries.sh
#!/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
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
CMCDragonkai / README.md
Last active Mar 20, 2019
Python Logging #python
View README.md

Python Logging

View json_schema_relative_references.md

JSON Schema Relative References

You may need this:

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

jsonschema.validate(
    instance=parameters,
View nix_snapshots.md

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
CMCDragonkai / managing-the-gpg-agent.md
Last active Mar 17, 2019
Managing the gpg-agent #nix #gpg
View managing-the-gpg-agent.md

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.