Skip to content

Instantly share code, notes, and snippets.

View eggsyntax's full-sized avatar

Egg Syntax eggsyntax

View GitHub Profile
'''
Implementation of the puzzle given at
https://worldspiritsockpuppet.com/2021/03/07/sleep-math-red-clay-blue-clay.html
I strongly suggest thinking about the puzzle for a while before looking at the
code; it's really interesting and counterintuitive, or was for me.
"Suppose that you have 1 kg of red clay that is 100 degrees and 1 kg of blue
clay that is 0 degrees. You can divide and recombine clay freely. If two pieces
of clay come into contact, temperature immediately equilibrates—if you put the
shortname: ssc_archive
metadata:
dc:
title: SSC Archive
creator: Scott Alexander
language: en-US
tags:
title: h2
content:
- "https://web.archive.org/web/20200217141740/https://slatestarcodex.com/2013/02/12/abraham-lincoln-ape-man/"
@eggsyntax
eggsyntax / archiver.clj
Created June 28, 2020 02:18
One-off script to grab latest valid archive.org capture URLs for a list of ordinary URLs
(ns archiver
(:require [clojure.string :as s]))
(def archive-root "https://web.archive.org/web/")
(def cutoff-date "20200621000000")
(def ssc-urls
"Assumes the existence of a file in the current directory named 'ssc-urls' and
containing a list of URLs, one per line."
@eggsyntax
eggsyntax / exercise.clj
Last active October 27, 2019 02:38
Exercise proposed on ACL slack
(ns ski.wotcha
(:require [clojure.string :as string]))
;; Based on exercise at https://drive.google.com/drive/folders/1AQN08ikQZvq0QWn9KLuhiE9kJu1Tp2a5
;;; NB: The top-level code to actually solve the problem is down at the bottom:
;; Clojure relies on Java regex, which means regexes of any
;; complexity are pretty ugly:
(def name-regex #"^(\p{IsAlphabetic}+), (\p{IsAlphabetic}+)")
@eggsyntax
eggsyntax / datapull.clj
Last active July 1, 2019 00:58
Datomic-ish pull for vanilla Clojure data structures
(ns datapull
"Datomic-ish pull for vanilla Clojure data structures. Usage examples in test below."
(:require [clojure.test :as t]))
;; Alternatives:
;; - Juxt has a full-featured library for doing the same thing: https://github.com/juxt/pull
;; - Meander and Specter are both libraries for performing complex searches & transformations on Clojure data
(defn- seq-into
"Like into, but returns nil if existing-seq is empty or contains only nils."
@eggsyntax
eggsyntax / learning-from-human-preferences-setup-ubuntu-18.04.txt
Last active March 21, 2019 18:06
stuff I had to do on a fresh Ubuntu 18.04 install to get the learning-from-human-preferences project to work:
# stuff I had to do on a fresh Ubuntu 18.04 install (minimal IIRC) to get the learning-from-human-preferences project to work:
# ( https://github.com/mrahtz/learning-from-human-preferences )
sudo apt install git
sudo apt install vim
mkdir bin
# Add /home/egg/bin and /home/egg/.local/bin to PATH
vim .bashrc
ln -s /usr/bin/python3 /home/egg/bin/python
python --version
@eggsyntax
eggsyntax / shors-test.clj
Created May 21, 2018 16:02
Shor's algorithm, classical part
(ns shors.core
(:require [clojure.math.combinatorics :as c]
[clojure.test :as t :refer [is deftest]]))
(def tries (atom 0))
(defn test-val
"Given p - 1, check whether p is a factor of n. Returns q if it is."
[n p-1]
(swap! tries inc)
(ns tempdat
"Minimal example of an unexpected Datomic behavior"
(:require [datomic.api :as d]))
(def uri "datomic:mem://temp")
(d/delete-database uri) ; ensure fresh start
(d/create-database uri)
(def conn (d/connect uri))
(ns cuber.core)
;; octal numbers:
(def start [0 1 2 3 4 5 6 7])
(def end [4 2 4 2 4 2 4 2])
(defn modding [f]
;; identity
(fn [x] (mod (f x) 8)))
;; Declare namespace
(ns harmonium.sock-problem2
(:require [clojure.pprint :refer [pprint]]))
;; ============ Starting here are some functions ===========
;; ============ for formatting output; feel free ===========
;; ============ to ignore. ===========
(defn to-percent [total n]