Skip to content

Instantly share code, notes, and snippets.

@saolsen
saolsen / day02.rs
Created December 2, 2022 13:40
aoc 2022 day02
#[derive(Clone, Copy)]
enum Move {
Rock,
Paper,
Scissors
}
impl Move {
pub fn from(s: &str) -> Move{
use Move::*;
@saolsen
saolsen / day01.rs
Created December 1, 2022 12:01
aoc 2022 day01
fn main() {
let input = include_str!("day01_input.txt");
let mut elf_totals = vec![];
let mut total = 0;
for line in input.split('\n') {
if line == "" {
elf_totals.push(total);
total = 0;
} else {
@saolsen
saolsen / polar.h
Created September 7, 2021 14:02
polar include file for 0.20.0-beta
/**
* We use the convention of zero as an error term,
* since we also use `null_ptr()` to indicate an error.
* So for consistency, a zero term is an error in both cases.
*/
#define polar_POLAR_FAILURE 0
#define polar_POLAR_SUCCESS 1
typedef struct polar_Polar polar_Polar;
@saolsen
saolsen / .clang-format
Created October 7, 2020 17:59
clang format
BasedOnStyle: LLVM
IndentWidth: 4
@saolsen
saolsen / sudoku.c
Last active October 7, 2020 17:55
sudoku solver
#include <stdio.h>
#include <string.h>
typedef char Sudoku[9][9];
typedef struct {
Sudoku board;
int x;
int y;
char i;
} Choice;
@saolsen
saolsen / readme.md
Last active August 6, 2019 17:56
trying out structs in javascript

I've been thinking about trying to build something like terra but with javascript as the host language and wasm as the low level thing you metaprogram for. Could be used to just "jit" expensive functions and call them from javascript or to build a fully wasm program but metaprogram it from javascript or whatever inbetween. One of the things I think I need to get that to be nice is to be able to have a struct implementation that can be easily shared between wasm and js.

@saolsen
saolsen / program.c
Created June 6, 2019 16:11
grow_memory in wasm from c
include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <webassembly.h>
typedef uint8_t u8;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t i32;
@saolsen
saolsen / steve_lib.h
Last active March 17, 2018 23:48
steve_lib.h
// Collections and helpers for c programming.
// Version: 0.1.3
// Shoutouts to @nothings and @pervognsen who I learned / copied most of this from
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
@saolsen
saolsen / keybase.md
Created October 10, 2017 16:51
keybase.md

Keybase proof

I hereby claim:

  • I am saolsen on github.
  • I am saolsen (https://keybase.io/saolsen) on keybase.
  • I have a public key ASD9j8N4AtK0fUZlAh1XujYN4d4bSiK7GJ3_RQuP7_pj5wo

To claim this, I am signing this object:

@saolsen
saolsen / aissac.cpp
Created August 3, 2017 21:35
python screen capture
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define LEN(e) (sizeof(e)/sizeof(e[0]))