Skip to content

Instantly share code, notes, and snippets.

View greghelton's full-sized avatar

Greg Helton greghelton

View GitHub Profile
package org.vanillaweb;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.*;
public class FullDuplexRelay {
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class BrowserRelay {
@greghelton
greghelton / kotlin_and_AS400.kt
Created May 23, 2026 14:04
jt400.jar is very cool. I had chatgpt write an application that uses AS400 DTAQs. The AS400 often responds to requests from other application tiers but with DTAQs, it can send a request out to the web. Here, the request would be managed or acted on by additional Kotlin code.
import com.ibm.as400.access.AS400
import com.ibm.as400.access.DataQueue
import com.ibm.as400.access.DataQueueEntry
import com.ibm.as400.access.KeyedDataQueue
import java.nio.charset.Charset
fun main() {
// Connect to IBM i
val system = AS400(
@greghelton
greghelton / AIPlayer.swift
Last active June 27, 2026 21:43
Swift Model Training and Gameplay for Backgammon
/// Selects the best legal move for the current player using a trained NeuralNetwork.
public enum AIPlayer {
/// Returns the move that maximises P(currentPlayer wins) according to the network.
public static func bestMove(for state: GameState, network: NeuralNetwork) -> Move {
let moves = uniqueByResult(MoveGenerator.legalMoves(for: state), from: state)
let player = state.currentPlayer
return moves.max { a, b in
score(move: a, state: state, network: network, player: player)
< score(move: b, state: state, network: network, player: player)
@greghelton
greghelton / ai.clj
Last active May 11, 2026 19:07
Claude's Backgammon Game in Clojure trains a model that you then play against.
(ns backgammon.ai
"TD-Gammon inspired reinforcement learning AI for backgammon.
Architecture:
- Neural network: input(198) → hidden(40) → output(1)
- Input: Tesauro's 198-feature encoding of board state
- Output: estimated probability that White wins
- Training: TD(λ) temporal difference learning
- Eligibility traces for credit assignment across moves
@greghelton
greghelton / commands.md
Last active May 10, 2026 06:48
Backgammon Game in clojure. I'm creating a game that I can use to train an AI model.

I'm using the Calva extension in IntelliJ IDEA and sometimes I run the game from the REPL.

(play-until-winner initial-game-state)

Sometimes I run it from the bash command line.

java -cp "lib/spec.alpha-0.6.249.jar:lib/core.specs.alpha-0.5.81.jar:lib/clojure-1.12.0.jar:src/main/clojure" clojure.main -i src/main/clojure/backgammon/core.clj -e "(in-ns 'backgammon.core)" -e "(play-until-winner initial-game-state)"

@greghelton
greghelton / main.clj
Last active May 9, 2026 12:35
Running Clojure with Maven etc
(ns my-project.core
(:require [clojure.spec.alpha :as s]))
;; Define a simple spec for a 'User' map
(s/def ::name string?)
(s/def ::age int?)
(s/def ::user (s/keys :req [::name ::age]))
(defn -main [& args]
(let [valid-data {::name "Greg" ::age 30}
@greghelton
greghelton / lisp_in_emacs.md
Last active May 13, 2026 04:52
Emacs and Lisp Notes

Install emacs on a Mac
Commands Run:
brew install emacs
/opt/homebrew/opt/emacs/bin/emacs --fg-daemon
open new terminal tab
emacsclient -c

Using emacs
Note that on the Mac keyboard, Meta is ⌥ and Control is ^

@greghelton
greghelton / FPvsOO.md
Last active May 11, 2026 00:08
Quote - Functional vs Object-Oriented Programming

Whenever I write some code to deal with data about people then functional programming seems to work best. Whenever I write some code to simulate people then object-oriented programming seems to work best.
— Michael Fogus

Object oriented programming makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts.
— Michael Feathers

• A function doesn’t have to be 100% pure to get many of the benefits of purity.
• Of course you don’t want to use the fact that it’s not 100% pure as an excuse for making it even less pure.
• A more functional programming style often results in more parameters to a function.
• A functional style does lead to more parameters but, it is much easier to test the functions in isolation.