Skip to content

Instantly share code, notes, and snippets.

@joncfoo
joncfoo / day01-1.awk
Last active December 22, 2022 23:06
advent of code 2022
#!/usr/bin/env awk -f
BEGIN { RS = ""; FS = "\n"; }
{
for (i=1; i<=NF; i++) {
sum += $i
}
if (sum > max) {
max = sum
@joncfoo
joncfoo / Cargo.toml
Created April 22, 2022 14:04
Auto-reloading server
[package]
name = "example"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4.0"
anyhow = { version = "1.0", features = ["backtrace"] }
listenfd = "0.5"
log = "0.4"
@joncfoo
joncfoo / solutions.md
Last active March 17, 2022 00:13
project euler

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

   +/ (+./ 0 = 3 5 |/ i. 1000) # i. 1000
233168
@joncfoo
joncfoo / main.go
Last active November 7, 2020 16:05
Peer Credentials from Unix Domain Socket
// Unix Domain Socket Peer Credentials
//
// This program demonstrates setting up a HTTP server over a Unix Domain Socket
// and subsequently obtaining connecting clients credentials. The credentials
// contain the User ID, Group ID, and Process ID of the incoming connection (as
// connections are made by some local system user as opposed to a network
// connection).
//
// This has interesting use cases around local process security. For example,
// a server listening on a Unix Domain Socket can choose to allow or reject
let print_row row =
Array.map print_char row |> ignore;
print_newline ()
let rule n = function
| ('_', '_', '_') -> if n land 0b00000001 = 0 then '_' else '*'
| ('_', '_', '*') -> if n land 0b00000010 = 0 then '_' else '*'
| ('_', '*', '_') -> if n land 0b00000100 = 0 then '_' else '*'
| ('_', '*', '*') -> if n land 0b00001000 = 0 then '_' else '*'