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 / 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 / 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 / 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 / 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 / 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 / no_std_rust_string_ffi_example.rs
Last active July 27, 2023 01:23
no_std_rust_string_ffi_example.rs
#![no_std]
extern crate alloc;
extern crate libc;
use alloc::{ boxed::Box, ffi::CString, string::{ String, ToString, } };
use hashbrown::HashMap;
use libc::{ c_char, c_void, printf, };
#[no_mangle]
@sgeos
sgeos / gimp-batch-coloring-book-convert.scm
Last active July 27, 2023 01:23
gimp-batch-coloring-book-convert.scm
(map
(lambda (image)
(gimp-image-undo-group-start image)
(define fullpath (car (gimp-image-get-filename image)))
(define filename (car (reverse (strbreakup fullpath "/"))))
(define path (car (strbreakup fullpath filename)))
(define basefilename (car (strbreakup filename ".")))
(define xcfpath (string-append path basefilename ".xcf"))
(define linepath (string-append path "bw_" basefilename ".png"))
// ChatGPT Prompt
// Please write a Rust function to generate rooms in a Rogue style dungeon.
// Thoughts:
// As far as basic structure goes, this works. It needs a lot of work to be useful.
use rand::Rng;
struct Dungeon {
width: usize,
@sgeos
sgeos / qsort_ascending.c
Last active July 8, 2023 06:37
C qsort example. It takes a list of values from the command line and sorts them in ascending order.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
void usage(const char *pProgramName) {
printf("Usage: %s x y z ...\n", pProgramName);
printf("Example: %s 818 -3 566 5 12 100 12 25\n", pProgramName);
printf(" This program will sort numbers in ascending order.\n");
}
@sgeos
sgeos / exrm_ecto_create_drop_tasks.sh
Last active September 13, 2016 09:39
exrm PostgreSQL/MySQL release equivalents for `mix ecto.create` and `mix ecto.drop`.
# PostgreSQL `mix ecto.create` equivalent
psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';"
createdb "${DB_NAME}"
psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};"
# PostgreSQL `mix ecto.drop` equivalent
dropdb "${DB_NAME}"
dropuser "${DB_USER}"
# PostgresSQL interactive terminal