Skip to content

Instantly share code, notes, and snippets.

(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)
@samdphillips
samdphillips / mcast-channel.rkt
Created March 8, 2023 22:35
Multicast channels using IVars
#lang racket/base
;; uses https://github.com/samdphillips/racket-syncvar
(require racket/contract
racket/match
"ivar.rkt")
(provide mcast-channel?
mcast-output?
@samdphillips
samdphillips / supervisor.rkt
Created January 17, 2023 23:41
Simple thread supervisor
#lang racket/base
(require racket/exn
racket/set
"util.rkt")
(provide supervise)
(define-logger supervise)