Skip to content

Instantly share code, notes, and snippets.

View cablehead's full-sized avatar

Andy Gayton cablehead

View GitHub Profile
@cablehead
cablehead / main.go
Created April 18, 2021 21:38
cli to merge / split stdio over a network
package main
import (
"bufio"
"fmt"
"net"
"os"
"sync"
"github.com/alexflint/go-arg"
@cablehead
cablehead / prefix.zig
Created April 17, 2021 20:49
std io with zig
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();
const a = std.testing.allocator;
var buf = std.ArrayList(u8).init(a);
defer buf.deinit();
@cablehead
cablehead / cgi2json.py
Created December 22, 2020 06:09
Experimenting with processing http requests with jq + shell2http
#!/usr/local/bin/python3
import json
import sys
import os
fh = open("/tmp/out", "a")
env = dict(os.environ)
skip = ['HOME', 'TMPDIR', 'USER', 'LANG', 'PATH', 'PWD', 'SHLVL', 'SCRIPT_NAME' ]
@cablehead
cablehead / aqi.py
Created September 29, 2020 07:27
Push data from specific PurpleAir sensors to an Apple Watch complication with Pushover
import requests
import json
from datetime import timedelta
from datetime import datetime
def calcAQI(Cp, Ih, Il, BPh, BPl):
a = (Ih - Il)
b = (BPh - BPl)
@cablehead
cablehead / 01-small-tools-everywhere.md
Last active March 1, 2024 15:11
small tools everywhere

What would it look like if we just used small tools, everywhere?

Original revision: Sep 6, 2018

Most developers are familiar and proponents of the Unix Philosophy Unix philosophy - Wikipedia particularly, Write programs that do one thing and do it well. In practice though, the tooling just doesn’t exist to build useful network services which follow this approach.

Let’s take a lightweight WebSocket service. In 2018 we’ve no shortage of languages and frameworks - however largely incompatible with each other, to create the service.

I’m most familiar with the Python world so can break out the different frameworks in that world that you could use: twisted, eventlet, gevent, tornado, asyncio, sanic - and even though these use the same base language, using libraries designed to be used with one of these frameworks would likely be difficult to use with another framework. And then there are also a myriad of options with Java, Golang, Erlang, Rust.

@cablehead
cablehead / jq-to-env.sh
Created August 30, 2018 23:58
set a shell's environment to the key / value pairs in a JSON mapping
$ jo foo=bar | \
jq -r 'to_entries | map("\(.key)=\(.value | @sh)") | join(" ")'| \
while read -r line ; do
eval "$line"
echo $foo
done
bar
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
local r, w = h.io:pipe()
h:spawn(function()
w:write(("X"):rep(16*1024*1024))
w:close()
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
local r, w = h.io:pipe()
h:spawn(function()
for i = 1, 1000 do
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
local r, w = h.io:pipe()
h:spawn(function()
for i = 1, 1000 do
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
local r, w = h.io:pipe()
h:spawn(function()
for i = 1, 1000 do