Skip to content

Instantly share code, notes, and snippets.

@stephenchew
stephenchew / index.js
Created January 21, 2017 23:01
[Runkit] Simple endpoint to interrogate a request
const queryString = require('query-string');
exports.endpoint = function (request, response) {
let queryStart = -1;
let url = request.url;
let parameters;
if ((queryStart = request.url.indexOf('?')) > -1) {
url = url.substring(0, queryStart + 1);
@stephenchew
stephenchew / pem2pkcs12.sh
Created February 22, 2017 18:10
OpenSSL command to convert PEM into PKCS12
openssl pkcs12 -export -out output.pkcs12 -in input.pem
@stephenchew
stephenchew / InvokeOutlookRules.vbs
Last active May 29, 2017 03:20
Invoke all Outlook rules with the prefix `[Clean Up]`
Public Sub CleanUpAll()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim ruleList As String
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
For Each rl In myRules
@stephenchew
stephenchew / OpenSSH-to-RSA.sh
Last active January 3, 2022 06:59
Generate private/public key (RSA format)
# Convert 4096-bit OpenSSH private key to RSA format
# Input -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNz...QECAwQ= -----END OPENSSH PRIVATE KEY-----
# Output -----BEGIN RSA PRIVATE KEY----- MIICXAI...OsuOpw= -----END RSA PRIVATE KEY-----
ssh-keygen -p -m pem -f private-key-file-name
# Convert given pub file to PEM format
# Input ssh-rsa AAAAB3NzaC1yc2EAAAADAQA....== alias@domain.com
# Ouput -----BEGIN RSA PUBLIC KEY----- MIGJAoG...gMBAAE= -----END RSA PUBLIC KEY-----
ssh-keygen -f public-key.pub -e -m pem
@stephenchew
stephenchew / .bash_aliases
Last active August 27, 2023 11:16
Handy shell aliases for Git.
# OS common
alias l='ls -l --color=auto'
alias ll='ls -al --color=auto'
# Git
alias gc='git commit'
alias gcm='git commit -m'
alias gco='git checkout'
alias gsw='git switch'
alias gsm='BRANCH=$(gdef) && git switch $BRANCH'
@stephenchew
stephenchew / .bashrc
Created April 24, 2023 06:41
Docker start-up script for WSL2
./start-docker.sh
@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
@stephenchew
stephenchew / README.md
Created June 9, 2023 14:44
Install emoji and Chinese fonts in Ubuntu (predominently WSL2)
@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)