Skip to content

Instantly share code, notes, and snippets.

View sgeos's full-sized avatar
💭
Too much to do, not enough time.

Brendan A R Sechter sgeos

💭
Too much to do, not enough time.
View GitHub Profile
@sgeos
sgeos / chatgpt4_no_std_roguelike.rs
Last active July 27, 2023 03:08
Took no_std Rust generated by ChatGPT 4 and cleaned it up a bit. The original code did not compile, but it was close and the core approach was sound.
#![no_std]
extern crate alloc;
extern crate libc;
use alloc::{ vec, vec::Vec, };
use core::convert::TryInto;
use libc::{ c_int, printf, };
struct Room {
x: usize,
@sgeos
sgeos / sdl2_simple_piano_roll.rs
Last active July 27, 2023 07:31
SDL2 based piano roll written in Rust. Consulted with ChatGPT4 and put solutions together.
extern crate sdl2;
use sdl2::audio::{ AudioCallback, AudioSpecDesired, };
#[derive(Copy, Clone)]
enum Note {
A = 0,
ASharp = 1,
B = 2,
C = 3,
@sgeos
sgeos / sdl2_looped_piano_roll.rs
Created July 27, 2023 07:33
This version of the piano roll opens a window and plays a looped piano roll until the user presses a key. ChatGPT4 was used instead of relying on standard technical documentation for information.
extern crate sdl2;
use sdl2::{
audio::{ AudioCallback, AudioSpecDesired, },
event::Event,
pixels::Color,
};
use std::{ time::{ Duration, Instant, }, };
#[derive(Copy, Clone)]
@sgeos
sgeos / water_fasting.rs
Created August 10, 2023 02:40
Water fasting calculations written in Rust. Most code written by chat GPT. Prompts, combining code, and refactoring done by a human engineer.
use std::fmt;
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
enum Sex {
Male,
Female,
}
impl Sex {
@sgeos
sgeos / gold_atoms.rs
Last active August 11, 2023 12:32
Gold atom and price calculations in Rust. Fact checking, prompts, combining code, and refactoring done by a human engineer.
// u128 seem like the right type for debiting and crediting atoms of gold
// u256 should be enough account for all the gold atoms in the universe
// micrograms of gold seem like a good unit for small transactions
fn gold_atoms_in_microgram(quantity: f64) -> u128 {
const AVOGADROS_NUMBER: f64 = 6.02214076e23; // atoms
const ATOMIC_WEIGHT_OF_GOLD: u128 = 196_966_570; // microgram/mol
(quantity * AVOGADROS_NUMBER) as u128 / ATOMIC_WEIGHT_OF_GOLD
}
@sgeos
sgeos / n_most_words.sh
Last active November 9, 2024 20:14
Shell script to get N most words given text input and desired number of words. Redirected input and output verbosity supported.
#!/usr/bin/env sh
# script flags
VERBOSE=true
# default inputs
DEFAULT_TEXT="The quick brown fox jumps over the lazy dog. Yes, the quick brown fox."
DEFAULT_COUNT=10
# check if input is redirected