Skip to content

Instantly share code, notes, and snippets.

View eggsyntax's full-sized avatar

Egg Syntax eggsyntax

View GitHub Profile
@eggsyntax
eggsyntax / precip-in-clojure.clj
Created December 1, 2011 13:39
Snippet of clojure
(ns precip
(:use [clojure.math.numeric-tower :only (expt)]))
(defn average [l]
(float (/
(reduce + l)
(count l))))
(defn variance [l]
(let [vmean (average l)]
@eggsyntax
eggsyntax / vimrc-egg
Created December 3, 2011 02:02
.vimrc
colorscheme morning
if has("gui_macvim")
let macvim_hig_shift_movement = 1
endif
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
;; 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]
(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)))
(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))
@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)
@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 / 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 / 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 / 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."