Skip to content

Instantly share code, notes, and snippets.

View hsqStephenZhang's full-sized avatar
🎯
Focusing

z combinator hsqStephenZhang

🎯
Focusing
View GitHub Profile
@frroossst
frroossst / queen.rs
Created November 15, 2025 16:02
N queen problem in the Rust type system
#! /usr/bin/env -S cargo +nightly -Zscript
---
[package]
edition = "2024"
[dependencies]
---
#![recursion_limit = "1024"]
use std::marker::PhantomData;
@novafacing
novafacing / RUST_OPTION_RESULT_CONVERSIONS.md
Created October 17, 2023 23:13
Rust Option/Result conversion functions

I used to have a site bookmarked with a table of all these functions, but the link is dead. Here's a matrix of Option and Result conversion functions. These become second nature once you have used Rust for any significant length of time, but it's useful to have a table reference.

For each of the below:

  • T is the value possibly contained in an input Ok Result or Some Option.
  • U is a new value created by transforming or replacing an input T. Note that when U appears in methods like map, U ?= T, for example by calling
{
"type": "hysteria",
"tag": "hysteria-out",
"server": "SERVER-IP-ADDRESS",
"server_port": 8443,
"up_mbps": 500,
"down_mbps": 500,
"auth": "8JCsPssfgS8tiRwiMlhARg==",
"auth_str": "upiTU?rUW3+4e6Radro",
"disable_mtu_discovery": false,
@mingfeima
mingfeima / part_2_parallelization_techniques.md
Last active May 6, 2026 11:23
PyTorch CPU Performance Optimization Tutorial - Section II
@hsqStephenZhang
hsqStephenZhang / gist:5620b89314c49b22b3d8dc402af54229
Created January 20, 2022 04:48
linux objdump certain function
#!/bin/sh
routine=$1
func=$2
if [ -z "$routine" ]; then
exit
fi
start=$(nm -n $routine | grep "\w\s$func" | awk '{print "0x"$1;exit}')
@sts10
sts10 / rust-command-line-utilities.markdown
Last active July 13, 2026 23:49
A curated list of command-line utilities written in Rust

A curated list of command-line utilities written in Rust

Note: I have moved this list to a proper repository. I'll leave this gist up, but it won't be updated. To submit an idea, open a PR on the repo.

Note that I have not tried all of these personally, and cannot and do not vouch for all of the tools listed here. In most cases, the descriptions here are copied directly from their code repos. Some may have been abandoned. Investigate before installing/using.

The ones I use regularly include: bat, dust, fd, fend, hyperfine, miniserve, ripgrep, just, cargo-audit and cargo-wipe.

  • atuin: "Magical shell history"
  • bandwhich: Terminal bandwidth utilization tool
@grahamking
grahamking / main.rs
Created June 5, 2021 00:00
Memory ordering experiment in Rust. See https://preshing.com/20120515/memory-reordering-caught-in-the-act/ . Try changing the two HERE lines.
// 1. Run it as is (SeqCst). Should be just timing output
// 2. Change the two HERE lines to Ordering::Relaxed and run it again.
// That should give lots of (seemingly impossible) memory reorderings.
use rand;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::*;
use std::thread;
fn main() {
@apivovarov
apivovarov / riscv-debian.md
Last active March 5, 2026 17:17
Run RISC-V Debian via QEMU #riscv #qemu

Run RISC-V Debian GNU/Linux bullseye/sid via QEMU.

  1. Run the latest version of Debian on regular x86_64 box (at least ver 10 Buster, better to run ver 11 Bullseye)
  2. If opensbi and u-boot-qemu packages are not found add testing apt repository (aka bullseye). Or even unstable (aka sid)
sudo vi /etc/apt/sources.list

# Add testing repo (or unstable)
deb http://cdn-aws.deb.debian.org/debian testing main
deb-src http://cdn-aws.deb.debian.org/debian testing main
@graninas
graninas / What_killed_Haskell_could_kill_Rust.md
Last active June 12, 2026 07:31
What killed Haskell, could kill Rust, too

At the beginning of 2030, I found this essay in my archives. From what I know today, I think it was very insightful at the moment of writing. And I feel it should be published because it can teach us, Rust developers, how to prevent that sad story from happening again.


What killed Haskell, could kill Rust, too

What killed Haskell, could kill Rust, too. Why would I even mention Haskell in this context? Well, Haskell and Rust are deeply related. Not because Rust is Haskell without HKTs. (Some of you know what that means, and the rest of you will wonder for a very long time). Much of the style of Rust is similar in many ways to the style of Haskell. In some sense Rust is a reincarnation of Haskell, with a little bit of C-ish like syntax, a very small amount.

Is Haskell dead?

@mingfeima
mingfeima / pytorch_channels_last_perf_optimization.md
Last active May 6, 2026 09:08
PyTorch Channels Last memory format perf optimization and oneDNN integration plan.

PyTorch Channels Last Memory Format Performance Optimization on CPU Path

("mkldnn" has been renamed to "oneDNN", but exsiting PyTorch APIs still use "mkldnn", future work will align PyTorch user level APIs to "oneDNN")

Table of Contents

  • PyTorch Channels Last memory format introduction
  • oneDNN API for NHWC layout
  • Generic Channels Last memory format optimization with ATen native
  • oneDNN NHWC integration

NB: Memory format refers to data representation that describes how multidimensional arrays (nD) are stored in linear (1D) memory address space. Memory format has the same semantic with layout in oneDNN. Layout in PyTorch has other semantic ofdescribing dense or sparse with the attributes: 'torch.strided', 'torch.sparse_coo'.