Skip to content

Instantly share code, notes, and snippets.

View erkin's full-sized avatar

Lulu Cathrinus Grimalkin erkin

View GitHub Profile
@erkin
erkin / csexp.scm
Last active October 14, 2022 07:18
Canonical S-expression parser
(define (read-csexp)
(letrec
((left-paren (char->integer #\())
(right-paren (char->integer #\)))
(zero (char->integer #\0))
(nine (char->integer #\9))
(colon (char->integer #\:))
(in (current-input-port))
(read-atom
(λ (byte digits)
@erkin
erkin / little-macros.ss
Last active April 7, 2021 17:08
Useful Scheme macros I keep rewriting for every project
(define-syntax define-syntax-rule
(syntax-rules ()
((_ (name args ...) body)
(define-syntax name
(syntax-rules ()
((name args ...) body))))))
(define-syntax-rule (do-times n . body)
(do ((i n (sub1 i)))
((< i 1))
@erkin
erkin / sudoku.rkt
Created December 11, 2020 23:40
Nondeterministic sudoku solver
#lang racket
(module amb racket/base
(provide amb assert!)
(define-syntax-rule (pop! stack)
(begin0 (car stack) (set! stack (cdr stack))))
(define-syntax-rule (push! v stack)
(set! stack (cons v stack)))
(define (U f) (f f))
@erkin
erkin / regexp-checker.rkt
Created October 30, 2020 23:04
A graphical regular expression checker in plain Racket, supports PCRE
#lang racket/base
(require racket/gui/base
racket/class
racket/list
racket/string)
(define program-name "regexp-checker")
(define program-version "v0.1")
(define version-message
@erkin
erkin / get-pass.ss
Last active October 5, 2020 02:52
getpass in Chez Scheme
;;; Chez Scheme clone of Python `getpass'
;;; Based on github.com/smitchell556/get-pass
(library (get-pass)
(export get-pass)
(import (chezscheme))
;;; FFI portion
;;; See termios(3) for more info
(define-ftype termios
(struct
@erkin
erkin / webhook.rkt
Last active July 22, 2020 17:00
Minimal Discord webhook client (text-only)
#lang racket/base
(require net/http-client json)
(define webhook-id "foo")
(define webhook-token "bar")
(module+ main
(http-conn-send!
(http-conn-open "discord.com" #:ssl? #t)
(string-append "/api/webhooks/" webhook-id "/" webhook-token)
@erkin
erkin / docker-compose.yaml
Created May 29, 2020 12:42
SchemeBBS with Varnish
version: "3.3"
services:
bbs:
image: erkin/schemebbs
container_name: sbbs
ports:
- '8080'
volumes:
- ${SBBS_DATADIR}:/opt/schemebbs/data
proxy:
@erkin
erkin / docker-compose.yaml
Created May 29, 2020 12:40
SchemeBBS with Traefik
version: "3.3"
services:
bbs:
image: erkin/schemebbs
container_name: sbbs
labels:
- "traefik.enable=true"
- "traefik.http.services.bbs.loadbalancer.server.port=80"
- "traefik.http.routers.bbs.rule=Host(`example-bbs.org`)"
- "traefik.http.routers.bbs.entrypoints=websecure"
@erkin
erkin / pure-mlang.rkt
Created January 9, 2020 08:46
`racket/base` sans mutative procedures
#lang racket/base
(provide
(except-out
(all-from-out racket/base)
set!
set!-values
box-cas!
bytes-copy!
bytes-fill!
bytes-set!
@erkin
erkin / pride.rkt
Last active January 14, 2022 18:13
Print pride flags to your terminal
#lang racket ; -*- racket -*-
(define gay
'((228 003 003) ; red
(255 140 000) ; orange
(255 237 000) ; yellow
(000 128 038) ; green
(000 077 255) ; blue
(117 007 135) ; purple
))