Skip to content

Instantly share code, notes, and snippets.

@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,
@stonegao
stonegao / generate_blocks.sh
Created February 12, 2023 04:34 — forked from System-Glitch/generate_blocks.sh
Tutorial for bitcoin regtest
# Script to generate a new block every minute
# Put this script at the root of your unpacked folder
#!/bin/bash
echo "Generating a block every minute. Press [CTRL+C] to stop.."
address=`./bin/bitcoin-cli getnewaddress`
while :
do

The correct way, install homebrew on apple m1.

# We'll be installing Homebrew in the /opt directory.
cd /opt

# Create a directory for Homebrew. This requires root permissions.
sudo mkdir homebrew

# Make us the owner of the directory so that we no longer require root permissions.
sudo chown -R $(whoami) /opt/homebrew
@stonegao
stonegao / prng.js
Created December 27, 2022 08:09 — forked from blixt/prng.js
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**