Skip to content

Instantly share code, notes, and snippets.

@exupero
exupero / README.md
Last active March 29, 2024 21:10
Alias a domain to a local port (Mac)

I run a lot of web servers for different projects, all of them on different ports. Generally I start with port 8000 and increment from there as I spin up new servers, but it became tiresome to remember what projects were running on which ports and what the next available port was.

/etc/hosts won't let you specify a port, but a combination of aliasing 127.0.0.1 to 127.0.0.X, forwarding ports from 8000 to 80, and adding the 127.0.0.X IP under an alias in /etc/hosts did work.

This script finds the next available value of X, aliases it with ifconfig, forwards the given port to port 80 with ipfw, and adds a new entry to /etc/hosts that aliases the IP to the domain you want.

Now I can add a server alias with sudo domain-alias funproject 8000, run the web server at 127.0.0.X:8000, and load up http://funproject/ in my browser.

(Because I needed it to work on a Mac, I couldn't use iptables. pfctl seems to work.)

@exupero
exupero / README.md
Last active February 6, 2024 22:24
Mid-oceanic ridge

Traced from this image of crustal age and assuming an equirectangular projection.

I've imagined a connection between where the ridge disappears under Alaska and where it emerges from eastern Siberia.

If you know where I can find proper geographical coordinates for the mid-oceanic ridge, please leave a comment.

@exupero
exupero / stack-math.clj
Last active December 31, 2023 16:29
Stack math evaluator
#!/usr/bin/env bb
(ns stack-math
(:require [clojure.string :as str]
[clojure.core.match :refer [match]]
[clojure.tools.cli :as cli]))
(defn parse-stack [s]
(read-string (format "[%s]" s)))
@exupero
exupero / clipboard.clj
Created September 22, 2017 18:32
Clojure code to interact with the system clipboard
(refer-clojure :exclude '[slurp spit])
(import '[java.awt.datatransfer DataFlavor StringSelection Transferable])
(defn clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp []
(try
(.getTransferData (.getContents (clipboard) nil) (DataFlavor/stringFlavor))
(catch java.lang.NullPointerException e nil)))
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {org.clojars.askonomm/ruuter {:mvn/version "1.3.2"}}})
(require '[clojure.java.browse :as browse]
'[clojure.string :as str]
'[cheshire.core :as json]
'[org.httpkit.server :as srv]
'[ruuter.core :as ruuter]
@exupero
exupero / serve.clj
Created January 30, 2023 16:11
Babashka HTTP server that watches files
#!/usr/bin/env bb
(ns server
(:require [clojure.string :as string]
[clojure.java.browse :as browse]
[clojure.tools.cli :refer [parse-opts]]
[babashka.fs :as fs]
[org.httpkit.server :as server])
(:import [java.net URLDecoder]
[java.time Instant]))
@exupero
exupero / README.md
Last active January 28, 2022 18:15
Michigan Big Trees
@exupero
exupero / README.md
Last active January 20, 2022 17:00
Michigan county line roads
  • Orange roads use "County Line" names
  • Red roads use hyphenated names
  • Blue roads use portmanteaus
#!/bin/bash
domain=$1
port=$2
if [ -z "$domain" ] || [ -z "$port" ]; then
echo "Usage: domain-alias <domain> <port>"
exit 1
fi
@exupero
exupero / IntellijNrepl.java
Created April 17, 2019 15:01
Launching a Clojure nREPL from IntelliJ
package squij;
import clojure.lang.*;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;