Skip to content

Instantly share code, notes, and snippets.

Avatar
🤦‍♂️
Permanent 418 status code.

Jon Gjengset jonhoo

🤦‍♂️
Permanent 418 status code.
View GitHub Profile
View tag-from-cargo-toml.sh
#!/bin/bash
dry=0
if [[ $# -gt 0 && $1 == "-n" ]]; then
dry=1
shift
fi
prefix="v"
if [[ $# -gt 0 ]]; then
if [[ $1 = -* || $# -gt 1 ]]; then
View mpsc.rs
use std::collections::VecDeque;
use std::sync::{Arc, Condvar, Mutex};
// Flavors:
// - Synchronous channels: Channel where send() can block. Limited capacity.
// - Mutex + Condvar + VecDeque
// - Atomic VecDeque (atomic queue) + thread::park + thread::Thread::notify
// - Asynchronous channels: Channel where send() cannot block. Unbounded.
// - Mutex + Condvar + VecDeque
// - Mutex + Condvar + LinkedList
@jonhoo
jonhoo / cell-tests.rs
Last active Sep 21, 2022
cell-refcell-rc
View cell-tests.rs
// these aren't _quite_ functional tests,
// and should all be compile_fail,
// but may be illustrative
#[test]
fn concurrent_set() {
use std::sync::Arc;
let x = Arc::new(Cell::new(42));
let x1 = Arc::clone(&x);
std::thread::spawn(move || {
View crust-of-rust-mascot.md

Hi there!

I'm looking for a mascot to use with my [YouTube] and [Twitch] channels. Unlike seemingly many of the channels out there, mine is not gaming related, but is instead a place where I do live programming videos with an educational focus on the [Rust programming language].

My want for a mascot is particularly tied to a new series of streams I've started doing called "Crust of Rust". I think the name is cute, and warrants a mascot, though I'd like to also use the mascot for the rest of my channel.

View iterators.rs
pub trait IteratorExt: Iterator + Sized {
fn our_flatten(self) -> Flatten<Self>
where
Self::Item: IntoIterator;
}
impl<T> IteratorExt for T
where
T: Iterator,
{
fn our_flatten(self) -> Flatten<Self>
View vecmac.rs
#[macro_export]
macro_rules! avec {
($($element:expr),*) => {{
// check that count is const
const C: usize = $crate::count![@COUNT; $($element),*];
#[allow(unused_mut)]
let mut vs = Vec::with_capacity(C);
$(vs.push($element);)*
vs
View strsplit.rs
#![warn(rust_2018_idioms)]
#[derive(Debug)]
pub struct StrSplit<'haystack, D> {
remainder: Option<&'haystack str>,
delimiter: D,
}
impl<'haystack, D> StrSplit<'haystack, D> {
pub fn new(haystack: &'haystack str, delimiter: D) -> Self {
View podcast.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
>
<channel>
<atom:link href="{{ site.url }}{{ page.url }}" rel="self" type="application/rss+xml" />
<link>{{ site.url }}</link>
View googleplay-podcast-sample-feed.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" version="2.0">
<channel>
<title>The Unknown Podcast</title>
<link>http://sample.com/podcasts/unknown/index.html</link>
<language>en-us</language>
<copyright>℗ 2025 Unknown Podcaster Corp</copyright>
<googleplay:author>Unannounced Podcaster</googleplay:author>
<googleplay:description>The Unknown Podcast will look at all the things that are unknown or unknowable. Find us on Google Play Music!</googleplay:description>
<description>The Unknown Podcast will look at all the things that are unknown or unknowable.</description>
View trace-timing-through-buffer
view-request::submit request:
mean: 5.3µs, p50: 8µs, p90: 16µs, p99: 24µs, p999: 24µs, max: 24µs, #: 34
1µs | ************************************ | 88.2th %-ile
2µs | | 88.2th %-ile
4µs | | 88.2th %-ile
8µs | | 88.2th %-ile
16µs | **** | 97.1th %-ile
view-request::waiting for service readiness:
mean: 1404.2µs, p50: 1466µs, p90: 1859µs, p99: 3670µs, p999: 3670µs, max: 3670µs, #: 34
64µs | ** | 2.9th %-ile