Skip to content

Instantly share code, notes, and snippets.

@samdphillips
samdphillips / ivar.rkt
Created August 19, 2022 18:09
One shot synchronizable variables.
#lang racket/base
(require racket/contract
racket/undefined)
(provide ivar?
exn:fail:ivar?
make-ivar
(contract-out
[ivar-put! (-> ivar? any/c any)]
@otherjoel
otherjoel / spf-fail.rkt
Last active July 2, 2024 06:35
Generate a form email to explain to someone at another company that their SPF is broken
#lang racket/base
;; Generate a form email to let someone know their SPF records are misconfigured for their current email provider.
;;
;; Run (fill-report "domain.com" "1.2.3.4") where the 2nd arg is the sending email server's IP address.
;; It will copy the completed report to the clipboard for you.
;; Only works on Windows for now.
(require net/dns
@jackfirth
jackfirth / pretty-printing.rkt
Created April 15, 2021 00:18
Pretty printing sequences with indentation and without any delimiters.
#lang racket/base
(require racket/contract/base)
(provide
(contract-out
[sequence-markup? predicate/c]
[sequence-markup
@samth
samth / 206-vs-80.md
Last active February 25, 2021 16:44
Racket performance improvement over 17 years

Arseny Kapoulkine (h/t John Regehr) wrote a nice exploration of how LLVM from 2010 compares to the performance we get today. I decided to try out an old version of Racket, and compare performance to a modern version.

The versions I compared were:

  • MzScheme 206p1, released January 2004
  • Racket 8.0.0.4, compiled February 2021 (using the Chez Scheme backend)

I measured exactly one benchmark, a mandelbrot set computation from the Computer Language Benchmarks Game, using the implementation in the Racket repository. Of course, that code won't run on v206p1, so I modified it to avoid new features of Racket. The modified version is below.

Of course, many of the features that have been added make the program faster, so it's important to compare with the performance of the modern code. There's even a [parallel version](https://githu

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.

@LiberalArtist
LiberalArtist / default-lightbulb.png
Last active October 2, 2019 01:20
A Racket lightbulb for the Standard Fish Summer Competition 2019
default-lightbulb.png
@LiberalArtist
LiberalArtist / oxgarage.rkt
Created February 20, 2019 02:35
Simple OxGarage Query Script
#!/usr/bin/env racket
#lang racket/base
(require racket/file
racket/string
racket/port
net/url)
(module+ main
(require racket/cmdline)
@samdphillips
samdphillips / gui-tabs.rkt
Created October 3, 2018 18:35
Tabs Example in Racket GUI
#lang racket/base
(require racket/class
racket/gui)
(define frame
(new frame% [label "Tabs!"]))
(define (change-tab tp event)
(when (eq? (send event get-event-type) 'tab-panel)
@bjmiller121
bjmiller121 / multiple-push-urls.md
Last active October 23, 2024 22:13
Add multiple push URLs to a single git remote

Sometimes you need to keep two upstreams in sync with eachother. For example, you might need to both push to your testing environment and your GitHub repo at the same time. In order to do this simultaneously in one git command, here's a little trick to add multiple push URLs to a single remote.

Once you have a remote set up for one of your upstreams, run these commands with:

git remote set-url --add --push [remote] [original repo URL]
git remote set-url --add --push [remote] [second repo URL]

Once set up, git remote -v should show two (push) URLs and one (fetch) URL. Something like this:

@mrexodia
mrexodia / Encrypted iTunes Library.grammar
Created December 16, 2014 20:27
Encrypted iTunes Library File Format
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.9">
<grammar name="Encrypted iTunes Library" start="id:4" author="Mr. eXoDia" email="[email protected]" fileextension="itl" uti="com.apple.itunes.db">
<description>Grammar for encrypted iTunes Library files.</description>
<structure name="Defaults" id="5" encoding="ISO_8859-1:1987" endian="little" signed="no"/>
<structure name="iTunes Library" id="4" extends="id:5">
<structref name="hdfm" id="8" structure="id:7"/>
<binary name="encryptedData" id="9" length="remaining">
<description>This chunk of data is encrypted using AES/ECB/NoPadding with the key &quot;BHUILuilfghuila3&quot;. After decryption, you have to inflate the data using ZLIB.