Skip to content

Instantly share code, notes, and snippets.

View 0atman's full-sized avatar
🦀
Oxidising

Tristram Oaten 0atman

🦀
Oxidising
View GitHub Profile
#![allow(dead_code, unused_variables)]
fn main() {}
struct Machine<State> {
data: Vec<u16>,
state: State,
}
struct State1 {}
struct State2 {}
@0atman
0atman / PR-Template.md
Created December 4, 2023 09:17
I'd love to learn more about git-native issues and projects, though my first thought is that if they're stored in markdown, you can build them in whatever editors you would like! Here's a mockup

head: 0atman:branch-name-with-your-changes assignee: 0atman base: local-branch-name-on-this-repo draft: true issue: linked issue url? reviewers:

  • 0atman
  • user2
  • user3
@0atman
0atman / scoped_threads.rs
Last active March 13, 2024 11:05
Unlike non-scoped threads, scoped threads can borrow non-'static data, as the scope guarantees all threads will be joined at the end of the scope.
use std::thread;
struct User {
age: u16,
}
fn simple_thread() {
let user = User { age: 30 };
// thread::spawn(|| &user); // can't borrow `user` as thread may outlive current function
thread::spawn(|| user); // can only move into thread, then it's gone.
use rand_derive2::RandGen;
use rand::random;
fn main() {
println!("Hey, world! 👻 3spoopy5me");
let some_rooms: Vec<Room> = (1..=5)
.map(|n| Room {name: "empty room".into(), next_room: vec![], item: random()})
.collect();
let room = Room {
@0atman
0atman / typer.rs
Created June 12, 2022 08:39
Auto-typer from Lost Terminal
use std::fs;
use std::io::{self, BufRead, Write};
use std::{thread, time};
/// stdout readline implementation
fn wait() {
io::stdin().lock().lines().next();
}
/// Type the script at 300wpm
@0atman
0atman / rust-perfect.md
Created May 19, 2022 16:52
The sourcecode to my Rust Perfect presentation (available here https://www.youtube.com/watch?v=IA4q0lzmyfM)

Rust

Your code can be perfect

%% As developers we build critical infrastructure, it's time to build it in a language designed to build critical infrastructure. %%

@0atman
0atman / Makefile
Last active March 7, 2022 14:58
Sensible python defaults in 2022
default: lints run
run:
@poetry run python app.py
watch:
@poetry run watchmedo auto-restart --ignore-directories --patterns="*.py" --ignore-patterns="*#*" --recursive make
lints:
clear
@0atman
0atman / markup-example.rs
Last active April 3, 2021 10:01
markup.rs is pug with brackets
html {
head {
title { "example.com" }
style {
"body { background: #fafbfc; }"
"#main { padding: 2rem; }"
}
}
body {
@Header { "example.com" }
/*******************************************************************
A telegram bot for your Adafruit Feather M0 with KeyboardFeatherWing
Adapted from telegram code written by Brian Lough
*******************************************************************/
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <WiFi101.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
@0atman
0atman / main.rs
Last active January 15, 2021 10:19
Simple C programming bootstrap file in Rust
#![feature(start, libc, lang_items)]
#![no_std]
#![no_main]
#![feature(rustc_private)]
extern crate libc;
extern { // A list of imported C functions
pub fn printf(format: *const u8, ...) -> i32;
}