Skip to content

Instantly share code, notes, and snippets.

@kettle11
kettle11 / Simple breakout for Processing
Last active August 29, 2015 14:19
A simple breakout framework intended for teaching early programming concepts.
//Classes
class Block
{
public int xPosition = 0;
public int yPosition = 0;
public int rightEdge = 10;
public int bottomEdge = 10;
public int myWidth = 10;
@kettle11
kettle11 / audio.rs
Created March 7, 2020 22:00
Audio callback with attenutation
impl AudioCallback for AudioThread {
type Channel = f32;
// All the mixing and primary audio logic is here.
fn callback(&mut self, out: &mut [Self::Channel]) {
let old_position = self.listener.position;
// let old_rotation = self.listener.rotation;
// Store previous position and tempo for interpoltation.
for instance in self.playing_clips.iter_mut() {
@kettle11
kettle11 / main.rs
Last active July 31, 2020 20:13
The minimal amount of code required to create a window on MacOS from Rust
use objc::runtime::{Object, NO};
use objc::*;
// We must link with AppKit for all application and windowing related matters.
#[link(name = "AppKit", kind = "framework")]
extern "C" {}
// https://developer.apple.com/documentation/objectivec/nsuinteger
#[cfg(target_pointer_width = "32")]
pub type NSUInteger = u32;
@kettle11
kettle11 / color_name_approximator.rs
Created March 6, 2022 15:57
Code for approximating color names
pub fn get_approximate_color_name(color: koi::Color) -> String {
let considered_exact = 0.1;
let hues = [
(0.0, "Pink"),
((29.0 / 360.), "Red"),
((53.0 / 360.), "Orange"),
((110.0 / 360.), "Yellow"),
((142.0 / 360.0), "Green"),
((195.0 / 360.0), "Cyan"),
@kettle11
kettle11 / color_temperature_to_srgb.rs
Last active August 16, 2022 19:10
Snippet illustrating how to convert Kelvin color temperatures to an sRGB color
// CC0 License
// These functions cannot be directly copy-pasted because they use a library called `kmath`
// but it should be easy enough transcribe to a different math library.
fn temperature_to_srgb_planckian_locus(temperature_kelvin: f64) -> kmath::Vector<f64, 3> {
// See here: https://en.wikipedia.org/wiki/Planckian_locus#Approximation
// And here: https://google.github.io/filament/Filament.html#lighting/directlighting/lightsparameterization
let k = temperature_kelvin;
let k2 = k * k;
#VERTEX
#version 300 es
precision mediump float;
in vec3 a_position;
void main()
{
@kettle11
kettle11 / gpt3_chat_lifetime_explainer.md
Created December 1, 2022 03:20
This gist was generated by asking chat.openai.com "Can you explain Rust lifetimes to me?"

Yes, I can explain Rust lifetimes to you. In the Rust programming language, lifetimes are a way of ensuring that references to objects are valid and safe. Lifetimes are used to specify the scope and duration for which a reference is valid, and they help prevent common pitfalls, such as accessing freed memory or using a reference after its corresponding object has been destroyed.

In Rust, lifetimes are typically declared using a set of angle brackets, such as <'a>, which indicates the lifetime of the reference. When a reference is declared with a lifetime, the Rust compiler checks to ensure that the reference is only used within the specified lifetime. This can prevent common errors, such as using a reference after its corresponding object has been dropped or freed.

Here is an example of a Rust function that uses lifetimes to ensure the safety and validity of references:

fn get_first_word(s: &str) -> &str {
    let bytes = s.as_bytes();
You are Webby, a website creation assistant.
Carefully adhere to the following steps for our conversation. Do not skip any steps!:
1. Introduce yourself
2. Ask my name and where I'm from. Offer me the option to continue in a different language, but default to English. In the next message say something personal and kind about where I'm from and include an emoji that references where I'm from.
3. Give me an extremely brief overview of how the website building process will go. Use numbered steps and emojis.
4. Ask what type of website I want to make (offer examples)
5. Ask what I'd like to title the website.
6. Ask a series of questions to clarify information and constraints for the website
@kettle11
kettle11 / gist:33413b02b028b7ddd35c63c0894caedc
Created December 3, 2022 23:23
Chat GPT World Builder Prompt
You are Whimsy, a world-building creation assistant. You are going to help me detail and describe an imaginary world.
Carefully adhere to the following steps for our conversation. Do not skip any steps!:
Main steps:
1. Introduce yourself. Ask what sort of world I'd like to build, offer some ideas including fantasy, scifi, and cyberpunk. Present the ideas as a numbered list with emojis. Also offer at least 2 other world types. Wait for my response.
2. Choose a name for the world. Present alternatives names as a numbered list with emojis or let me propose my own option. Wait for my respinse.
3. Choose a secondary theme for the world or let me propose my own options. Present alternative themes with a numbered list with emojis. Wait for my response.
4. Briefly describe the world and ask if I'd like to make changes. Tell me what the year within the world is. Do not set the year to the real world current year. Wait for my response.
@kettle11
kettle11 / chestnut.md
Last active August 30, 2023 16:57
Chestnut Street History in Philly

Chestnut St. was Philly's premiere shopping street, full of classy stores. The problem was all those stores were threatened by the surge of suburban malls.

So around 1975 Philly wanted to make Chestnut a mall-like pedestrian-only street, but it didn't have the funds. Federal transit agencies wanted to do a bus road and had the funds, so the 'transitway' was born from a compromise: busses down the middle and pedestrians on the sides. Further the whole thing needed to be rushed in time for Philly's 200th anniversary.

Over the next 5 years a few things happened:

  • Market West and East were redeveloping into dense office buildings, pushing out food, convenience stores, and theaters. This also brought in a huge flood of non-resident office workers.
  • Fast food and convenience stores were on the rise.
  • "Classy" boutique stores, Chestnut Street's staples, were on the decline due to pressure from suburban malls.

Chestnut had an influx of businesses catering to office workers: fastfood