Skip to content

Instantly share code, notes, and snippets.

View samdphillips's full-sized avatar

Sam Phillips samdphillips

  • Oakland, California
View GitHub Profile
@samdphillips
samdphillips / evdev.rkt
Created December 8, 2023 03:39
Simple Racket library to interact with Linux input event devices
#lang racket/base
(require ffi/unsafe
ffi/unsafe/custodian
ffi/unsafe/define
ffi/unsafe/schedule
racket/struct)
(provide evdev-open
evdev-read
(define (poll-evt poll-thunk
#:interval [interval-thunk (const 1000)]
#:cleanup [cleanup-thunk void])
(poll-guard-evt
(lambda (polling?)
(if polling?
(cond [(poll-thunk) =>
(lambda (v)
(wrap-evt always-evt (const v)))]
[else never-evt])
(define-syntax-parse-rule (with-env ([var val] ...) body ...+)
(call-with-env
(make-environment-variables
(~@ (string->bytes/locale var)
(string->bytes/locale val)) ...)
(λ () body ...)))
#lang racket/base
;; Works on Linux, doesn't work on Mac? More minimal version.
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-curl (ffi-lib "libcurl"))
(define CURL_GLOBAL_ALL #b11)
#lang racket/base
;; Works on Linux, doesn't work on Mac?
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-curl (ffi-lib "libcurl")
#:provide provide-protected)
@samdphillips
samdphillips / uuid.rkt
Created June 25, 2023 03:50
uuid in racket
#lang racket/base
(require (for-syntax racket/base
syntax/parse)
racket/stxparam
(only-in racket/format ~r)
(only-in racket/port
call-with-input-bytes
call-with-input-string
@samdphillips
samdphillips / python_codec_abuse.md
Last active June 18, 2023 20:28
Python Codec Abuse List

Python allows a codec directive at the start of a file which allows for a hook to rewrite the content.

Here are some uses I've found of this in the wild using this github query.

#lang racket
(define-logger workin)
(struct queue (fore aft))
(define (enqueue q w)
(match q
[(queue a d) (queue a (cons w d))]))
#lang rhombus/static/and_meta
import:
lib("racket/stream.rkt")
export:
Stream
meta:
namespace Stream:
#lang racket/base
(require mzlib/thread
racket/match
racket/port
racket/string
"mcast-channel.rkt")
(define-logger chat-server)