Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar
🚀
Lightspeed

Roger Qiu CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@CMCDragonkai
CMCDragonkai / clone_to_mem.py
Last active April 8, 2024 12:30
Clone GDAL/OGR DataSource/DataSet to in-memory instance #gdal #ogr #python
from osgeo import gdal, ogr
def clone_data_to_mem(ds, name=''):
if (isinstance(ds, gdal.Dataset)):
return clone_raster_to_mem(ds, name)
elif (isinstance(ds, ogr.DataSource)):
return clone_vector_to_mem(ds, name)
else:
raise TypeError('Data source must be of GDAL dataset or OGR datasource')
@CMCDragonkai
CMCDragonkai / linux_kernel_modules_nixos.md
Last active April 7, 2024 09:42
Linux Kernel Modules for NixOS #linux #nixos

Linux Kernel Modules for NixOS

You can find what kernel modules are loaded using lsmod.

However some kernel modules are required at stage 1 boot. Basically preloaded in the initial ram disk before switching to the root filesystem. These kernel modules are mostly needed to deal with peripherals, storage devices, filesystems and network devices. You may need to be wary of these required modules:

  • sd_mod - SCSI, SATA, and PATA (IDE) devices
@CMCDragonkai
CMCDragonkai / exporting_modules_functions_from_python_init.md
Last active April 6, 2024 05:50
Exporting Modules and Functions from Python `__init__.py` #python

Exporting Modules and Functions from Python __init__.py

Any directory with __init__.py is considered a package in Python.

Any python files inside a package is considered a module.

Modules contain functions and other bindings that is always exported.

If you are outside the package, and you want to import a module from a package:

@CMCDragonkai
CMCDragonkai / fold_ideas.md
Last active April 1, 2024 12:49
Haskell: Foldl vs Foldr

Foldl vs Foldr

I like to call foldr as "fold from the right", while foldl is "fold from the left".

@CMCDragonkai
CMCDragonkai / new_disk_zfs_raid_0.md
Last active March 31, 2024 08:32
Adding a new disk ZFS RAID-0 #zfs

Adding a new disk ZFS RAID-0

When adding a new disk to ZFS RAID-0, you must ensure that the disk has the same storage size as the other disks.

You will need the gptfdisk package to use sgdisk.

hdd='/dev/disk/by-id/<DISKNAME>'
zpool labelclear -f "$hdd" || true
sgdisk --zap-all "$hdd"
@CMCDragonkai
CMCDragonkai / history_data_structures.md
Last active March 31, 2024 00:39
History Data Structures

History Data Structures

For stateful applications, there are 5 different ways of managing the history of state:

  • No History - Living in the moment. - Examples: Any stateful application that doesn't discards all previous states upon mutation.
  • Ad Hoc Snapshotting - Allows restoration to manually saved snapshots. - Examples: Memento Pattern.
  • Singleton - Only remembers the previous snapshot, where undoing the undo is just another undo. - Examples: Xerox PARC Bravo.
  • 1 Stack - Allows linear undo. - Examples: AtariWriter.
  • 2 Stack - Allows linear undo and redo. - Examples: Browser History, Microsoft Word, Adobe Photoshop.
@CMCDragonkai
CMCDragonkai / cryptolink.txt
Created March 19, 2024 21:42
Cryptolink between Polykey Keynode and Github Identity
@CMCDragonkai
CMCDragonkai / nix_string_and_path_concatenation.md
Last active March 15, 2024 00:21
Nix: String and Path Concatenation #nix #nixos

Nix String and Path Concatenation

From Bas van Dijk:

To understand these things I would recommend using nix-repl:

$ nix-repl
Welcome to Nix version 1.11.2. Type :? for help.
@CMCDragonkai
CMCDragonkai / text_shortening.md
Last active March 14, 2024 21:20
CLI: Text Shortening (Text to ASCII Compression)

Text Shortening

Tools like gzip and xz compress bitstrings to bitstrings. We want something designed to do lossless compression on short to medium strings and produce printable ASCII or any kind of printable text. This would allow us to create our own URL shortening system.

We need to combine these 2:

@CMCDragonkai
CMCDragonkai / ways_of_piping_and_redirection.sh
Last active March 12, 2024 11:06
BASH: Ways of Piping/Redirection and Heredoc Demonstration
# shells are an orchestration environment
# the language they provide is intended to orchestrate processes
# on the operating system
# if programs are functions, then all of the below are variants of function application
# anonymous pipe
echo "string" | cat
# herestring
cat <<< "string"