Skip to content

Instantly share code, notes, and snippets.

View p7g's full-sized avatar

Patrick Gingras p7g

View GitHub Profile
@p7g
p7g / map.txt
Created December 14, 2022 17:24
0 .................+.....................................................................
1 ................ooo....................................................................
2 ...............ooooo...................................................................
3 ..............ooooooo..................................................................
4 .............ooooooooo.................................................................
5 ............ooooooooooo................................................................
6 ...........ooooooooooooo...............................................................
7 ..........ooooooooooooooo..............................................................
8 .........ooooooooooooooooo.............................................................
9 ........ooooooooooooooooooo............................................................
@p7g
p7g / README.md
Last active December 8, 2022 00:31
webrtc demo

how to use

You are the signalling server

  1. turn on camera on both (dunno if required)
  2. create a peer on both
  3. create offer on one, paste into "add remote session description form" and submit
  4. copy answer from previous step and paste into "add remote session description form" in other client, submit
  5. copy ice candidates array from each client and paste into "add ice candidate" on other, submit both
@p7g
p7g / bf.rkt
Last active October 31, 2022 02:18
bf interpreter in racket
#lang racket
(define (tape-new)
(cons 0 (make-vector 1 0)))
(define (tape-inc tape amount)
(let ([pos (car tape)]
[vec (cdr tape)])
(vector*-set! vec pos (+ (vector-ref vec pos) amount))))
@p7g
p7g / recompose.py
Created August 2, 2022 13:12
Python regular expressions that can be composed into bigger regular expressions
"""
This is a really basic and dumb regexp engine to play with composable regular
expressions.
A Re object is basically just a pointer to some initial state and to some
accepting state. These states can each point to other states, forming an NFA-ε,
which can then be evaluated directly.
The cool thing is that you can just combine Re objects like this:
import textwrap
from csnake import (
AddressOf,
CodeWriter,
Function,
TextModifier,
Variable,
)
@p7g
p7g / 0_bf.joe
Created February 12, 2022 16:13
Manually translated joe -> C, this BF implementations runs only 14% slower than bf.c
// vim: ft=java
import joe.collections.ArrayList;
import joe.fs.File;
import joe.io.StdOut;
import joe.io.StdErr;
class Tape {
final ArrayList<uint> data;
uint pos;
@p7g
p7g / lis.py
Last active February 7, 2022 21:06
i have invented the LISt Processor
import operator
nil = ()
def nilp(l):
return l == nil
def cons(a, b):
return a, b
@p7g
p7g / bf.c
Created February 1, 2022 04:36
My fastest BF interpreter so far, using dynamic dispatch in C
#include <stdlib.h>
#include <stdio.h>
struct tape {
unsigned pos, capacity;
unsigned char *data;
};
void tape_init(struct tape *t)
{
@p7g
p7g / getstructinfo.py
Created January 30, 2022 16:58
Ask clang what a struct looks like
"""Ask clang what a struct looks like
Structs like stat don't necessarily have the same fields in the same order on
different platforms. This makes writing a language with C FFI sound pretty
awful... since all the different platforms would need to be handled by the FFI
library of that language. Maybe with something like this, the C compiler could
be queried to find out what these structs look like?
"""
import io
@p7g
p7g / day19.rs
Last active December 19, 2021 22:19
use std::collections::BTreeSet;
type Point = [i64; 3];
type Rotation = [u8; 3];
#[derive(Debug)]
struct Orientation {
signs: [i8; 3],
rotation: Rotation,
}