Skip to content

Instantly share code, notes, and snippets.

View lithdew's full-sized avatar

Kenta Iwasaki lithdew

View GitHub Profile
package flatend
import (
"encoding/json"
"strconv"
"testing"
"unsafe"
)
var _ json.Marshaler = (*SafePayload)(nil)
@lithdew
lithdew / example
Created May 19, 2020 11:37
flatlang: example script
(flatlang.Program) {
Stmts: ([]flatlang.Stmt) (len=10 cap=16) {
(flatlang.Stmt) {
Type: (flatlang.StmtType) Assign,
Name: (string) (len=2) "db",
Exprs: ([]flatlang.Expr) (len=1 cap=1) {
(flatlang.Expr) {
Nodes: ([]flatlang.Node) (len=1 cap=1) {
(flatlang.StringNode) {
Val: (string) (len=17) "sqlite://:memory:"
@lithdew
lithdew / main.go
Created May 27, 2020 11:19
Unescape strings in Go.
func unescape(s string) (string, error) {
if !strings.ContainsRune(s, '\\') && utf8.ValidString(s) {
return s, nil
}
tmp := make([]byte, utf8.UTFMax)
buf := make([]byte, 0, 3*len(s)/2)
for len(s) > 0 {
c, mb, t, err := strconv.UnquoteChar(s, '"')
if err != nil {
return "", err
@lithdew
lithdew / layout.go
Last active May 31, 2020 13:20
casso: Split a region up into vertically-aligned regions that meet a set of constraints.
package layout
import "github.com/lithdew/casso"
type Layout struct {
solver *casso.Solver
tags []casso.Symbol
err error
}
@lithdew
lithdew / client.zig
Created June 7, 2020 16:54
`zig-network` test.
const std = @import("std");
const net = @import("./zig-network/network.zig");
const PROTOCOL = net.Protocol.tcp;
pub fn main() !void {
var buf: [16384]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buf);
try net.init();
@lithdew
lithdew / main.go
Created June 11, 2020 16:13
Monte.
package main
import (
"encoding/hex"
"fmt"
"github.com/lithdew/monte"
"net"
)
func main() {
@lithdew
lithdew / main.zig
Last active July 18, 2020 09:53
(wip) zig tcp server
const std = @import("std");
const print = std.debug.print;
const File = std.fs.File;
const BufferedWriter = std.io.BufferedWriter;
const Address = std.net.Address;
const Server = std.net.StreamServer;
const Connection = std.net.StreamServer.Connection;
@lithdew
lithdew / main.zig
Created July 18, 2020 13:00
zig: linux exit signal
var frame: anyframe = undefined;
pub fn main() !void {
print("Before\n", .{});
const handler = struct {
fn impl(sig: i32, info: *std.os.siginfo_t, ucontext: ?*c_void) callconv(.C) void {
resume frame;
}
};
@lithdew
lithdew / main.zig
Last active July 18, 2020 22:15
zig: evented i/o stream server accept not returning an error (?)
const std = @import("std");
pub const io_mode = .evented;
var main_frame: ?*std.event.Loop.NextTickNode = undefined;
pub fn loop(server: *std.net.StreamServer) !void {
while (true) {
var conn = server.accept() catch |err| {
std.debug.print("Got loop error: {}\n", .{err});
@lithdew
lithdew / main.zig
Last active July 19, 2020 21:16
zig: listen for SIGINT (linux)
const std = @import("std");
const print = std.debug.print;
const assert = std.debug.assert;
pub const signalfd_siginfo = extern struct {
signo: u32,
errno: i32,
code: i32,
pid: u32,