Skip to content

Instantly share code, notes, and snippets.

View marvhus's full-sized avatar
🎯
Focusing

Martin marvhus

🎯
Focusing
View GitHub Profile
# write is for writing N newlines to a file.
# count is from counting the newlines in a file.
CC := gcc
CFLAGS := -Wall -Wextra -Werror \
-std=c11 -pedantic
TARGETS := count \
write

Ref

A small Jai library for making it easy to share pointers/references to the same data, while making it easy to get rid of the pointer/reference when it is no longer needed.

How to use

Creating a Ref variable

You just create a variable using with the Ref(T) type, where you replace T with your type. For example Ref(int).

Initializing

Then you initialize it with init(*ref_variable) where ref_variable is your variable,

@marvhus
marvhus / README.md
Last active April 23, 2024 18:51
Floating Point Precision in x86-64 Assembly

Floating Point Precision in x86-64 Assembly

The lack of precison you get with floating point numbers isn't a language problem, it's a problem with floating point nubers themselves, so it even shows up as low as x86-64 assembly.

The assembly in the file bellow is the code I have written to showcase this.

To compile it you have to do this:

$ nasm floats.asm -o floats.o -f elf64
@marvhus
marvhus / mu4e.md
Last active February 9, 2024 23:21 — forked from A6GibKm/mu4e.md
Read your emails with mu4e

Connecting emacs and Protonmail Bridge

This guide will cover the basics on how to integrate emacs with protonmail-bridge using

Configuring mbsync

@marvhus
marvhus / AoC_2023_day_09.hs
Created December 10, 2023 18:01
Day 9 of AoC 2023 in Haskell. No bullshit, just standard stuff.
getPairs :: [Int] -> [(Int, Int)]
getPairs [] = []
getPairs [_] = []
getPairs (x:y:xs) = (x,y) : getPairs (y:xs)
getDiff :: [(Int, Int)] -> [Int]
getDiff [] = []
getDiff ((x1, x2):xs) = (x2 - x1) : getDiff xs
generate :: [Int] -> [[Int]]
@marvhus
marvhus / .xinitrc
Created November 25, 2023 01:47
startx script for starting DWM and KDE
#!/usr/bin/bash
setxkbmap -option caps:ctrl_modifier no &
do_dwm ()
{
slstatus &
picom -b &
nitrogen --restore &
dunst -font "iosveka" &
@marvhus
marvhus / probe.rs
Created November 6, 2023 19:06
Encoder and Decoder for John Hammond's Snyk Rust challenge. https://www.youtube.com/watch?v=4ZFypGpGfAo
use std::fs;
const CHARSET: &[u8] = b"QWlKoxp3mT9EeRb4YzgG6rNj1OLvZ5SDfMBaXtP8JyIFVH07uh2wicdnUAC#@q";
fn encode(input: String) -> String {
let input_bytes = input.as_bytes();
let mut output = Vec::new();
let mut temp = 0u32;
let mut temp_len = 0u8;
@marvhus
marvhus / fizzbuzz.jai
Created September 12, 2023 15:13
FizzBuzz in Jai
fizzbuzz :: (low: u32, high: u32) {
_print :: (str: string) #expand {
print("%", str);
`already_printed = true;
}
for i: low..high {
already_printed := false;
if i % 3 == 0 then _print("Fizz");
if i % 5 == 0 then _print("Buzz");
if !already_printed then print("%", i);
@marvhus
marvhus / input.jai
Created September 9, 2023 12:15
Blocking Console Input in Jai.
main :: () {
print("What is your name?\n> ");
name := input();
print("Hello, %!\n", name);
}
#import "Basic";
#if OS == .LINUX {
#import "POSIX";
@marvhus
marvhus / jai_cloc.sh
Created August 19, 2023 21:47
Jai count lines of code
#!/bin/bash
# Small script to count lines in .jai files
# Cloc doesn't support jai, so I just made this for now
files=$(find $1 -name "*.jai")
if [ "$1" == "" ]; then
echo "No path"
exit 1
fi