Skip to content

Instantly share code, notes, and snippets.

View thecoder08's full-sized avatar

Lennon McLean thecoder08

View GitHub Profile
@thecoder08
thecoder08 / ball.asm
Created June 4, 2024 03:34
x86-64 assembly bouncing ball demo using libxgfx
; x86_64 assembly libxgfx bouncing ball demo
; assemble with: nasm -f elf64 ball.asm
; link with: ld ball.o -lxgfx --dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ball (needs libxgfx installed)
; run with: ./ball
global _start
extern initWindow
extern clear
extern circle
extern updateWindow
@thecoder08
thecoder08 / hello.asm
Created January 23, 2024 02:14
Minimal hello world, Linux x86_64.
; compile with:
; nasm -felf64 hello.asm
; ld hello.o -o hello
; strip hello
global _start
section .text
_start:
mov rax, 1 ; write(
mov rdi, 1 ; stdout,
@thecoder08
thecoder08 / sdl-drivers.c
Created January 23, 2024 02:10
List SDL2 video and audio drivers.
#include <SDL2/SDL.h>
#include <stdio.h>
int main() {
puts("Available video drivers:");
int numVideoDrivers = SDL_GetNumVideoDrivers();
for (int i = 0; i < numVideoDrivers; i++) {
puts(SDL_GetVideoDriver(i));
}
@thecoder08
thecoder08 / hello.asm
Created December 12, 2023 22:48
Hello World in relocatable assembly
; A program in x86_64 assembly that uses the shared library version of libc and prints Hello World!
; assemble: nasm -f elf64 hello.asm
; link: ld hello.o /lib/x86_64-linux-gnu/Scrt1.o --dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc -o hello
; run: ./hello
global main
extern puts
section .text
main:
push rbp
mov rbp, rsp
@thecoder08
thecoder08 / bezier.c
Created June 20, 2023 21:54
Display a bezier curve using xgfx
#include <xgfx/window.h>
#include <xgfx/drawing.h>
typedef struct {
int x;
int y;
} Point;
Point lerp(Point a, Point b, float t) {
Point c;
@thecoder08
thecoder08 / ocgp.md
Created February 14, 2022 01:32
OCGP

The Open Console Gaming Platform v1.0

The Open Console Gaming Platform (OCGP) is a specification for and family of game consoles running Free and Open Source Software (FOSS) that allows software written for one of them to work on any other.

Software specification

The OCGP defines certain software requirements that make a console OCGP-compliant. These include a kernel specification, as well as a graphics specification.

Kernel

OCGP-compliant consoles must run Linux version 5.0 or greater, or a compatible kernel. This ensures that system calls on one system are fully compatible with any other.

Graphics

OCGP systems must have a graphics system capable of displaying 1920x1080p images at 60fps. 3D acceleration capabilities are recommended, but not explicitly required.

Hardware specification

The OCGP also defines hardware requirements that make a console OCGP-compliant. This includes system architecture and I/O devices.

#!/usr/bin/env node
var net = require('net');
var clientNumber = 0;
net.createServer(function(client) {
var myNumber = clientNumber;
clientNumber++;
var server = net.connect(6667);
server.on('end', function() {
client.destroy();
});
@thecoder08
thecoder08 / print
Created November 24, 2021 03:04
a Linux utility for printing to text-only printers
#!/usr/bin/env node
// print: a Linux utility for printing to text-only printers
// to use it: Install node.js in the $PATH, download this script and save it as /usr/local/bin/print, and run chmod +x /usr/local/bin/print
var cp = require('child_process');
var fs = require('fs');
var net = require('net');
var unamea = '';
cp.exec('uname -a', function(err, stdout, stderr) {
unamea = stdout.toString().split('\n')[0];
@thecoder08
thecoder08 / collatz.html
Created November 3, 2021 22:27
The collatz conjecture, graphed
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Collatz Conjecture</title>
</head>
<body>
<canvas id="canvas" width="500" height="500" style="border: 1px solid black;"></canvas>
<input type="range" id="initialVal" value="7" min="1" max="100"><span id="valueDisplay"></span>
<script>
// passwd.js: use passwd-linux to check if a given user's password is correct. enter the plaintext username and password, and see whether the password was correct or not. NOTE: must be run as root in order to get access to /etc/shadow. Does not work on macOS as it doesn't use /etc/shadow.
var passwd = require('passwd-linux');
passwd.checkPassword('username', 'password', function(err, response) {
if (err) {
console.log(err);
}
else {
if (response) {