Skip to content

Instantly share code, notes, and snippets.

@tkanerva
tkanerva / puzzle2.ex
Created December 21, 2023 20:02
aoc day 21
defmodule Foo do
@directions %{north: {0, -1}, south: {0, 1}, east: {1, 0}, west: {-1, 0}}
def sampletext() do
"""
...........
.....###.#.
.###.##..#.
..#.#...#..
@tkanerva
tkanerva / puzzle.ex
Created December 21, 2023 17:53
aoc 21
def allowed_step?(m, {x, y}) do
case m[{x, y}] do
:rock -> false
nil -> false
_ -> true
end
end
def get_next_steps({w,h,m} = map, {x0, y0} = curpos) do
use nohash_hasher::IntMap;
//use std::sync::{Arc, Mutex};
//use std::thread;
//use std::time::Instant;
//use once_cell::sync::Lazy;
//use once_cell::sync::OnceCell;
use std::cell::RefCell;
// our counters.
struct Counters {
@tkanerva
tkanerva / echoserv.ex
Created September 18, 2023 19:47
elixir echoserver
defmodule Echoserv do
@moduledoc """
Documentation for `Echoserv`.
"""
require Logger
@port 9999
def accept(port) do
@tkanerva
tkanerva / mand.go
Created August 29, 2022 20:23
gomand
package main
import (
"bufio"
"log"
"os"
//"fmt"
"unsafe"
)
@tkanerva
tkanerva / pykivi.py
Last active November 24, 2020 08:42
a small micro-benchmark for python3 interpreters.
import timeit
MAXITER, XDIM, YDIM = 500, 500, 500
def mand(c):
it, z = 0, 0+0j
while it < MAXITER:
z = z*z + c
if abs(z) > 4.0:
break
@tkanerva
tkanerva / dashd.service
Last active September 23, 2017 07:23
systemd files for running dashd / sentinel
[Unit]
Description=dashd
After=network.target
OnFailure=mynotify@%n
[Service]
User=topi
Group=topi
Type=forking
#!/usr/bin/python
# arg1 == path to devfile, like "/dev/bus/usb/bus_number/device_number"
import fcntl, sys, os
USBDEVFS_RESET = ord('U') << (4*2) | 20
def main():
fd = os.open(sys.argv[1], os.O_WRONLY)
if fd < 0: sys.exit(1)
fcntl.ioctl(fd, USBDEVFS_RESET, 0)
os.close(fd)
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
@tkanerva
tkanerva / iptables.txt
Created July 26, 2017 07:01
problem doing nat to enable wlan clients internet access
# Generated by iptables-save v1.6.0 on Wed Jul 26 07:00:26 2017
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Wed Jul 26 07:00:26 2017
# Generated by iptables-save v1.6.0 on Wed Jul 26 07:00:26 2017