Skip to content

Instantly share code, notes, and snippets.

@otherjoel
otherjoel / keybase.md
Created February 17, 2015 16:14
keybase.md

Keybase proof

I hereby claim:

  • I am otherjoel on github.
  • I am joeld (https://keybase.io/joeld) on keybase.
  • I have a public key whose fingerprint is 3E62 C998 419D 9A17 EE0D AB81 E699 A27B 70BF 1CD8

To claim this, I am signing this object:

@otherjoel
otherjoel / counterfile.sh
Created October 7, 2016 20:36
Script to find a line in a text file (based on an environment variable) and increment a value within that line
#!/bin/bash
# Script to find a line in a text file (based on an environment variable) and increment a value within that line
# In this example, the text file has several lines of the form "<ip address>,<number>"
# Add a line for this IP address if it doesn't exist
grep -q -F $REMOTE_ADDR hits.txt || echo "$REMOTE_ADDR,0" >> hits.txt
# Increase the count for this IP address
sed -r -i 's/'"$REMOTE_ADDR"',([0-9]+)/echo "$REMOTE_ADDR,$((\1+1))"/ge' /d2a/4weeks/shipreporthits.txt
# Load functions for validating email addresses
from email.utils import parseaddr
from dns.resolver import query
from dns.exception import DNSException
def check_address(addr):
addr_parsed = parseaddr(addr)[1]
# An empty string at this point means the address was wildly invalid
if addr_parsed == '':
@otherjoel
otherjoel / web_sync.sh
Created September 26, 2017 13:58
Simple script for syncing a folder and a database from a local dev environment to a production web server
#!/bin/bash
# This script will push any changes in a local dev environment (both files and
# a SQL database) to a prod server. It assumes you have passwordless SSH login
# set up on the remote server, and that you already have a database of the same
# name created on the remote server.
# This script stores SQL usernames and passwords in plain text. If you use it,
# make sure you store it in a safe place, don't include it in version control,
# and chmod its permissions to 700!
@otherjoel
otherjoel / chapter1.html.pm
Created March 16, 2018 21:19
Minimal Pollen project demonstrating use of `in`
#lang pollen
◊define-meta[title]{Chapter I}
Travellers left and entered our car at every stopping of the train. Three persons, however, remained, bound, like myself, for the farthest station...
@otherjoel
otherjoel / example-nbsp-replacer.rkt
Created August 14, 2018 23:58
Example module that replaces the last space in a tagged X-expression with the HTML nbsp entity
#lang racket
(require txexpr)
(define (string-reverse str)
(list->string (reverse (string->list str))))
(define (replace-first-space str)
(string-replace str " " "&nbsp;" #:all? #f))
@otherjoel
otherjoel / SketchSystems.spec
Last active February 28, 2019 23:00
Not Authenticated
Not Authenticated
Log In*
authenticate -> Authenticated
Authenticated
Reservation Display*
log out -> Log In
enter reservation -> Reservation Display
enter message -> Reservation Display
click own reservation -> Edit Reservation
@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)
@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 / 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)