Skip to content

Instantly share code, notes, and snippets.

Avatar

Tony Colston tonetheman

View GitHub Profile
@tonetheman
tonetheman / mod.lua
Created Aug 29, 2022
lua code for a mod that works for 1 based numbers
View mod.lua
--[[
saw this buried in this code
https://www.lexaloffle.com/bbs/?tid=49068
]]--
function mod(val,modulo)
--Mod for 1 based numbers.
--3%3=3. 4%3=1, 1%3=1
return (val-1)%modulo+1
@tonetheman
tonetheman / structtesting.py
Created Aug 14, 2022
python3 struct read bytes
View structtesting.py
import struct
data = open("test.bin","rb").read()
# all of these are unsigned
def read_single_byte(data,position):
return struct.unpack("B",data[position:position+1])
def read_single_word(data,position):
return struct.unpack("H",data[position:position+2])
View example.cpp
#include <iostream>
#include "raylib.h"
int main(void) {
std::cout << "howdy" << std::endl;
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
@tonetheman
tonetheman / lines.pde
Created May 14, 2022
interesting processing i saw on twitter lost the link though :(
View lines.pde
int n=200,i,s,t;
float a[] = new float[n*4],d;
void setup() {
size(800,800);
colorMode(3);
blendMode(2);
for(i=0;i<n*4;i++) {
a[i] = 400-random(800);
@tonetheman
tonetheman / makefile
Created May 13, 2022
shows an overwrite in c (not enough space in the array greeting)
View makefile
# needed to include the no-stack-protector to make gcc
# be fast and loose with the stack
junk : test.c
gcc -o junk -g -fno-stack-protector test.c
clean :
rm -f ./junk
@tonetheman
tonetheman / server.py
Created May 11, 2022
Python3 http.server that does send back the 2 needed headers for SharedArrayBuffer errors
View server.py
"""
TONY notes
This is a DIRECT copy pasta of the server.py file in the official cpython github https://github.com/python/cpython/tree/main/Lib/http
I added the following two headers from SHEER FRUSTRATION to get past a random SharedArrayBuffer not defined error
line 749 or so
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
@tonetheman
tonetheman / turtle_frac.py
Created Nov 20, 2021
mandelbrot with turtle and Python3
View turtle_frac.py
#!/usr/bin/python3
import turtle
import sys
MAX_ITER = 100
def mand(c):
z = 0
n = 0
while abs(z) <= 2 and n < MAX_ITER:
@tonetheman
tonetheman / recur.nim
Created Oct 11, 2021
crazy recursive define of is_even and is_odd in nim
View recur.nim
# predicate zero or not
proc zero(n : int) : bool =
return n==0
# simple subtract 1
proc sub1(n : int) : int =
return n-1
# forward defs since this is recursive
View syscall_with_rust.rs
#![feature(llvm_asm)]
fn main() {
let message = String::from("hello world tony!\n");
syscall(message);
}
#[cfg(target_os = "linux")]
#[inline(never)]
fn syscall(message: String) {
let msg_ptr = message.as_ptr();
View oddhnew.pas
program TestMe;
var
i : Longint;
x : Longint = 0;
y : Real = 0;
begin
for i:=0 to 116000 do
begin
x := i;