Skip to content

Instantly share code, notes, and snippets.

@byzantic
byzantic / tester.cpp
Created January 6, 2025 12:40
ValveWizard Tester Arduino sketch
#define DIODE_MODE 1
#define TRIODE_MODE 2
#define PENTODE_MODE 3
#define PENTODE_G2_MODE 4
#define DIAGNOSTIC_MODE 5
#define MIN_HV_INCREMENT 5 //Minimum increment between each high-voltage datapoint in a sweep, in volts
#include <math.h>
#include <avr/pgmspace.h>
#include <Wire.h> //Include the Wire library to talk I2C
@byzantic
byzantic / W5500_tcp_echo_desc.md
Last active February 4, 2024 10:08
TCP server in micropython on Wiznet W5500-EVB-Pico

Wiznet has a board that adds ethernet capability to a Raspberry Pi Pico - the W5500-EVB-Pico. I'd like to use this to implement network connected instruments in my home lab.

There are plenty of examples on the documentation site, but the TCP examples all seem to use low-level socket programming. The latest Micropython implementations all have asyncio available so why not use the facilities available there?

For example Bytepawn's simple message queue server

Nope. Doesn't work. The problem seems to be that even though the Micropython documentation says that the asyncio.start_server function works in the same way as the standard library - it doesn't. After some digging on the net, I came up with the following.

This code uses start_server but then runs the resulting generator using an explicitly constructed asyncio event_loop. There is an advantage to this, though, in that this also allows us to start multiple tasks, o

@byzantic
byzantic / anagrams.py
Last active January 3, 2022 17:36
Anagrams
def ana_key(word):
return ''.join(sorted(word))
def addAna(anas, word):
key = ana_key(word)
ws = anas.get(key,set())
ws.add(word)
anas[key] = ws
@byzantic
byzantic / appparser.u
Last active June 21, 2021 19:43
Applicative Parser in Unison
-- convert elm version of applicative parsers here:
-- https://gist.github.com/byzantic/bf2922861ff548193850def6c1b68e85
--
-- try to implement the Applicative Parser examples from
-- CIS 194 week 9
-- see http://www.seas.upenn.edu/~cis194/fall16/lectures/09-more-applicative.html
--
-- no type alias in Unison
--
@byzantic
byzantic / ureads.u
Created March 30, 2020 21:57
Matthew Ess' Unison parser combinators
-- see https://gist.github.com/matthewess/3f1140382b4c4e3f60d61e783b334763
f <$> p = 'let
p' = !p
f p'
pf <*> p = 'let
f = !pf
p' = !p
@byzantic
byzantic / monads.u
Created March 30, 2020 12:41
Unison Monads
-- This gist shows how we can use abilities to provide nicer syntax for any monad.
-- We can view abilities as "just" providing nicer syntax for working with the
-- free monad.
ability Monadic f where
eval : f a -> a
-- Here's a monad, encoded as a first-class value with
-- two polymorphic functions, `pure` and `bind`
type Monad f = Monad (forall a . a -> f a) (forall a b . f a -> (a -> f b) -> f b)
@byzantic
byzantic / AppChemParser.elm
Created November 23, 2017 11:25
Chemical Parser using ELm Applicative Parser
-- Cambridge Elm Meetup problem, chemical formulae,
-- implemented using Applicative Parser Combinators
--
module AppChemParser exposing (..)
import Char exposing (..)
import Dict exposing (..)
import Html exposing (Attribute, Html, beginnerProgram, div, input, text)
import Html.Attributes exposing (..)
@byzantic
byzantic / AppParser.elm
Created November 23, 2017 11:09
Elm Applicative Parsers
-- try to implement the Applicative Parser examples from
-- CIS 194 week 9
-- see http://www.seas.upenn.edu/~cis194/fall16/lectures/09-more-applicative.html
--
module AppParser exposing (..)
import Char exposing (..)
import Result exposing (..)