Skip to content

Instantly share code, notes, and snippets.

View jinyangustc's full-sized avatar

Jinyang Li jinyangustc

View GitHub Profile
@jinyangustc
jinyangustc / latency.markdown
Created June 25, 2025 00:06 — forked from nelsnelson/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Syscall on Intel 5150 ...................... 105 ns
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Context switch on Intel 5150 ............. 4,300 ns  =   4 µs

Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs

@jinyangustc
jinyangustc / python_sum_types.py
Created April 19, 2025 22:14
Python Sum Types
import time
import traceback
from typing import Literal, final
class String:
"""
A variant containing a string
"""
@jinyangustc
jinyangustc / nano.el
Created February 28, 2025 07:11 — forked from rougier/nano.el
NANO Emacs (minimal version: 256 lines)
;; nano-emacs.el --- NANO Emacs (minimal version) -*- lexical-binding: t -*-
;; Copyright (c) 2025 Nicolas P. Rougier
;; Released under the GNU General Public License 3.0
;; Author: Nicolas P. Rougier <[email protected]>
;; URL: https://github.com/rougier/nano-emacs
;; This is NANO Emacs in 256 lines, without any dependency
;; Usage (command line): emacs -Q -l nano.el -[light|dark]
@jinyangustc
jinyangustc / RPiWiFiFreeze.md
Created March 27, 2024 03:41 — forked from Paraphraser/RPiWiFiFreeze.md
Do your Raspberry Pi's Network Interfaces freeze? This may solve it.

Do your Raspberry Pi's Network Interfaces freeze?

My Raspberry Pi 4 kept losing its wlan0 interface. I could usually reconnect via Ethernet but, from time to time, I noticed that the eth0 interface would also go walkabout.

I tried a lot of things but the one described here seems to have cured the problem. I have no idea why it works. It just does.

Step 0 - are you a Windows user?

The script shown in the next step should be created on your Raspberry Pi. Please do not make the mistake of selecting the text, copying it into a text editor on your Windows machine, saving the file, and then moving the file to your Raspberry Pi. Unless you take precautions, Windows will add its 0x0d 0x0a (CR+LF) line endings and those will stop the script from working properly on your Raspberry Pi.

@jinyangustc
jinyangustc / Checking your Raspberry Pi's view of its power supply.md
Created March 26, 2024 19:00 — forked from Paraphraser/Checking your Raspberry Pi's view of its power supply.md
Checking your Raspberry Pi's view of its power supply (sometimes it's not the wall-wart)

Checking your Raspberry Pi's view of its power supply

Sometimes it seems like the first (and sometimes only) advice you get offered for almost any problem with a Raspberry Pi is "check your power supply". You think something like:

"hey, I'm using an official power supply sold as being matched with my Pi so how can there be any problem?"

You look up the specs then stick a controlled load across your supply and confirm that it can deliver the required number of Watts.

Yet your problems persist…

@jinyangustc
jinyangustc / htop.usage
Created December 23, 2023 22:20 — forked from makeittotop/htop.usage
htop explanation
System wide cpu usage:
The numbers on the top left from 1 to 8 represents the number of cpu's/cores in my system with the progress bar next to them representing the load of cpu/core. As you would have noticed the progress bars can be comprised of different colors. The following list will explain what each color means.
Blue: low priority processes (nice > 0)
Green: normal (user) processes
Red: kernel processes
Yellow: IRQ time
Magenta: Soft IRQ time
Grey: IO Wait time
@jinyangustc
jinyangustc / ssh
Created February 11, 2023 04:21 — forked from danydev/ssh
Update iTerm Badge with hostname of the server used to ssh
#!/bin/bash
# Script that updates the iTerm Badge with the hostname of the server that you are
# connecting to with ssh.
#
# Instructions:
# - Put this script in ~/bin/ssh (this will override the default ssh binary)
# - Run 'chmod +x ~/bin/ssh' to give execution permission to the script
# - Open iTerm\Preferences\Profiles, select your profile and put '\(user.current_ssh_host)' in the Badge text box
# - Enjoy!
set nocompatible
filetype indent on
syntax on
set hidden
set wildmenu
set showcmd
set incsearch
set nohlsearch
hi Search ctermbg=Grey
set backspace=indent,eol,start
@jinyangustc
jinyangustc / Acme.sublime-color-scheme
Created December 28, 2021 03:24 — forked from multiversecoder/Acme.sublime-color-scheme
A new Sublime Text color scheme inspired by Plan9 and Acme
{
"name": "Acme",
"author": "Adriano Romanazzo (multiversecoder)",
"globals":
{
"foreground": "#000",
"background": "#FFFEEC",
"border": "13px solid #000",
"accent": "#000",
"caret": "#000",
@jinyangustc
jinyangustc / python_cheatsheet.md
Last active December 5, 2019 21:11
Python cheatsheet

How to sort dict...

By value

Return as a list of tuples:

x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=lambda kv: kv[1])
#=> [(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]