Skip to content

Instantly share code, notes, and snippets.

View greghelton's full-sized avatar

Greg Helton greghelton

View GitHub Profile
@greghelton
greghelton / main.groovy
Last active September 15, 2026 07:23
Groovy that executes Stored Procedures and UDFs
import java.sql.Connection
import java.sql.DriverManager
import java.sql.CallableStatement
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.Types
if (args.length < 2) {
println "Usage: groovy main.groovy SCHEMA ROUTINE_NAME"
System.exit(1)
@greghelton
greghelton / CALCSVCS.rpgle
Last active September 13, 2026 07:20
Use Spock and IBM's Mapepire to unit test RPG Subproceures that are registered as UDFs. Google Gemini wrote the code.
**FREE
Ctl-Opt NoMain Option(*SrcStmt:*NoDebugIo);
// -----------------------------------------------------------------
// Subprocedure: CalculateInterest
// Computes simple interest: (Principal * Rate * Years)
// -----------------------------------------------------------------
Dcl-Proc CalculateInterest Export;
Dcl-Pi CalculateInterest Packed(15:2);
pPrincipal Packed(15:2) Const;
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}