Skip to content

Instantly share code, notes, and snippets.

@ollpu
ollpu / persistent.md
Last active June 20, 2023 19:50
App state persistence system for Rust

The idea

This document presents a system for persistent application state management that

  • is based on COW trees
  • allows the user to freely define the structs that become nodes in the tree
  • can be relatively ergonomically used to construct a kind of reactive GUI that depends on the data
  • supports mutations from an arbitrary point without needing lenses or other macro-heavy solutions.

Similar systems that rely on lenses already exist, e.g. the Druid architecture. They are used because mutations

@ollpu
ollpu / test2.py
Created October 11, 2019 12:32
Perspective matrix solver
#!/usr/bin/python3
import numpy as np
# Input
w, h = map(float, input("Framebuffer dimensions (W H): ").split())
point_human = ["top left", "top right", "bottom left", "bottom right"]
P = [list(map(float, input("Enter coordinates of {} point (x y): ".format(s)).split())) for s in point_human]
T = [(0, 0), (w, 0), (0, h), (w, h)]
# Compute
@ollpu
ollpu / tg_api.rb
Last active August 27, 2019 07:21
Lightweight Passive Telegram Bot API (Ruby)
require 'json'
require 'net/http'
module TgAPI
BOT_TOKEN = "[...]"
def self.api_do action, **params
uri = URI.parse "https://api.telegram.org/bot#{BOT_TOKEN}/#{action.to_s}"
response = Net::HTTP.post uri, params.to_json, "Content-Type" => "application/json"
unless response.is_a? Net::HTTPSuccess
m = JSON.parse(response.body)&.[]("description") rescue nil
@ollpu
ollpu / includeguard.vim
Last active April 26, 2019 14:54
VIM Include Guard Generator
func! IncludeGuard()
let l:h = tr(toupper(expand("%:t")), ".", "_")
call append(0, "#ifndef ".h)
call append(1, "#define ".h)
call append(2, "")
call append(line("$"), "")
call append(line("$"), "#endif")
endfunc
@ollpu
ollpu / gen.cpp
Last active October 19, 2017 15:37
Bare minimum C++ SDL tone generator
/* Compilation:
Requires libsdl2-dev
$ g++ --std=c++14 -lSDL2 -o gen gen.cpp
*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_audio.h>
#include <iostream>
#include <cmath>
@ollpu
ollpu / keybase.md
Created June 30, 2017 15:30
keybase.md

Keybase proof

I hereby claim:

  • I am ollpu on github.
  • I am ollpu (https://keybase.io/ollpu) on keybase.
  • I have a public key ASBeeRUHMXf1WmUgJpNDyvWa7TUTdwNHv94-ivKcFmfKoQo

To claim this, I am signing this object:

@ollpu
ollpu / arm.s
Last active June 6, 2017 21:04
ARM assembly mathematical expression evaluator (addition, subtraction, multiplication, brackets)
.data
output_format:
.asciz "%d\n"
.balign 4
.text
parse_number:
// while numeric, mul register by 10, add number
@ollpu
ollpu / generate.sh
Last active March 8, 2020 22:05
giffer - Make a compressed GIF from any video file
#!/bin/bash
# First parameter describes the input video file
mplayer -ao null "$1" -vo jpeg:outdir=output
convert output/* fuzz 10% -layers Optimize output.gif
rm -r ./output
@ollpu
ollpu / telegram_controller.rb
Last active October 30, 2017 15:35
Telegram Bot API in Rails
# Set ENV["TELEGRAM_BOT_API_KEY"] before usage!
# Use telegram#repair to connect to API
require "net/http"
require "uri"
include ActionView::Helpers::TextHelper
class TelegramController < ApplicationController
protect_from_forgery with: :null_session
@ollpu
ollpu / Arduino.ino
Created January 17, 2015 20:17
Processing > Arduino DMX Protocol
//DMX communication protocol for Processing ---> Arduino
//Made by Roope Salmi
void setup() {
Serial.begin(115200);
}
byte message[3];