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 / notebook_launcher.py
Created May 17, 2012 08:03 — forked from timo/notebook_launcher.py
branded ipython notebook launcher
"""==============================
Branded IPython Notebook Launcher
=================================
Executing this module will create an overlay over ipython notebooks own static
files and templates and overrides static files and templates and copies over all
example notebooks into a temporary folder and launches the ipython notebook server.
You can use this to offer an interactive tutorial for your library/framework/...

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@timClicks
timClicks / zip_arrays.rs
Last active June 21, 2020 09:01
How to .zip() through items in two arrays in Rust
fn main() {
let x_coordinates: [f32; 4] = [0., 1., 2., 3.];
let y_coordinates: [f32; 4] = [0., 1., 4., 9.];
for (x, y) in x_coordinates.iter().zip(y_coordinates.iter()) {
// Comparisons require that you dereference the values.
// iter() for arrays returns a reference to each element.
if *x <= 0.0 || *y <= 1.0 {
continue;
@timClicks
timClicks / Cargo.toml
Created June 25, 2020 09:55
Implementating Circle Packing in Rust
[package]
name = "circle-packing"
version = "0.1.0"
authors = ["Tim McNamara <paperless@timmcnamara.co.nz>"]
edition = "2018"
[dependencies]
nannou = "0.14"
@timClicks
timClicks / bfs.rs
Created February 15, 2022 03:19
Breadth-first search in Rust
// watch the video if you would like an explanation of this code
// https://youtu.be/FoNJ5zhL6bQ
use std::collections::{HashSet, VecDeque};
use std::hash::Hash;
trait Graph {
type Node: Hash + Eq + Clone + std::fmt::Debug;
fn neighbours(&self, node: &Self::Node) -> Vec<Self::Node>;
@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()
@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 / 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 / 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 / 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,