Skip to content

Instantly share code, notes, and snippets.

View timClicks's full-sized avatar
🏠
Working from home

Tim Clicks timClicks

🏠
Working from home
View GitHub Profile
@timClicks
timClicks / README.md
Created May 9, 2024 09:41
Lints used across all Rust crates on crates.io Data from "Lints to add to your crates"

Lints used across all Rust crates

What is this? See this 4 minute video https://www.youtube.com/watch?v=dJiL9gHNgKU

Description

denials.tsv is the source data generated from searching through every crate. lints-ranked-by-usage.txt provides an indication of how popular each lint is.

It's produced with this shell pipeline:

@timClicks
timClicks / Cargo.toml
Last active November 28, 2023 23:32
async chat server
[package]
name = "chat"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures-util = { version = "0.3.28", features = ["sink"] }
http = "0.2.9"
@timClicks
timClicks / lol.c
Last active February 16, 2024 08:14
How many bugs can you spot?
// By [Colin Finck] and used by the [Comprehensive Rust] course,
// developed by the Android team at Google.
//
// This code compiles warning-free at the default warning level,
// even in the latest GCC version (13.2 as of writing).
//
// [Colin Finck]: https://colinfinck.de/Master_Thesis_Slides.pdf
// [Comprehensive Rust]: https://github.com/google/comprehensive-rust
#include <stdio.h>
@timClicks
timClicks / Cargo.toml
Created September 2, 2023 10:39
Using Rust's MPSC channels to create a system monitoring utility
[package]
name = "tmon"
version = "0.1.0"
edition = "2021"
description = "Code used in this (https://www.youtube.com/live/mVyNAwzj5mA?si=vk-4qPsFlT4x3g6Z) tutorial"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sysinfo = "0.29"
use std::collections::BinaryHeap;
use std::sync::{
mpsc::{channel, Receiver, Sender},
Arc, Mutex,
};
use std::thread;
use std::time::Duration;
#[derive(Debug, Ord, PartialOrd, PartialEq, Eq)]
enum Task {
@timClicks
timClicks / priorityqueue.rs
Last active October 30, 2023 14:53
Making a practical priority queue from std::collections::BinaryHeap
use std::collections::BinaryHeap;
// Create a type that implements Ord to represent your tasks. That can be
// fed into BinaryHeap with a tuple, using its first field representing priority,
//
// > "When derived on enums, variants are ordered by their discriminants"
// > - https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html#derivable
#[derive(Debug, Ord, PartialOrd, PartialEq, Eq)]
enum Task {
A,
@timClicks
timClicks / pixie.rs
Created June 29, 2023 03:23
Pixelate images in less than 50 lines of code
//! # pixie
//!
//! Pixelate images. This file provides the code demonstrated
//! in this video: <https://youtu.be/Q18vAySAiHc>
//!
//! Uses image 0.24.0 <https://docs.rs/image/0.24.6/image/>
use image::io::Reader as ImageReader;
use image::{GenericImageView, DynamicImage, ImageBuffer, Rgba};
@timClicks
timClicks / ringo.rs
Created June 27, 2023 23:30
Ring buffer implementation
// code from https://youtu.be/TQVwv_e_rMw
#[derive(Debug)]
struct RingBuffer<T: Clone> {
storage: Vec<Option<T>>,
read_idx: usize,
write_idx: usize,
}
#[derive(Debug)]
@timClicks
timClicks / fst.rs
Created June 11, 2023 21:26
A simple finite state machine in Rust (from https://youtu.be/xuu3FrTKb50)
#[derive(Debug)]
enum TrafficSignal {
Green,
Yellow,
Red,
}
impl TrafficSignal {
fn step(&mut self) {
use TrafficSignal::*;
@timClicks
timClicks / main.rs
Created March 27, 2023 22:08
Axum Example
use axum::{response::Json, routing::get, Router};
use serde_json::{json, Value};
async fn greet() -> Json<Value> {
Json(json!({ "msg": "Hello, world!" }))
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()