Skip to content

Instantly share code, notes, and snippets.

🚀
Lightspeed

Roger Qiu CMCDragonkai

🚀
Lightspeed
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 / file-s3-etag
Last active Apr 15, 2020
Calculate S3 ETAG including Multipart Uploads #python #aws
View file-s3-etag
#!/usr/bin/env python3
import argparse
import hashlib
# see https://docs.aws.amazon.com/cli/latest/topic/s3-config.html
# for default multipart_threshold and multipart_chunksize
def md5sum(
file_like, multipart_threshold=8 * 1024 * 1024, multipart_chunksize=8 * 1024 * 1024
@CMCDragonkai
CMCDragonkai / README.md
Last active Apr 11, 2020
Self-Referential/Recursive Dictionary in Strict Languages #python #javascript
View README.md

Self-Referential/Recursive Dictionary in Strict Languages

The problem with this in strict languages is that we keep needing lazy annotations.

And the other problem is that this won't be very fast in strict languages.

In strict languages there is probably no caching of the function calls.

What this means is comparing a recursive dictionary to a static dictionary, the recursive dictionary is going to be slower depending on how many function calls there are. In fact the slow down may be linear to the number of self or that function calls.

@CMCDragonkai
CMCDragonkai / git-common-descendant.sh
Last active Apr 9, 2020
Acquire the earliest common descendant for 2 Git commit revision hashes #git
View git-common-descendant.sh
#!/usr/bin/env bash
commit_1="$1"
commit_2="$2"
branch="$(git rev-parse --abbrev-ref HEAD)"
if git merge-base --is-ancestor "$commit_1" "$commit_2"; then
echo "$commit_2"
exit 0
fi
@CMCDragonkai
CMCDragonkai / singleton_list_syntax.md
Created Mar 25, 2020
Singleton List Syntax #python #haskell
View singleton_list_syntax.md

Singleton List Syntax

Sometimes you want to have a singleton list or an empty list.

In Python:

[1] * (True) # [1]
[1] * (False) # []
@CMCDragonkai
CMCDragonkai / load_images_arrays_urls_stdin.py
Last active Mar 13, 2020
Load Images and Numpy Arrays from Filesystem URLs and From Standard Input #python
View load_images_arrays_urls_stdin.py
import io
import sys
import fs
import contextlib
import urllib.parse
import numpy as np
from PIL import Image
from typing import Tuple, Iterator, IO, Optional, List
@CMCDragonkai
CMCDragonkai / nixos_build_netboot.sh
Created Jan 20, 2020
Building the NixOS netboot release.nix (from the nixpkgs source) #nix
View nixos_build_netboot.sh
#!/usr/bin/env sh
revCount="$(git rev-list --count HEAD)"bootstrap
shortRev="$(git rev-parse --short HEAD)"
nix-build nixos/release.nix \
--attr netboot.x86_64-linux \
--arg nixpkgs "{ outPath = ./.; revCount = $revCount; shortRev = \"$shortRev\"; }" \
-o netboot
@CMCDragonkai
CMCDragonkai / docker_containers_with_cacert_and_tzdata.nix
Created Jan 8, 2020
Docker Containers with CA certificates and timezone database built using Nix #cli #nix #docker
View docker_containers_with_cacert_and_tzdata.nix
# if you have networked applications that use the TLS or timezones
# you need to have these dependencies in the container
# note that these don't get put in the default.nix derivation
# because the package will use the OS provided cacert and tzdata
# but inside the container, they will need these 2 bundled explicitly
# or mounted...
# both cacert and tzdata has setup hooks
# this means when the container is built
# these pieces of data gets added into the container root filesystem
# at their standard locations
@CMCDragonkai
CMCDragonkai / virtualizing_linux_usb_host_controller_drivers_for_qemu.md
Last active Nov 20, 2019
Virtualizing Linux USB Host Controller Drivers for QEMU #linux #qemu
View virtualizing_linux_usb_host_controller_drivers_for_qemu.md

Virtualizing Linux USB Host Controller Drivers for QEMU

USB is a device-host protocol. So the host, which is likely your operating system requires a host controller interface (which is a piece of hardware).

The host controllers require drivers to run.

There are 3 kinds of USB host controller drivers:

  • ohci - Open Host Controller Interface - USB 1
@CMCDragonkai
CMCDragonkai / qemu_boot_from_kernel_initrd.sh
Created Nov 11, 2019
QEMU-KVM boot a new x86-64 Virtual Machine from kernel and initrd #qemu
View qemu_boot_from_kernel_initrd.sh
#!/usr/bin/env sh
# assume you have bzImage, initrd, cmdline, share, bootdisk, maindisk
# the below will boot a QEMU VM with 2 disks attached (as raw), with host port 55555 mapped to 22
# and also pass the share directory into the VM
qemu-system-x86_64 \
-kernel ./bzImage \
-initrd ./initrd \
-smp $(nproc) \
You can’t perform that action at this time.