Skip to content

Instantly share code, notes, and snippets.

View charles-l's full-sized avatar
👾
making games

Charles charles-l

👾
making games
View GitHub Profile
@charles-l
charles-l / send_data_through_pipe.c
Last active April 30, 2016 00:58
Simple C program to send data through one end of a pipe, to a command, then read it back in.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// p pp
// (input - sent to first pipe) | tr a b | (output - read back in)
int main (void) {
int p[2];
@charles-l
charles-l / main.lua
Last active October 29, 2016 18:57
End of tutorial 1 for the polished platformer series
bump = require 'bump'
local world = bump.newWorld()
local level = {elems = {}}
function level:addElem(x, y, w, h, drawLambda)
local t = {draw = drawLambda}
world:add(t, x, y, w, h)
table.insert(self.elems, t)
@charles-l
charles-l / notifyd.c
Last active November 2, 2016 21:27
a simple notification service demo
// a simple notification daemon that sits on a fifo and calls a popup commend when new lines appear
// to use:
// cc -o notifyd notifyd.c
// ./notifyd
// <in a different terminal>
// echo 'a wild notification appears!' > /etc/notidsock
// <bask in the glory of a simple notification service that's less than 100 lines of code>
#include <stdio.h>
#include <unistd.h>
@charles-l
charles-l / meta.scm
Last active November 10, 2023 17:15
metacircular evaluator from sicp
;; metacircular evaluator from sicp
(define apply-in-underlying-scheme apply)
(define (list-of-values exps env)
(if (no-operands? exps)
'()
(cons (eval (first-operand exps) env)
(list-of-values (rest-operands exps) env))))
(define (eval-if exp env)
(if (true? (eval (if-predicate exp) env))
@charles-l
charles-l / llvm_writeup.md
Last active January 11, 2021 00:40
LLVM GSoC Writeup

GSoC 2017 Project

This summer, I worked on adding more attributes to ThinLTO's index to allow for more optimizations.

Background

LTO (Link-time optimization) combines the bitcode of every module in a project into a monolithic bitcode file during linking, so IPO (interprocedural optimizations) can be applied throughout a whole program. This improves the quality and the speed of the executables generated. However, LTO consumes a large amount of memory, so it isn't viable on many larger C/C++ codebases.

ThinLTO addresses this problem by introducing a light-weight in-memory index, that tracks attributes for relevant global values in a program. The index can be used to propagate information across a whole program, import and internalize functions, and apply whole program optimizations without having to store all the bitcode in memory.

@charles-l
charles-l / fretboard.rkt
Created January 7, 2018 14:44
Quick script to draw SVG fretboards. For yak-shaving purposes.
#lang racket
(require racket/draw)
(define string-dist 15)
(define fret-dist 20)
(define strings 6)
(define (draw-gstring dc frets x h)
def kalman_predict(x_hat, u, P, wheel_slip_std):
# non-linear state transition
def f(p, u):
x, y, θ = p
dΦ_l, dΦ_r = u
return v(
x + (((WHEEL_R * dΦ_l) / 2) +
((WHEEL_R * dΦ_r) / 2)) * DT * cos(θ),
y + (((WHEEL_R * dΦ_l) / 2) +
((WHEEL_R * dΦ_r) / 2)) * DT * sin(θ),
@charles-l
charles-l / kalmanfilter.ijs
Created May 13, 2018 19:51
Kalman filter implementation in the J Language
NB. Port of https://scipy-cookbook.readthedocs.io/items/KalmanFiltering.html
require 'stats/distribs/normal'
n =: 50 NB. number of steps to compute
x =: _0.37227 NB. real value
z =: (x , 0.1) rnorm n NB. readings (normal distribution)
Q =: 1e_5 NB. process variance
R =: 0.1^2 NB. estimate of variance
@charles-l
charles-l / Makefile
Last active January 10, 2019 03:16
c++ compile times
FILES=$(wildcard *.cpp)
NJOBS=$(shell echo $$(nproc) + 1 | bc)
all:
g++ $(FILES)
generate_empty:
echo "int main() {}" > main.cpp
for i in `seq 500`; do touch f$$i.cpp; done
from typing import Callable, Any
from dataclasses import dataclass
class _CpsA: # (x, k) -> ()
@staticmethod
def lift(f) -> '_CpsA':
return _CpsA(lambda x, k: k(f(x)))
def __init__(self, cps: Callable[[Any, Callable], None]):
self.cps = cps