Skip to content

Instantly share code, notes, and snippets.

View avesus's full-sized avatar
🎯
Focusing

Brian Cannard avesus

🎯
Focusing
View GitHub Profile
@avesus
avesus / machine.js
Last active January 4, 2020 21:53
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@avesus
avesus / experiment.js
Last active December 8, 2019 18:15
Experimental Statechart
const deviceMachine = Machine({
id: 'device',
initial: 'powered_off',
states: {
powered_on: {
type: 'parallel',
on: {
@avesus
avesus / bit_bit_jump.cpp
Created November 19, 2019 15:08
BitBitJump interpreter in 12 bit RAM
# include <stdio.h>
bool memory[12] = {
0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0,
// 0 1 0 1 0 1 0 1 0 1 0 1
// 0 0 1 1 0 0 1 1 0 0 1 1
// 0 0 0 0 1 1 1 1 0 0 0 0
// 0 0 0 0 0 0 0 0 1 1 1 1
};
bool current_instruction[12] = { 0 };
@avesus
avesus / fold.txt
Created September 9, 2019 22:23
Fold
https://en.wikipedia.org/wiki/Fold_(higher-order_function)#Folds_as_structural_transformations
@avesus
avesus / the-best-string-ever.cpp
Created January 18, 2019 21:52
The Best String Ever
class TuffString {
public:
template <typename T, size_t Size>
TuffString (const T (&ptr) [Size]) : ptr(ptr), len(Size - 1) {
// _dev_logA("Pre-computed length\n");
}
TuffString (const void* pString) : ptr((const char*)pString) {
@avesus
avesus / lz77.cpp
Last active August 10, 2018 17:24
"Vanilla" LZ77
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
unsigned int countBits(unsigned int number)
{
return (int)log2(number) + 1;
}
@avesus
avesus / wasm-compile.sh
Last active May 18, 2018 20:36
Complete WASM compilation
~/wasmllvm/bin/clang++ -emit-llvm -fno-builtin -fshort-wchar --compile --sysroot=/root/wasmsysroot/ --target=wasm32-unknown-unknown-wasm client/main.cpp --optimize=3 -o client/app.bc && ~/wasmllvm/bin/llc -mtriple=wasm32-unknown-unknown-elf -filetype=asm -asm-verbose=false -o client/app.s client/app.bc && ~/binaryen/s2wasm client/app.s > client/app.wat && ~/wabt/wat2wasm client/app.wat -o client/app.wasm
@avesus
avesus / stylus-detection-methods.js
Last active January 26, 2021 08:23
Stylus Detection
// Apple:
var body = document.getElementByTagName('body')
body.addEventListener('touchstart', function(evt){
// should be either "stylus" or "direct"
console.log(evt.touches[0].touchType)
})
// Chrome & Edge:
if (window.PointerEvent) {
// Pointer events are supported.
@avesus
avesus / bashrc
Created December 12, 2017 02:13
SpectrWM XTerm Background Color Change on Focus
finish() {
rm ${HOME}/.xterm-bash/$PPID
}
trap finish EXIT
echo -en $$ > ${HOME}/.xterm-bash/$PPID
@avesus
avesus / nginx.conf
Last active December 1, 2017 05:55
Nginx perfect nodern SPA config
location /app/ {
expires max;
}
location /img/ {
expires max;
}
location = /favicon.ico {
try_files $uri =204;