Skip to content

Instantly share code, notes, and snippets.

View marvhus's full-sized avatar
🎯
Focusing

Martin marvhus

🎯
Focusing
View GitHub Profile
@marvhus
marvhus / sample.md
Created August 6, 2020 09:05 — forked from bradtraversy/sample.md
Markdown Cheat Sheet

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

This text is italic

@marvhus
marvhus / types.h
Last active March 28, 2023 10:46
C header file for some typedef stuff.
/*
types.h - a header file for Rust/Jai like types in C.
Copyright (C) 2023 marvhus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@marvhus
marvhus / python-coroutines-dynamic.py
Last active May 16, 2023 23:11
Python Coroutines
class Coroutine: # I JUST WANT STRUCTS, BUT THIS LANGUAGE WONT LET ME
def __init__(self, start, end, name):
self.iterator = Coroutine.coroutine(start, end, name)
self.is_done = False
def next(self):
if not self.is_done:
self.is_done = next(self.iterator)
return self.is_done
#!/usr/bin/jai
#import "Basic";
Rule :: struct {
num: u32;
str: string;
}
fizzbuzz :: (rules: [] Rule, max: u32) {
msg: String_Builder;
COUNT :: 1_000_000;
arr : [COUNT] bool;
sieve :: () {
// Computer primes using sieve of Eratosthenes
for 1..arr.count-1 { arr[it] = true; }
arr[1] = false;
for idx: 2..(COUNT / 2) - 1 {
j := 2 * idx;
while j < COUNT {
arr[j] = false;
@marvhus
marvhus / u8_to_string.jai
Created August 19, 2023 21:40
Jai u8 to string
u8_to_string :: (c: u8) -> string {
buff: String_Builder;
init_string_builder(*buff);
append(*buff, c);
return builder_to_string(*buff);
}
u8_to_string :: (cs: []u8) -> string {
buff: String_Builder;
init_string_builder(*buff);
for c: cs {
@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
@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 / 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 / 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;