Skip to content

Instantly share code, notes, and snippets.

View geon's full-sized avatar

Victor Widell geon

View GitHub Profile
@geon
geon / signal.zig
Created June 18, 2024 18:51
Experiment with sending messages between theads.
const std = @import("std");
fn Signal(comptime T: type) type {
return struct {
message: T,
readyToRecieveMessage: std.Thread.Semaphore,
messageHasBeenSet: std.Thread.Semaphore,
const Self = @This();
@geon
geon / recursive-iterator.zig
Last active June 18, 2024 09:53
Implementing simple recursion as an iterator in Zig 0.11.0.
const std = @import("std");
const Buffer = std.ArrayList(u8);
const source = [_]u8{ 1, 2, 3, 4, 5 };
const expectedOrder = [_]u8{ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 };
fn recursive(read: []const u8, write: *Buffer) !void {
if (read.len > 0) {
try write.append(read[0]);
@geon
geon / Main.asm
Created August 1, 2021 20:47
Modified version of the interrupt handling in https://www.youtube.com/watch?v=LpG9gqPtNLo
; 10 SYS (4096)
*=$0801
BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $30, $39, $36, $29, $00, $00, $00
*=$1000
start
@geon
geon / async-iterator-server.ts
Created November 30, 2018 08:47
How to build a socket server with async and for-await.
import { createServer, Socket } from "net";
// Promisified socket.write().
const write = (socket: Socket, data: Buffer | string) =>
new Promise((resolve, reject) =>
socket.write(data as Buffer, (error: Error | undefined) => {
if (error) {
reject();
} else {
resolve();
@geon
geon / tsbug.ts
Last active November 20, 2017 14:50
console.log(myFunction());
const myConstant = "";
function myFunction(myArgument: string = myConstant): string {
return myArgument;
}
@geon
geon / demo.sql
Created June 1, 2017 12:37
pipelinedb event clustering
-- DROP SCHEMA public CASCADE;
-- CREATE SCHEMA public;
-- The bad measurements that should be clustered into errors.
CREATE STREAM bad_measurements ("measurement" REAL, "timestamp" TIMESTAMPTZ);
-- This is only useful because it create an output stream of deltas, important for clustering events.
@geon
geon / keyof.ts
Created December 8, 2016 12:13
Typed Backbone-style models with `keyof` in Typescript 2.1
class Model<T> {
props: T;
constructor(initial: T | void){
if (initial) {
this.props = initial;
}
}
set<K extends keyof T>(propName: K, value: T[K]) {
this.props[propName] = value;
@geon
geon / index.jade
Created February 5, 2016 21:46
Flexbox full-page web app layout with scrollable panels.
.full-screen.column
.header Header
.main.stretchy
.left Menu-stuff here
ul
li Menu Entry
li Menu Entry
li Menu Entry
li Menu Entry
li Menu Entry
@geon
geon / gist:e8b9e1125325e39c58b9
Created October 5, 2015 09:28
PipelineDB example
Data:
{"type":"add","uuid":"4b24edb2-5074-4a3a-95cb-927d5535da7c","topic":"clients","data":{"time":"2015-03-23T15:45:34.995Z"}}
{"type":"add","uuid":"26ff7bdb-9913-47ab-a6df-8c985320c1bb","topic":"clients","data":{"time":"2015-03-23T15:45:36.082Z"}}
{"type":"add","uuid":"914096b8-dc66-4239-bb1c-88baba0c1831","topic":"lines","data":{"time":"2015-03-23T15:45:40.323Z","clientId":"26ff7bdb-9913-47ab-a6df-8c985320c1bb","line":"Hello?"}}
{"type":"add","uuid":"bdb60b1e-b34b-490e-a737-0ceb81208f4e","topic":"lines","data":{"time":"2015-03-23T15:45:44.935Z","clientId":"4b24edb2-5074-4a3a-95cb-927d5535da7c","line":"What?"}}
{"type":"del","uuid":"4b24edb2-5074-4a3a-95cb-927d5535da7c","topic":"clients"}
{"type":"add","uuid":"f9aacc7e-1745-4a54-8e54-b9bea3cbc3bb","topic":"clients","data":{"time":"2015-03-23T15:45:59.800Z"}}
{"type":"add","uuid":"2c45cca3-cfa5-4ac2-bfec-12ca985d869b","topic":"lines","data":{"time":"2015-03-23T15:46:15.624Z","clientId":"f9aacc7e-1745-4a54-8e54-b9bea3cbc3bb","line":"Works finw"}}
{"type":"ad
@geon
geon / demo.sh
Created October 1, 2015 06:09
Command line tool to extract values from a JSON file.
echo '{"foo1":123, "foo":{"bar":[1,2,3]}}' | ./json.js foo.bar.2