Skip to content

Instantly share code, notes, and snippets.

View chongshenng's full-sized avatar

Chong Shen Ng chongshenng

View GitHub Profile
@chongshenng
chongshenng / update_git.md
Created June 8, 2022 09:06
Update `git` to version 2.28 to ensure `init.defaultBranch` is honoured
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

If you receive an error about add-apt-repository command not found you need to install software-properties-common, and then redo the above steps.

sudo apt-get install software-properties-common
@chongshenng
chongshenng / git_branch_off_pager.md
Created June 8, 2022 10:32
Turn off pager when listing git branch
@chongshenng
chongshenng / r_tips.md
Created June 13, 2022 09:38
Tips for setting up R environment
@chongshenng
chongshenng / Dockerfile
Created July 5, 2022 11:02
A docker image with python and setuptools for building releasable python packages consistently
# Ref: https://hub.docker.com/r/treyduskin/python-setuptools/Dockerfile
FROM ubuntu:trusty
RUN apt-get update && apt-get install -y python-pip createrepo rpm dpkg-dev git
RUN pip install setuptools-scm && pip install --upgrade setuptools
VOLUME /build
#COPY . /build/
@chongshenng
chongshenng / curl_wireless_connect.txt
Created July 26, 2022 10:07
Steps to connect to wireless with http authentication
Ref: https://superuser.com/a/262795
You will have to look once at the source of the login form to find out the names of the user and password fields. As the authentication redirect all pages, use any URL to get that source:
curl http://www.google.com > login.html
For example, you'll find:
@chongshenng
chongshenng / K3sInstallationNotes.md
Created August 2, 2022 12:43 — forked from ben-z/K3sInstallationNotes.md
K3s Installation Notes

K3s Installation Notes (for running Gitlab Runner)

Install k3s master and expose api:

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --write-kubeconfig-mode 644 --bind-address 0.0.0.0" sh -

The --write-kubeconfig-mode 644 gives /etc/rancher/k3s/k3s.yaml group and world read permissions so that we can run kubectl without sudo. The INSTALL_K3S_EXEC argument can be modified at /etc/systemd/system/multi-user.target.wants/k3s.service.

@chongshenng
chongshenng / mp4_converter.sh
Created September 28, 2022 20:24
Quality-preserving `mp4` to Window's friendly `wmv` converter
#!/bin/sh
# Ref 1: https://stackoverflow.com/a/11080028
# Ref 2: https://trac.ffmpeg.org/wiki/Encode/MPEG-4
ffmpeg -i input_video.mp4 -qscale:v 2 -c:a aac -strict -2 output_video.wmv
@chongshenng
chongshenng / relative_imports_notebook.md
Created November 3, 2022 15:41
Sometimes you need relative imports in a notebook ...

Given this directory structure

project
├── utils
│   └── module.py
└── notebooks
    └── notebook.ipynb

and that you want to import module.py in notebook.ipynb. Add the directory path to the notebook like so,

@chongshenng
chongshenng / docker_build_with_secrets.md
Last active March 23, 2023 14:39
Build Docker container with secrets

Sometimes you want to build a Docker image with secrets. To do so, you should use BuildKit and add this line to the start of your Dockerfile:

syntax=docker/dockerfile:1.4

Then, if you have the secrets as an environment variable in your local machine, do:

$ export MYSECRET=theverysecretpassword
$ export DOCKER_BUILDKIT=1
$ docker build --secret id=mysecret,env=MYSECRET .
@chongshenng
chongshenng / shallow_submodule_clone.md
Created March 16, 2023 15:19
Clone your submodule shallowly
# add shallow submodule
git submodule add --depth 1 <repo-url> <path>
git config -f .gitmodules submodule.<path>.shallow true

# later unshallow
git config -f .gitmodules submodule.<path>.shallow false
git submodule update <path>