Skip to content

Instantly share code, notes, and snippets.

@97jaz
97jaz / import-example.rkt
Created Feb 24, 2021
proof-of-concept for module aliases with `open`
View import-example.rkt
#lang racket/base
(require (for-syntax racket/base
racket/syntax
racket/require-transform
syntax/id-table))
(begin-for-syntax
(struct import-transformer (aliases)
#:property prop:require-transformer
View n-way-output-port.rkt
#lang racket/base
(require (only-in racket/port open-output-nowhere)
(only-in racket/string string-join))
(struct pending-write (bstr out start end) #:authentic #:mutable)
(define-syntax-rule (define/pending-write (bstr out start end) pending-write)
(define-values (bstr out start end)
(let ([x pending-write])
View simple-chunked-transfer.rkt
#lang racket/base
(define max-chunk-len (sub1 (expt 2 16)))
(define (produce in-port out-port)
(define buffer (make-bytes max-chunk-len))
(let loop ([chunk-length (read-bytes-avail! buffer in-port 0 max-chunk-len)])
(cond
[(eof-object? chunk-length)
View evt-do.rkt
#lang racket/base
(require racket/match
racket/port
syntax/parse/define
(for-syntax racket/base))
(define (read-message inp)
(match (read-byte inp)
[#x00 (define payload-size (read-byte inp))
View tee-output-port.rkt
#lang racket/base
(struct pending-tee (bstr out start end) #:authentic #:mutable)
(define (tee-output-port out1 out2)
(define pending #f)
(define lock (make-semaphore 1))
;(define ready-evt
; (replace-evt lock (λ (_) (replace-evt out1 (λ (_) out2)))))
View Racket var-int codec
#lang racket/base
(define (signed-var-int val)
(cond
[(bitwise-bit-set? val 31)
(bitwise-ior val (bitwise-not #xffffffff))]
[else
val]))
(define (read-var-int in)
View structural-each-plus-others.rkt
#lang racket/base
(require racket/match)
(define (each+others/non-index cs [prev '()] [res '()])
(match cs
['() res]
[(cons c cs) (each+others/non-index cs
(cons c prev)
(cons (cons c (append prev cs)) res))]))
View recursive-each-plus-others.rkt
#lang racket/base
;; others: generates a list of characters in `str` *other*
;; than the one at index `pos`
(define (others str pos [i 0] [res '()])
(cond [(= i (string-length str))
(reverse res)]
[(= pos i)
(others str pos (add1 i) res)]
[else
@97jaz
97jaz / limited-for-list.rkt
Created Sep 1, 2015
Limiting the size of the result of for*/list
View limited-for-list.rkt
;; RFC 5545 example: "Every other week on Tuesday and Thursday, for 8 occurrences"
(define start (moment 1997 9 2 9 #:tz "America/New_York"))
;; using for*/fold with #:break and explicit reverse
(let-values ([(res _)
(for*/fold ([xs '()] [i 0]) ([w (in-naturals)]
[t (in-value (+weeks start (* w 2)))]
[d (list (on-wday t 2) (on-wday t 4))]
#:break (= i 8))
(values (cons d xs) (add1 i)))])
View rspec-rails-3.2.0-take2.diff
diff --git a/Gemfile.lock b/Gemfile.lock
index c6a353c..821b0bf 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -286,7 +286,7 @@ GEM
gridhook (0.2.0)
multi_json (>= 1.3.0)
rails (>= 3.1.0)
- guard (2.11.1)
+ guard (2.12.1)