Skip to content

Instantly share code, notes, and snippets.

@ohAitch
ohAitch / the_good_rust.rs
Created October 30, 2020 23:08 — forked from iximeow/the_good_rust.rs
monkeypatching in rust
trait Person {
fn greeting(&self) -> StateOfMind;
fn name(&self) -> &'static str;
}
struct Ixi { }
struct Katie { }
#[derive(Debug)]
enum StateOfMind {
@ohAitch
ohAitch / vlist.rs
Last active October 30, 2020 07:26
Kinda in the middle of figuring out the Either<Index,u32> aspect of the data representation
#![feature(const_panic)]
#![feature(const_in_array_repeat_expressions)]
#![feature(array_map)]
#![feature(untagged_unions,min_const_generics)]
use std::convert::{TryInto,TryFrom};
use std::mem;
use core::fmt;
use core::fmt::{Debug};
// Adapted from https://fabiensanglard.net/rayTracing_back_of_business_card/
#include <stdlib.h> // card > aek.ppm
#include <stdio.h>
#include <math.h>
#include <time.h>
typedef int i;typedef float f;struct v{
f x,y,z;v operator+(v r){return v(x+r.x
,y+r.y,z+r.z);}v operator*(v r){return
v(x*r.x,y*r.y,z*r.z);}v operator*(f r){return
v(x*r,y*r,z*r);}f operator%(v r){return
@ohAitch
ohAitch / bars.ls
Created March 6, 2020 22:22
Playing around with osc
#!/usr/bin/env lsc
{stdin, stdout} = process
stdout.write "\x1b[?25l"
stdin.on \data -> stdout.write "\x1b[?25h"; process.exit 0
require! \osc-js
a = new oscJs plugin:new osc-js.DatagramPlugin
a.open port:2222 host:0
v = -> "█"*(it*8) + " ▏▎▍▌▋▊▉█"[0.^.(it*64%8)]
n=1
a.on "*" ({address:[...,a], args:[h]}) ->
@ohAitch
ohAitch / indent-explicit.es6
Created June 17, 2018 20:26
Small sketch of a bijection that renders indents explicit
/*
- `»` and `«` to delimit indent/outdent tokens
- two text areas side by side, one with »«, one without
- edits to indent editor update the brackets, edits to bracket editor update indents in both to match brackets
*/
mnt = document.body.querySelector('div')
mnt && mnt.remove()
document.body.appendChild(mnt = document.createElement('div'))
out.innerText=''; (new Date)+"\n"+document.body.outerHTML
mnt.innerHTML = `
@ohAitch
ohAitch / backstep-roundtrip.ls
Created June 7, 2018 17:13
Roundtrip backstep indentation to s-expr json to text formatter, under http://fiddle.jshell.net/uHL8r/26/show/light/
ind = ->
out = []
for line in it / \\n
# line.replace /[^\s]+( [^\s]+)*/g (w,_,at)->
line.replace /[^\s]+/g (w,at)-> # actually just iterate
out.push [at,w]
#
out
ren = ->
cur = 0
@ohAitch
ohAitch / code.js
Last active June 5, 2018 18:27
Wast bootstrap under data:text/html,<textarea%20onkeyup="out.innerText=eval(this.value)"></textarea><pre%20id=out>
/*
- panes: input | compiler | wast | runtime | output
TODO
- snapshot button that saves json of [date input compiler runtime] to localStorage
- timestamp buttons to cycle through old versions - also sth with diffs?
- <details> on "foo =\n", w/ collapse back if backspace on beginning
*/
document.body.querySelector('script') || document.body.appendChild(
document.createRange().createContextualFragment(
'<script src=https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/libwabt.js>'
@ohAitch
ohAitch / index.html
Last active January 28, 2018 15:36
"IDE"
<body>
<script src="https://code.jquery.com/jquery.js"></script>
<pre id="boot" contenteditable style="background:#eea">inp.onkeyup = inp.onfocus = () =&gt; {
var a
try{ a = eval(inp.innerText)} catch(_a){ a = _a}
res.innerText = a
}</pre>
<pre id="inp" contenteditable style="background:#bdb">
@ohAitch
ohAitch / deco-extracted.md
Created April 7, 2017 20:42
Further rendering of deco-inverted

this is a sample file designed to set conventions for high-quality conventional hoon.

all lines must be under 80 characters. no blank lines. any line longer than 60 characters is probably too long. uppercase or non-ascii letters are strongly discouraged.

informal comments (lines with ::) should be used only for meta-discussion about the code.

@ohAitch
ohAitch / deco-inverted.md
Created April 7, 2017 20:41
Actually literate gen/deco.hoon

this is a sample file designed to set conventions for high-quality conventional hoon.

all lines must be under 80 characters. no blank lines. any line longer than 60 characters is probably too long. uppercase or non-ascii letters are strongly discouraged.

informal comments (lines with ::) should be used only for meta-discussion about the code.