Skip to content

Instantly share code, notes, and snippets.

@otherjoel
otherjoel / appify
Created August 1, 2023 17:41 — forked from mathiasbynens/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
#lang racket/base
(require racket/function)
(struct command (subproc stdout stdin))
(define (start cmd-str . args)
(define-values (subp out in _err)
(if (null? args)
; 'new is important - without it, killing the subprocess will not
@otherjoel
otherjoel / xexpr-len.rkt
Last active January 11, 2022 16:54
Attempting to calculate string-length of an x-expression with minimal allocation
#lang racket/base
(require racket/contract/base
racket/match
racket/symbol
txexpr
xml)
;; Function for calculating the length in characters of an x-expression if it
;; we converted to a string --- without actually converting it into a string
@otherjoel
otherjoel / spf-fail.rkt
Last active February 11, 2023 06:16
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
@otherjoel
otherjoel / lp2.rkt
Created September 24, 2021 17:04
Example of Scribble/lp2 doc that does not produce links to definitions of stuff defined in the doc itself.
#lang scribble/lp2
@(require scribble/manual
(for-label racket/contract
racket/base))
@(declare-exporting "lp2.rkt")
@title[#:style manual-doc-style]{Example}
@otherjoel
otherjoel / run-test.rkt
Last active March 22, 2021 20:25
Beeswax/Pollen: simple rendering performance comparison
#lang racket/base
;; Place all the files in this gist in the same folder
;; Then do:
;; racket -tm run-test.rkt -- simple.html.pm out.html template.html.p wax-template.html.rkt
;;
;; For comparison, also try doing "raco make wax-template.html.rkt" before running run-test.rkt
(require pollen/core
(prefix-in pollen: pollen/render))
@otherjoel
otherjoel / wallpaper.rkt
Created March 18, 2021 20:32
IT Wallpaper Generator
#lang racket/base
(require br/macro
pict
racket/class
racket/draw)
;; Make wallpaper for use on server desktops
(define mint-green (make-object color% 1 133 116))
@otherjoel
otherjoel / sandwiches.rkt
Created June 16, 2020 21:44
Count the possible sandwiches in a loaf of bread (Racket)
#lang racket
(require threading)
(define (slice-pairs slice-count)
(combinations (range slice-count) 2))
;; Any two non-adjacent slices form a sandwich
(define (sandwich-pair? lst)
(and (list? lst)
@otherjoel
otherjoel / Pollen namespace reuse test.txt
Last active May 12, 2020 00:30
Pollen namespace reuse test
❯ raco pollen render another.txt example.txt
pollen: rendering another.txt example.txt
pollen: rendering /another.txt.pm
pollen: rendered /another.txt (421 ms)
pollen: rendering /example.txt.pm
pollen: rendered /example.txt (339 ms)
❯ cat another.txt
Result: 1
@otherjoel
otherjoel / 0-test-word-counter.rkt
Last active March 21, 2019 02:56
Benchmarking regular expressions against purpose-built functions in Racket
#lang racket/base
;; Comparing the speed of two methods for getting the first N words out of the string elements
;; of a tagged X-expression.
;;
;; Licensed under the Blue Oak Model License 1.0.0 (blueoakcouncil.org/license/1.0.0)
(require racket/list
txexpr)