Skip to content

Instantly share code, notes, and snippets.


Roger Qiu CMCDragonkai

Block or report user

Report or block CMCDragonkai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
CMCDragonkai / check_types.js
Created Jun 18, 2019
Checking Types in JavaScript #javascript
View check_types.js
// you often want to check if a value is truthy
function booleanise(v) {
return !!v;
booleanise(0) // false
booleanise('') // false (empty strings is falsey)
booleanise(false) // false
booleanise(null) // false
booleanise(undefined) // false
CMCDragonkai /
Last active May 23, 2019
Journey into Nix Package Repository #nix

Journey into Nix Package Repository

There are 2 commits that I need in my build:

  • 8d0e3ad603dda85462161bba1351893b84339462
  • 83e01aa5e48a9107f3b988c9d4c1c21d610626fb

Clone nixpkgs and add the nixpkgs-channels as a remote.


Nix Overrides

  • overrideDerivation is used to override the call to derivation
  • overrideAttrs is used to override the call to stdenv.mkDerivation
  • override is used to override the last function call. Often this will be the callPackage call.
  • overridePythonAttrs is used to override the call to buildPython*.

This PR discusses the idea to have a generic overrideArgs that works like overridePythonAttrs for all language infrastructures.

CMCDragonkai /
Last active May 9, 2019
Understanding Nix Inputs #nix

Understanding Nix Inputs

Every Nix derivation produces a Nix store output that has 3 things:

  • Executables
  • Libraries
  • Data

Executables are always exported using the PATH environment variable. This is pretty much automatic.

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
You can’t perform that action at this time.