Skip to content

Instantly share code, notes, and snippets.

@stephenchew
stephenchew / README.md
Created June 8, 2024 14:21
Headless setup of Raspberry PI

Enable SSH

  1. Locate the partion of the newly flashed Raspberry Pi OS.
  2. Create a new empty file named ssh with no extension in the boot partition.

or

echo '' > ssh
@stephenchew
stephenchew / main.py
Created April 25, 2024 11:14
O(1) way to chunk an array into small pieces in Python
arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
chunk_three = chunk(arr, 3)
assert chunk_three == [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"], ["j"]]
chunk_default = chunk(arr)
assert chunk_default == [["a", "b", "c", "d"], ["e", "f", "g", "h"], ["i", "j"]]
chunk_max = chunk(arr, 1000)
assert chunk_max == [['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']]
@stephenchew
stephenchew / README.md
Created February 14, 2024 09:39
WSL import/export and setting default user

Export a WSL instance

wsl --export <distribution name> <export file name>

e.g.

wsl --export Ubuntu-22.04 D:\wsl-backup\Ubuntu.22.04.tar

Forward port from host to WSL

In PowerShell, run:

netsh interface portproxy add v4tov4 listenport=<host post> listenaddress=0.0.0.0 connectport=<wsl port> connectaddress=<wsl IP address>

e.g. forward port 8080 to port 8080

netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=172.30.144.20
@stephenchew
stephenchew / README.md
Last active January 6, 2024 14:44
Bulk edit photos in Photoprism

Bulk edit photos in Photoprism

Tested to work with builds: -

  • 231011-63f708417
  • 230923-e59851350
  • 230719-73fa7bbe8

Use this workaround until Photoprism implemented bulk-edit feature.

@stephenchew
stephenchew / README.md
Last active October 11, 2023 12:59
All about WSL2

All about WSL2

Docker in WSL2 (without Docker Desktop)

🔗 https://nickjanetakis.com/blog/install-docker-in-wsl-2-without-docker-desktop

Installing Google Chrome

  1. Change directories into the temp folder: cd /tmp
  2. Use wget to download it: sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  3. Get the current stable version: sudo dpkg -i google-chrome-stable_current_amd64.deb
  4. Fix the package: sudo apt install --fix-broken -y
@stephenchew
stephenchew / README.md
Created August 14, 2023 06:49
Force source file to be LF on Windows

Force source file to be LF on Windows

Follow the instructions below to force all files to be checked out as LF, especially in Windows.

  1. Create .gitattributes file in the root directory of the project, if one does not exist.
  2. Add the following line to the file
    * text=auto eol=lf
    
  3. Run the following command to remove all Git caches (mind the trailing ., it indicates current path)
@stephenchew
stephenchew / README.md
Created June 9, 2023 14:44
Install emoji and Chinese fonts in Ubuntu (predominently WSL2)
@stephenchew
stephenchew / README.md
Last active June 2, 2023 09:12
If port 53 is occupied...

Context

If you want to host a DNS server in a Linux environment (e.g. Ubuntu or raspbian), port 53/udp might be occupied by one of the services below. Use. ss or lsof to check the running service.

Stop systemd-resolved

  1. Edit the conf file
    sudo vim /etc/systemd/resolved.conf