Skip to content

Instantly share code, notes, and snippets.

View jonhoo's full-sized avatar
🤦‍♂️
Permanent 418 status code.

Jon Gjengset jonhoo

🤦‍♂️
Permanent 418 status code.
View GitHub Profile
@jonhoo
jonhoo / cell-tests.rs
Last active April 20, 2024 07:44
cell-refcell-rc
// 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 || {
@jonhoo
jonhoo / packet-generator.cpp
Created December 4, 2013 00:27
Complete example code showing how to construct a UDP packet from scratch and inject it on a WiFi interface in Linux
/**
* Hello, and welcome to this brief, but hopefully complete, example file for
* wireless packet injection using pcap.
*
* Although there are various resources for this spread on the web, it is hard
* to find a single, cohesive piece that shows how everything fits together.
* This file aims to give such an example, constructing a fully valid UDP packet
* all the way from the 802.11 PHY header (through radiotap) to the data part of
* the packet and then injecting it on a wireless interface
*
#![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 {
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>
@jonhoo
jonhoo / go-test-many.sh
Last active October 19, 2023 16:33
Script for running go tests many times in parallel, printing the current status, and logging errors
#!/bin/bash
#
# Script for running `go test` a bunch of times, in parallel, storing the test
# output as you go, and showing a nice status output telling you how you're
# doing.
#
# Normally, you should be able to execute this script with
#
# ./go-test-many.sh
#
#[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
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 / userChrome.css
Created June 5, 2018 05:34
Firefox tabs-on-bottom
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/* tabs on bottom of window */
#navigator-toolbox { -moz-box-ordinal-group: 10; }
#TabsToolbar { -moz-box-ordinal-group: 10; }
#PopupAutoCompleteRichResult {
margin-top: -35vh;
/*
position: fixed;
bottom: 74px;
@jonhoo
jonhoo / abstract.md
Created January 10, 2023 02:45
Living with Rust Long-Term abstract

Living with Rust Long-Term

Rust and its ecosystem are, seemingly, in constant flux. And this appearance of perpetual motion can be scary, especially when you're building an application with stability and long-term project sustainability in mind. New Rust versions bring ever-higher editions, must-have new features, and lint and tool changes to keep on top of. And as new features get adopted, new crates and major versions emerge, leaving once-vibrant ecosystems to fade into oblivion. All this happens while the software ecosystem surrounding and underpinning Rust continues its relentless march forward.

In this talk, we'll take a look at the kinds of changes that may happen under you when working with Rust and how to live with them. We'll talk about Rust and crate versioning, but also backwards compatibility, unstable features, minimum supported Rust versions, and 1.0 releases. This talk is geared towards those using Rust to build applications and services, not those building Rust libraries. It won't tell you

[START][2022-12-02 20:14:20] LSP logging initiated
[INFO][2022-12-02 20:14:20] .../vim/lsp/rpc.lua:261 "Starting RPC client" {
args = {},
cmd = "rust-analyzer",
extra = {
cwd = "/local/home/jongje/dev/tmp/consumer-of-needs-nightly"
}
}
[TRACE][2022-12-02 20:14:20] .../lua/vim/lsp.lua:953 "LSP[rust_analyzer]" "initialize_params" {
capabilities = {