Skip to content

Instantly share code, notes, and snippets.

View dannas's full-sized avatar

Daniel Näslund dannas

View GitHub Profile
@dannas
dannas / ports_adapters.md
Created September 16, 2023 18:30
Snippet from my notes on Functional core, imperative shell

Gary Bernhart made the concept popular with his screencast Functional core, Imperative shell. The idea is to let the code that uses side effects call into purely functional code. It's an extension of [[Architecture software Sans IO]]. Andy Matuschak expands on Gary's ideas in the presentation Controlling complexity.

I think I've seen an article where Joe Armstrong used the same construct but I'm unable to find it now. In https://www.destroyallsoftware.com/talks/boundaries, Gary makes the claim that Erlang's actors are built around functional cores, but that sending messages is imperative.

The ports and adapters pattern is the same idea dressed in different wording and not taken to such extremes. https://embeddeduse.com/2023/08/24/ports-and-adapters-architecture-the-pattern/

Marin Haverbeke claims that he's used the functional core, imperative sh

@dannas
dannas / backtrace
Last active June 2, 2022 12:26
sc18im700 hung task
[ 24.661114] ftdi_sio ttyUSB8: FTDI USB Serial Device converter now disconnected from ttyUSB8
[ 24.661212] ftdi_sio 1-1.2.4:1.0: device disconnected
[ 24.661901] ftdi_sio ttyUSB9: FTDI USB Serial Device converter now disconnected from ttyUSB9
[ 24.661972] ftdi_sio 1-1.2.4:1.1: device disconnected
[ 24.878017] sc18im700: i2c read timed out - gpio_get_all()
[ 243.695663] INFO: task kworker/0:2:495 blocked for more than 120 seconds.
[ 243.708006] Tainted: G C O 4.19.71 #1
[ 243.713310] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[ 243.721156] kworker/0:2 D 0 495 2 0x00000000
[ 243.721184] Workqueue: usb_hub_wq hub_event
@dannas
dannas / gist:cf01ba5687d3ed4d00baa84661c33f26
Created January 20, 2022 20:23
Mubes changes to SiglentSCPIOscilloscope.cpp
/***********************************************************************************************************************
* *
* libscopehal v0.1 *
* *
* Copyright (c) 2012-2021 Andrew D. Zonenberg and contributors *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met:
@dannas
dannas / siglent_scpi.py
Last active January 4, 2022 18:38
WIP Siglent SCPI experiments
# Very much WIP for experimenting with SDS1104X-E/SDS2104X-E scopes SCPI
# interface
import pyvisa as visa
from pyvisa.resources.resource import Resource
import matplotlib.pyplot as plt
import time
import numpy as np
@dannas
dannas / advent_of_code_2021.py
Created December 2, 2021 15:11
Solutions to AoC 2021
import re
from itertools import permutations, combinations, count, chain, product
from typing import Dict, Tuple, Set, List, Iterator, Optional, Union
from collections import defaultdict
from functools import lru_cache
from math import prod
#### FILE INPUT AND PARSING ######################################
# Adapted from Peter Norvigs Advent of Code solutions, https://github.com/norvig/pytudes.
def Input(day, parser=str.split, sep='\n') -> list:
@dannas
dannas / gist:554ddccca87bdc88ded3f9a36cecd75f
Created October 25, 2021 16:53
Rigol MSO1104 scpi trace
λ ./src/glscopeclient/glscopeclient --debug --trace SCPILxiTransport
OMP_WAIT_POLICY not set to PASSIVE. Re-exec'ing with correct environment
Detecting CPU features...
* AVX2
* FMA
Detecting OpenCL devices...
No platforms found, disabling OpenCL
Connecting to SCPI oscilloscope over VXI-11 at 10.42.0.35:0
[SCPILxiTransport::SendCommand] Sending *IDN?
@dannas
dannas / string_copy_elision_benchmark.cpp
Created April 30, 2021 19:49
Benchmark ways of passing strings to functions
#define RUN_ME /*
g++ -Wall -std=c++17 $(pkg-config benchmark --cflags) -O2 $0 -o $(basename $0 .cpp) $(pkg-config benchmark --libs) -lpthread
./$(basename $0 .cpp)
exit 0
*/
// --------------------------------------------------
// Benchmark Time CPU Iterations
// --------------------------------------------------
// BM_r1 52 ns 52 ns 12272152
@dannas
dannas / gdb_logging.txt
Last active January 27, 2021 20:02
gdb remote protocol exchanges during failed P&E flash programming
Already logging to gdb.txt.
quit
Remote debugging using localhost:7224
Sending packet: $qSupported:multiprocess+;qRelocInsn+#2a...Ack
Packet received: PacketSize=480;qXfer:memory-map:read+;qXfer:features:read+;QStartNoAckMode+
Packet qSupported (supported-packets) is supported
Sending packet: $QStartNoAckMode#b0...Ack
Packet received: OK
Sending packet: $Hg0#df...Packet received: OK
Sending packet: $qXfer:features:read:target.xml:0,47b#18...Packet received: m<?xml version="1.0" ?>\r\n<!DOCTYPE target SYSTEM "gdb-target.dtd">\r\n<target>\r\n\t<architecture>powerpc:vle</architecture>\r\n\t<feature name="org.gnu.gdb.power.core">\r\n\t\t<reg bitsize="32" name="r0"/>\r\n\t\t<reg bitsize="32" name="r1"/>\r\n\t\t<reg bitsize="32" name="r2"/>\r\n\t\t<reg bitsize="32" name="r3"/>\r\n\t\t<reg bitsize="32" name="r4"/>\r\n\t\t<reg bitsize="32" name="r5"/>\r\n\t\t<reg bitsize="32" name="r6"/>\r\n\t\t<reg bitsize="32" name="r7"/>\r\n\t\t<reg bitsize="32" name="r8"/>\r\n\t\t<reg bitsize="32" name="r9"/>\r\n\t\t<reg bitsize=
@dannas
dannas / advent_of_code_2020.py
Last active December 15, 2020 20:54
AoC solutions. In heavy need of editing
import re
from itertools import permutations, combinations, count
from collections import defaultdict
from functools import lru_cache
from math import prod
#### FILE INPUT AND PARSING ######################################
# Adapted from Peter Norvigs Advent of Code solutions, https://github.com/norvig/pytudes.
def Input(day, line_parser=str.split, line_ending='\n'):
"For this day's input file, return a tuple of each line parsed by `line_parser`."
@dannas
dannas / insertion_sort.c
Created October 4, 2020 19:38
Bentley insertion sort
#include <stdbool.h>
#include <math.h>
// https://godbolt.org/z/eE853h
void swap(int a[], size_t i, size_t j) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}