Skip to content

Instantly share code, notes, and snippets.

View posoo's full-sized avatar
🐝
caffeine fueled

Sen Lin posoo

🐝
caffeine fueled
View GitHub Profile
@posoo
posoo / authorize_pub_keys.sh
Last active September 3, 2023 01:02
Download SSH public keys from GitHub and append them to `authorized_keys`
curl https://github.com/$GITHUB_HANDLE.keys >> ~/.ssh/authorized_keys
@posoo
posoo / bug_analysis-encoded_frame_too_large.md
Created July 11, 2023 11:02
Copied from posoo/Metaverse-ALVR #19 (Cannot receiving unreliable datagrams)

posoo/quinn-dquic@4f8b9bc introduced the capability to send an encoded frame that's larger than conn.inner.datagrams().max_size(), which is slightly smaller than MTU, i.e., ~1400 bytes. The way is to split the buffer data into multiple QUIC datagrams in quinn::Connection::poll_write(): https://github.com/posoo/quinn-dquic/blob/4f8b9bc8033385e1de5d3cbd1ae9b94e12365c56/quinn/src/connection.rs#L576-L603. This is because the current quinn implementation demands a QUIC datagram to fit into a "network frame", which, however, is not a requirement in QUIC's specification.

This new fix (posoo/quinn-dquic@4f8b9bc) works well in my small-scale tests even for server and client distribute in different machines. But it still didn't fix the issue in ALVR. I guess the reason might be there are some QUIC packets that contain partial "data frames" lost, i.e., split data frame chunks. Hence the receiver decoder

@posoo
posoo / new_user_with_pub_key.sh
Created May 31, 2023 22:33
Quickly create a new Linux user, set its password, and upload its public ssh key. (NO INTERACTION, ALL IN COMMANDS)
export NEW_USER="<USER_NAME>"
export NEW_USER_PASSWD="<SOME_PASSWORD>"
export NEW_USER_GROUP="<SOME_USER_GROUP>"
export NEW_USER_PUB_KEY="<SOME_PUB_KEY>"
sudo useradd -m -G $NEW_USER_GROUP -s /bin/bash $NEW_USER
echo "$NEW_USER:$NEW_USER_PASSWD"| sudo chpasswd
sudo -u $NEW_USER sh -c "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo $NEW_USER_PUB_KEY >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
@posoo
posoo / README.md
Last active June 11, 2023 22:30
Apply macOS key bindings on Windows (through Microsoft PowerToys)

Bring my favorite key bindings (shortcuts) from macOS on Windows through Microsoft PowerToys

Usage:

  • Install PowerToys from GitHub or Microsoft store
  • Open a Powershell and go to the keyboard manager configuration directory:
cd "C:\Users\$env:UserName\AppData\Local\Microsoft\PowerToys\Keyboard Manager"
  • If there is a default.json, back it up. Otherwise, create it.
  • Append or overwrite its content with values from the below attached default.json
@posoo
posoo / ddns_he_net.py
Created September 28, 2022 01:37
Update DDNS through HE.net's APIs
"""
Dynamic DNS on he.net
Using he.net's official APIs to update DNS records with queried public IP addresses
Please follow the official tutorial to set up required DNS entries in he.net:
https://dns.he.net/docs.html
"""
@posoo
posoo / convert_skim_note_to_roam_research.py
Created August 8, 2022 01:58
Convent Skim the exported note to be compatible with RoamResearch. Choose "File" -> "Export..." -> "File Format: Notes as Text" in Skim to get the input file.
import re
import click
def process(data: list):
parsed = []
i = 0
# flag indicates the next line:
# 0 -> page; 1 -> original highlighted text; 2 -> a blank line before my notes; 3 -> my notes
@posoo
posoo / setup-kernel-dev-ubuntu.sh
Created March 3, 2022 16:11
Set up the kernel development environment on Ubuntu (Tested on Ubuntu 20.04)
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
echo "Disable Ubuntu's annoying Apport"
systemctl disable apport.service
@posoo
posoo / recover_from_bak_files.py
Last active September 16, 2021 22:23
Recover original files from `.bak` files. Search in directories recursively.
# A progra conducted file conversion and made a copy of the original file as .bak file
# .bak files have name convention of <original_file_name>.<timestamp>.bak
# This simple program help to reverse such conversion.
import os
import click
def get_sub_files_and_dirs(parent_dir):
files_in_dir = []
dirs_in_dir = []
@posoo
posoo / hello-http.go
Created August 7, 2021 18:23
Simple Golang HTTP Server
package main
import (
"fmt"
"net/http"
)
var i int
func hello(w http.ResponseWriter, req *http.Request) {
@posoo
posoo / disable_offload.sh
Last active July 30, 2021 02:54
Hardware offloading hurts the performance of software P4 switch (BMV2) working with physical NICs
#!/bin/bash
set -xe
ifconfig $1 multicast allmulti promisc mtu 1500 up
ethtool -K $1 rx off # RX checksumming
ethtool -K $1 tx off # TX checksumming
ethtool -K $1 sg off # scatter gather
ethtool -K $1 tso off # TCP segmentation offload
ethtool -K $1 ufo off # UDP fragmentation offload