Skip to content

Instantly share code, notes, and snippets.

@morgangallant
morgangallant / build.zig
Created January 9, 2024 21:39
build.zig file which automatically creates executables for all .main.zig files in src/
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// For every `.main.zig` file in src (recursive), we export an executable
// using it as the root source file. This means one Zig project can be used
// to build multiple end-executables (and they can all share code!).
{
@morgangallant
morgangallant / db_bench.zig
Created January 3, 2024 22:07
Script used to benchmark the Zig version of LevelDB
const std = @import("std");
const builtin = @import("builtin");
const db = @import("db.zig");
const options = @import("options.zig");
// Rough re-creation of LevelDB's db_bench program with our Zig port.
const usage =
\\db_bench [options]
\\
// June is a client library for the June analytics API.
package june
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"net/http"
@morgangallant
morgangallant / tsnet.go
Created October 5, 2022 08:00
Playing around with "tailscale.com/tsnet", it's cool!
/*
Usage of INET (Uses TSKEY environment variable)
...
if ips := inet.Wait(context.Background()); len(ips) > 0 {
log.Printf("connected to tailscale (ips=%v)", ips)
} else {
log.Printf("not connected to tailscale")
}
defer inet.Shutdown()
@morgangallant
morgangallant / iofswebsite.go
Last active March 17, 2021 21:08
An easy way to serve static websites via HTTP with new Go io/fs package.
package main
import (
"embed"
"errors"
"io/fs"
"log"
"net/http"
"strings"
)
@morgangallant
morgangallant / deploy.go
Created August 10, 2020 02:55
automatic self-updating of go binaries from scratch
// This is a seperate binary that you use when you are deploying your primary binary (main.go).
package main
import (
"fmt"
"log"
"operand/pkg/update"
"os/exec"
"github.com/pkg/errors"

Keybase proof

I hereby claim:

  • I am morgangallant on github.
  • I am morgangallant (https://keybase.io/morgangallant) on keybase.
  • I have a public key ASA187D7v0ytKEXDJKin8pc_Am_eko-iGcY5Uhz_ZLGsJQo

To claim this, I am signing this object:

#include <unordered_map>
// Checks if this node has been flattened yet.
bool is_flattened() const { return offset_ == -1; }
// New private member variables for Node class.
// Stores the module offset for flattening.
int offset_ = -1;
#include <iterator>
#include <sstream>
// Brute force naive solution.
std::optional<std::function<void()>> brute_force(
const std::string &msg) const {
// If this node is a leaf node, return the action.
if (action_ != std::nullopt) return action_;
// Tokenize the input string.
#include <iostream>
// Some test functions to show that implementation is working.
void buy_func_usd() { std::cout << "buy usd." << std::endl; }
void buy_func_cad() { std::cout << "buy cad." << std::endl; }
void sell_func_usd() { std::cout << "sell usd." << std::endl; }
void sell_func_cad() { std::cout << "sell cad." << std::endl; }
int main() {
// Buy Shares