Skip to content

Instantly share code, notes, and snippets.

View SteveLauC's full-sized avatar
😃
I love code that is extremely easy to follow!

SteveLauC SteveLauC

😃
I love code that is extremely easy to follow!
  • $HOME
  • 13:19 (UTC +08:00)
View GitHub Profile
@SteveLauC
SteveLauC / signed_int_addition.c
Last active March 17, 2022 03:34
Interget overflow check program
/*
* signed int addition overflow test
* exit(EXIT_FAILURE) if result overflows
* print the correct value if everything is good.
*/
#include <stdio.h>
#include <stdlib.h>
int add(int x, int y) {
@SteveLauC
SteveLauC / read_char.rs
Last active April 9, 2022 08:12
Read an ascii char from stdin in Rust.
use std::io::{Read, stdin};
/*
return: Some(char) on success, None on EOF or error.
*/
fn read_char() -> Option<char> {
stdin().bytes().next().and_then(|res| res.ok()).map(|c| {
char::from(c)
})
}
#Put it in the file '$home /. Cargo / config'
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
#Replace it with your preferred mirror source
replace-with = 'sjtu'
#replace-with = 'ustc'
#Tsinghua University
[source.tuna]
# execute the following script in your terminal
echo "set -sg escape-time 0" >> ~/.tmux.conf
tmux source-file ~/.tmux.conf
@SteveLauC
SteveLauC / chn_fonts.reg
Created August 26, 2022 00:56 — forked from swordfeng/chn_fonts.reg
Chinese font settings in wine
REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Arial"="wqy-microhei.ttc"
"Arial Black"="wqy-microhei.ttc"
"Arial CE,238"="wqy-microhei.ttc"
"Arial CYR,204"="wqy-microhei.ttc"
"Arial Greek,161"="wqy-microhei.ttc"
"Arial TUR,162"="wqy-microhei.ttc"
"Courier New"="wqy-microhei.ttc"
@SteveLauC
SteveLauC / map-vs-and_then.rs
Last active October 6, 2022 10:45
Stupid code snippet to tell the diff between `map` and `and_then`
fn map_using_if<T, U, F>(s: Option<T>, f: F) -> Option<U>
where
F: FnOnce(T) -> U,
{
if let Some(item) = s {
Some(f(item))
} else {
None
}
}
@SteveLauC
SteveLauC / main.rs
Created November 10, 2023 03:05
Hey! Are we coding today?
fn main() {
println!("Hello World!");
}
@SteveLauC
SteveLauC / Test the above code.sh
Last active December 12, 2023 06:43
A program demostrating the impact of cache line bouncing
$ neofetch
_,met$$$$$gg. steve@debian
,g$$$$$$$$$$$$$$$P. ------------
,g$$P" """Y$$.". OS: Debian GNU/Linux 12 (bookworm) x86_64
,$$P' `$$$. Kernel: 6.1.0-15-amd64
',$$P ,ggs. `$$b: Uptime: 1 day, 5 hours, 34 mins
`d$$' ,$P"' . $$$ Packages: 1807 (dpkg), 22 (flatpak)
$$P d$' , $$P Shell: zsh 5.9
$$: $$. - ,d$$' Resolution: 3440x1440
$$; Y$b._ _,d$P' DE: GNOME 43.9