Skip to content

Instantly share code, notes, and snippets.

@RaphGL
RaphGL / install_odin.sh
Created March 4, 2024 20:24
Install Odin compiler and LSP
#!/bin/env sh
USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
# where to put the odin repos
REPO_DIR=${USER_HOME}/Documents
if [ "$EUID" -ne 0 ];
then echo "Please run as root"
exit
fi
@RaphGL
RaphGL / textbuffer.odin
Last active December 29, 2023 15:26
Bug printing textbuffer window with ncurses
package main
import "core:c"
import "core:fmt"
import "core:os"
import "core:slice"
import "core:strings"
import nc "ncurses/src"
TextBuffer :: struct {
@RaphGL
RaphGL / static_array_indices.md
Last active November 13, 2023 15:57
Static array indices in Modern C

Static Indices

C99 adds static indices letting you preserve size information for array parameters. This means that there's a guarantee that an array will never be null and has to have at least the specified number of items instead of just decaying into pointer.

So say we have this function signature:

void print_msg(char msg[10]);

You could call it this way:

@RaphGL
RaphGL / rle.c
Created September 20, 2023 15:14
Run-length encoding written in C11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
size_t times;
char chr;
} RLEChar;
// Run length Encoding
@RaphGL
RaphGL / sorting.js
Last active September 20, 2023 19:43
Sorting Algorithms in JavaScript
function bubbleSort(myArr) {
for (let j = myArr.length - 1; j > 0; j--) {
let biggest = myArr[j];
for (let i = 0; i < j; i++) {
const item1 = myArr[i];
const item2 = myArr[i + 1];
if (item1 > item2) {
myArr[i] = item2;
myArr[i + 1] = item1;
@RaphGL
RaphGL / FlappyBird.ch8
Created June 22, 2023 12:26
Flappy Bird for the Chip8. It uses Wernsey's Chip8 assembler: https://github.com/wernsey/chip8
define x v0
define y v1
define tube_x v2
define tube_y v3
define px v4
define py v5
define k_flap v6
define score v7
define x2 v8
define arg1 va
@RaphGL
RaphGL / portscanner.c
Created April 18, 2023 15:51
Very basic port scanner
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#define MAXPORTNUM 65535
int main(int argc, char **argv) {
if (argc < 2) {
@RaphGL
RaphGL / eventloop.go
Last active September 19, 2023 17:51
Event handling from scratch
package main
import "fmt"
type EventHandler struct {
// all events available on the system
validEvents []string
// a were an event string contains all of it's associated functions to be run
subscribers map[string][]func(s string)
// a queue of all raised events to be processed
@RaphGL
RaphGL / main.go
Last active September 20, 2023 18:50
Rust's API for error handling in Go
package main
import (
"github.com/raphgl/rufero"
"errors"
)
func returnError() rufero.Result[string] {
return rufero.NewResult("", errors.New("this should fail"))
}
const std = @import("std");
const allocator = std.heap.page_allocator;
pub fn LinkedList(comptime T: type) type {
return struct {
const AllocatorError = std.mem.Allocator.Error;
const Self = @This();
data: T,
next: ?*Self = null,