Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
justanotherdot / x-compile-test
Last active March 21, 2023 16:59
Attempt to build all cross-compile targets supported by `rustc` and report the time taken.
#!/bin/sh -eu
FILTER="${FILTER:="."}"
TOOLCHAIN_BK="$(rustup toolchain list | rg default | awk '{print $1}')"
TOOLCHAIN_KIND_BK="$(echo "$TOOLCHAIN_BK" | rg -o '^(stable|nightly)')"
if [ "$TOOLCHAIN_KIND_BK" != "stable" ]; then
rustup install stable
rustup default stable
fi
@justanotherdot
justanotherdot / Dockerfile.bite_sized_networking
Last active May 20, 2022 08:56
A Dockerfile with (almost) all the tools mentioned in Bite Size Networking by Julia Evans
# N.B. The only tool missing here that is mentioned in the document is `zenmap`
# purely because this image is intended to be run via a CLI and `zenmap` is a GUI
# to `nmap` i.e. one can play around with the tools by running:
#
# $ docker build --name bite_size_networking:latest .
# $ docker run --rm -d --name bsn_test bite_size_networking:latest
# $ docker exec -it bsn_test bash
#
# Alternatively, one can change the `ENTRYPOINT` to `["bash"]` and run:
#
@justanotherdot
justanotherdot / box.txt
Last active March 28, 2022 11:41
Box unicode characters for diagrams in documentation, terminals, etc.
─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ╌ ╍ ╎ ╏
┌ ┍ ┎ ┏ ┐ ┑ ┒ ┓
└ ┕ ┖ ┗ ┘ ┙ ┚ ┛
├ ┝ ┞ ┟ ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫
┬ ┭ ┮ ┯ ┰ ┱ ┲ ┳
@justanotherdot
justanotherdot / box-example.txt
Last active March 28, 2022 08:12
Box unicode characters.
┏━━━┓
┃ ┃
┗━━━┛
┏━┳━┳━┓
┃ ┃ ┃ ┃
┗━┻━┻━┛
╭───╮
│ │
#![feature(allocator_api)]
use std::alloc::Allocator;
use std::alloc::Global;
use std::marker::PhantomData;
// Basicaly a Vec.
pub struct V<T, A: Allocator = Global> {
pub buf: Rv<T, A>,
pub len: usize,
@justanotherdot
justanotherdot / trello_delete_archived_cards.py
Created March 19, 2018 00:28
Batch delete of archived cards with Trello API
import requests
import json
import time
API_KEY = ""
API_TOKEN = ""
table_id = ""
url = "https://api.trello.com/1/boards/{}/cards/closed/?key={}&token={}".format(table_id, API_KEY, API_TOKEN)
use rand::Rng;
use std::default::Default;
use std::{cell::RefCell, collections::HashMap, time::Duration};
use tokio::{self, select, task, task_local, time::timeout};
fn rand_gen_millis() -> (u64, u64) {
let mut rng = rand::thread_rng();
let t1 = rng.gen_range(0..10);
let t2 = rng.gen_range(0..10);
(t1, t2)
use tokio;
use tokio::{task, task_local};
use std::cell::RefCell;
use std::collections::HashMap;
#[tokio::main]
async fn main() {
let handler = task::spawn(async {
task_local! {
pub static WRITER: RefCell<HashMap<String, i64>>;
@justanotherdot
justanotherdot / rust-underscore-idiom.rs
Created January 29, 2021 21:16
Avoid prefixing variables you will use with an underscore.
// Rust Idiom:
// prefixing a variable with an underscore
// signals to others that the variable
// isn't going to be used, not that it is
// intentionally private or an updated
// variable.
main () {
let x = 12;
// _x reads as
@justanotherdot
justanotherdot / sans-clone-derive.rs
Created January 29, 2021 21:10
Cloning borrows to things that lack a Clone impl simply return the original borrow.
// NB. fix
// #[derive(Debug, Clone)]
#[derive(Debug)]
struct Context;
fn dupe_context(context: &Context) -> Context {
context.clone()
}
fn main() {