Skip to content

Instantly share code, notes, and snippets.

View zesterer's full-sized avatar

Joshua Barretto zesterer

View GitHub Profile
// We're writing this code in 32-bit protected mode for now
.code32
// Declare multiboot header creation constants
.set ALIGN, 1 << 0 // Align loaded modules on page boundaries
.set MEMINFO, 1 << 1 // Provide memory map
.set FLAGS, ALIGN | MEMINFO // Multiboot 'flag' field
.set MAGIC, 0x1BADB002 // Magic number helps bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) // Checksum of the above to prove it's multiboot
/* The bootloader will look at this image and start execution at the symbol
designated as the entry point. */
ENTRY(_bootstrap)
/* Tell where the various sections of the object files will be put in the final
kernel image. */
SECTIONS
{
/* Begin putting sections at 1 MiB, a conventional place for kernels to be
loaded at by the bootloader. */
@zesterer
zesterer / gist:470d60b9be804b60256b7f0dd0ae00c8
Created April 3, 2017 16:20
readelf --relocs build-default/kernel/x86/amd64/arch.cpp
[17:05][joshua@archbox][~/Documents/Projects/tupai-dev] readelf --relocs build-default/kernel/x86/amd64/arch.o
Relocation section '.rela.text' at offset 0x6a0 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000002 000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 0
Relocation section '.rela.debug_info' at offset 0x6b8 contains 25 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000006 00080000000a R_X86_64_32 0000000000000000 .debug_abbrev + 0
00000000000c 000b0000000a R_X86_64_32 0000000000000000 .debug_str + b3
@zesterer
zesterer / refbucket.cpp
Created August 29, 2017 10:46
Thread-safe reference-based object bucket in C++
#include <iostream>
#include <mutex>
#include <unordered_map>
namespace PtrTest
{
/* Definitions */
typedef long id_t;
const id_t ID_INVALID = -1;
@zesterer
zesterer / hover.py
Created March 4, 2018 22:48
Kerbal Space Program Hovering PID Controller
import krpc, time, math
conn = krpc.connect(name = "PID Hover")
vessel = conn.space_center.active_vessel
# Find the craft height (altitude from command module and bottom of craft are different)
bbox = vessel.bounding_box(vessel.reference_frame)
HEIGHT = max(abs(bbox[0][1]), abs(bbox[1][1]))
print("Now controlling '" + vessel.name + "'")
@zesterer
zesterer / coord.rs
Created July 16, 2018 08:27
A few tests for coord
#![allow(unused_imports)]
#![allow(dead_code)]
extern crate core;
use core::ops::{
Add, Sub, Mul, Div,
AddAssign, SubAssign, MulAssign, DivAssign,
};
use core::fmt;
@zesterer
zesterer / bf.c
Last active July 29, 2018 17:36
Brainfuck Interpreter In C
// Run like: ./bf <myfile.bf>
#include<stdio.h>
main(int u,int**v){char t[1<<12]={0,},c[1<<16];int m=fread(c,1,1<<16,fopen(*++v,"r"));
char*p=t,n=0,x=0,*i=c;for(;i-c<m;){
*i==62?p++:*i==60?p--:*i==43?++*p:*i==45?--*p:*i==46?write(1,p,1):*i==44?read(0,p,1):0;
if((*i==91&&!*p)||(*i==93&&*p)){*p?n--:n++;for(;n;)*(*p?--i:++i)==91?n++:*i==93?n--:0;*p?0:i--;}i++;}}
@zesterer
zesterer / markov4.py
Created July 31, 2018 15:37
4th Order Markov Chain Generator
import random
by_word = True
text = open("test.txt").read().replace(" ", " ")
if by_word:
text = text.split(" ")
freq = {}
@zesterer
zesterer / procedural.c
Created July 31, 2018 16:18
C code, procedurally generated using a 4th-order Markov chain generator
///
/// This code is procedurally generated using the 4th-order Markov chain generator
///
/// Original training material: https://github.com/vurtun/nuklear/blob/master/nuklear.h
///
const struct nk_image s;
* a = (nk_byte) tmp[3];
}
NK_API void
struct Client {
jobs: Jobs,
depot: PostDepot,
}
impl Client {
fn new() -> Client {
Client { jobs: Jobs::new(), depot: PostDepot::new() }
}