Skip to content

Instantly share code, notes, and snippets.

Lucid

Roger Qiu CMCDragonkai

Lucid
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
CMCDragonkai / map_reduce_dask_dataframe.py
Created Aug 6, 2019
Map Reduce with Dask Dataframes #dask
View map_reduce_dask_dataframe.py
import functools
import dask
import dask.dataframe as dd
import pandas as pd
pdf = pd.DataFrame({
'x': range(0, 100),
'y': range(0, 100),
'z': range(0, 100)
})
View gopro_linux_nixos.md

GoPro on Linux (NixOS)

The GoPro Hero 7 uses MTP for transferring files. To connect on NixOS you need to have MTP.

The best GUI tool for MTP is gmtp. Connect your GoPro and use gmtp to transfer files.

For more advanced interaction with GoPro devices, see https://github.com/NixOS/nixpkgs/pull/65607

@CMCDragonkai
CMCDragonkai / random_range.js
Created Jul 19, 2019
Random Ranges in JS #javascript
View random_range.js
// by scaling the uniform distribution between [0,1) to [min,max)
function randomRangeInt (min, max) {
return min + Math.floor(Math.random() * (max - min));
}
@CMCDragonkai
CMCDragonkai / ideas_in_http_restful_api.md
Last active Jul 18, 2019
Ideas in HTTP Restful API #http
View ideas_in_http_restful_api.md

Ideas in HTTP Restful API

Pagination

Pagination should always be using 2 parameters: seek and limit.

The seek is the offset into the collection.

The limit is how many to items to acquire.

@CMCDragonkai
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
CMCDragonkai / journey_nix_package_repository.md
Last active Jun 22, 2019
Journey into Nix Package Repository #nix
View journey_nix_package_repository.md

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.

View nix_overrides.md

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 https://github.com/NixOS/nixpkgs/pull/46842 discusses the idea to have a generic overrideArgs that works like overridePythonAttrs for all language infrastructures.

@CMCDragonkai
CMCDragonkai / nix_inputs.md
Last active Jun 22, 2019
Understanding Nix Inputs #nix
View nix_inputs.md

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