Skip to content

Instantly share code, notes, and snippets.

@stonegao
stonegao / p2pk.rs
Created June 15, 2023 11:55 — forked from sgeisler/p2pk.rs
// bitcoin = "*"
// bitcoin_hashes = "*"
use bitcoin::{Address, Network, Script};
use bitcoin::util::address::Payload;
use bitcoin::util::psbt::serialize::Deserialize;
use bitcoin_hashes::{hash160, Hash};
fn main() {
let bytes: &[u8] = &[
@stonegao
stonegao / interesting_crates.md
Created May 16, 2023 11:59 — forked from vi/interesting_crates.md
List of crates that improves or experiments with Rust, but may be hard to find

Let's list here crates that enhance Rust as a language.

It not "batteries" like in stdx, but Rust-specific crates for workarounds for various missing features and experimental ideals from non-accepted/postponed RFCs, or just hacky tricks.

The list is supposed to contain (mostly) crates that are internal to Rust, not ones for making Rust deal with "external world" like other languages bindings, file formats, protocols and so on.

Primary focus should be on crates that are not easy to find by conventional means (e.g. no algorithm name, format or protocol to search for).

Note that quality of the listed crates may vary from proof-of-concept to stable-and-widely-used.

@stonegao
stonegao / Cargo.toml
Created May 16, 2023 11:59 — forked from tristan-f-r/Cargo.toml
Small WebRTC-rs example
[package]
name = "rs-example"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
webrtc = "0.4.0"
tokio = { version = "1.15.0", features = ["full"] }
@stonegao
stonegao / work_queue.rs
Created May 16, 2023 11:58 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
// Here is an extremely simple version of work scheduling for multiple
// processors.
//
// The Problem:
// We have a lot of numbers that need to be math'ed. Doing this on one
// CPU core is slow. We have 4 CPU cores. We would thus like to use those
// cores to do math, because it will be a little less slow (ideally
// 4 times faster actually).
//
// The Solution:
@stonegao
stonegao / rust-server.rs
Created May 16, 2023 11:57 — forked from Vultour/rust-server.rs
TCP server in Rust
use std::io::prelude::*;
use std::net::{TcpListener, TcpStream, Shutdown};
use std::sync::mpsc;
use std::io::BufReader;
use std::thread;
use std::str;
fn listen(tx_pipe: mpsc::Sender<u32>){
let listener = TcpListener::bind("127.0.0.1:7777").unwrap();
@stonegao
stonegao / borrow-checker-faqs.md
Created May 16, 2023 10:55 — forked from jyn514/borrow-checker-faqs.md
tips and tricks for dealing with the borrow-checker

(I plan to publish this as a blog post once a few people have looked at it and caught the obvious typos.)

I got lots of positive feedback about the FAQ section in my Rust 2020 blog post, so I'm trying that format again for another topic that's been requested a lot: How to fix common borrow-checker issues. This isn't meant to explain how or why the borrow checker works the way it does (see The Nomicon or Two Beautiful Rust Programs for that), just how to work around some of its current limitations.

@stonegao
stonegao / settings.jsonc
Created May 15, 2023 12:06 — forked from hyperupcall/settings.jsonc
VSCode config to disable popular extensions' annoyances (telemetry, notifications, welcome pages, etc.)
// I'm tired of extensions that automatically:
// - show welcome pages / walkthroughs
// - show release notes
// - send telemetry
// - recommend things
//
// This disables all of that stuff.
// If you have more config, leave a comment so I can add it!!
{
@stonegao
stonegao / macOS Internals.md
Created May 7, 2023 15:45 — forked from kconner/macOS Internals.md
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

@stonegao
stonegao / riscv.md
Created March 2, 2023 08:43 — forked from cb372/riscv.md
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

@stonegao
stonegao / text-sprite.ts
Created February 13, 2023 08:06 — forked from ruslanchek/text-sprite.ts
TextSprite for Three.js
import * as THREE from 'three';
const FONT_FAMILY:string = 'Open Sans';
export enum TextAlign {
NONE,
START,
END,
LEFT,
CENTER,