Skip to content

Instantly share code, notes, and snippets.

View Olical's full-sized avatar
🧙‍♂️
(magic)

Oliver Caldwell Olical

🧙‍♂️
(magic)
View GitHub Profile
@Olical
Olical / meter-readings.js
Last active July 24, 2023 18:16
Get all meter readings from Switch2 MeterReadings page
// For use on https://my.switch2.co.uk/MeterReadings/History
// Prints out a CSV which you can save to a file and then upload to something like https://www.csvplot.com/
data = Array.from(document.querySelectorAll(".meter-reading-history-table-data-row.desktop-layout")).map(function (row) {
return {
date: row.querySelector(".meter-reading-history-table-data-date-row-item").innerText,
amount: parseInt(row.querySelector(".meter-reading-history-table-data-amount-row-item").innerText)
}
}).reverse()
@Olical
Olical / conjure-school.sh
Created August 2, 2020 11:52
Conjure school without installing Conjure!
# Try an interactive Conjure tutorial without installing Conjure!
# All you need is curl and an up to date nvim.
curl -fL conjure.fun/school | sh
@Olical
Olical / repair.clj
Created October 15, 2019 12:02
Repair translated Markdown -> AsciiDoc files from my blog
(require '[clojure.string :as str]
'[clojure.edn :as edn])
(for [file (fs/list-dir "posts")
:when (str/ends-with? (str file) ".md.adoc")]
(let [[_ date slug] (re-find #"(\d\d\d\d\-\d\d\-\d\d)\-([\w\-\d]+)\.md\.adoc" (str file))
title (:title (edn/read-string (slurp (fs/file "posts" (str date "-" slug ".md")))))]
(spit (fs/file "posts" (str slug ".adoc"))
(str "= " title "\nOliver Caldwell\n" date "\n\n" (slurp file)))))
@Olical
Olical / conjure-alpha-usage.md
Last active October 7, 2019 11:57
Using a super alpha version of Conjure - Clojure socket prepl in Neovim

Conjure alpha preview

Neovim Clojure tooling over prepl

This is the legacy Rust implementation that I've replaced with Clojure. Check out the master branch for the main Clojure version. The old source can be found on the legacy-rust-implementation branch.

I've been working on [Conjure][] for a while now and using it day to day at work. It's coming along but I still have a todo list that stretches off the screen. This is mostly "nice to haves", not essential features. I don't want to release it until I've completed my main list and I'm happy with the level of polish.

This gist covers how to set up the current super alpha version (v0.3.0) in your own Neovim so you can give it a go and maybe give me some feedback. Here's the caveats:

@Olical
Olical / fireplace-refresh.vim
Created April 18, 2018 10:58
Vim bindings for vim-fireplace that act like cider-refresh
autocmd FileType clojure nnoremap <buffer> <silent> <localleader>rx :Eval (do (bounce.system/stop!) (clojure.tools.namespace.repl/set-refresh-dirs "src/clj" "src/cljc") (clojure.tools.namespace.repl/refresh :after 'bounce.system/start!))<cr>
autocmd FileType clojure nnoremap <buffer> <silent> <localleader>rX :Eval (do (bounce.system/stop!) (clojure.tools.namespace.repl/clear) (clojure.tools.namespace.repl/set-refresh-dirs "src/clj" "src/cljc") (clojure.tools.namespace.repl/refresh-all :after 'bounce.system/start!))<cr>
@Olical
Olical / scheme.vim
Created April 15, 2018 20:39
Some MIT Scheme bindings intended for Neovim
function! scheme#connect()
vnew
let s:repl_term_id = termopen('mit-scheme')
normal! G
endfunction
function! scheme#eval_top_form()
let l:save_clipboard = &clipboard
set clipboard=
let l:save_reg = getreg('s')
@Olical
Olical / cljs_namespace_tools.cljs
Created March 6, 2018 12:17
ClojureScript (node) to discover namespaces in a directory
(ns cljs-namespace-tools
(:require [clojure.tools.namespace.parse :as parse]
[cljs.tools.reader.reader-types :as reader-types]
[cljs-node-io.core :as io]
[cljs-node-io.fs :as fs]
[cljs.test :as t]))
(defn path-kind [path]
(cond
(fs/file? path) :file
@Olical
Olical / tree.cljc
Created September 16, 2017 11:18
Using clojure.spec to parse trees
(ns bonsai.tree
(:require #?(:clj [clojure.spec.alpha :as s]
:cljs [cljs.spec.alpha :as s])))
(s/def ::element (s/or :string string?
:element (s/cat :name keyword?
:attrs (s/? (s/map-of keyword? any?))
:children (s/* ::element))))
(s/conform ::element [:p])
@Olical
Olical / lzfn.clj
Created September 4, 2017 19:01
A function macro that yields the EXACT same function reference if the arguments and body LOOK the same.
;; Wasn't sure on a name, but this'll do.
(def fn-cache (atom {}))
(defmacro lzfn [& forms]
`(let [fn-hash# (hash '~forms)
fn# (get @fn-cache fn-hash#)]
(if fn#
fn#
(let [new-fn# (fn ~@forms)]
@Olical
Olical / rvm.fish
Last active February 6, 2017 13:18
Changes to rvm.fish so it doesn't make spacemacs error.
function rvm --description='Ruby enVironment Manager'
# run RVM and capture the resulting environment
set --local env_file (mktemp -t rvm.fish.XXXXXXXXXX)
bash -c 'source ~/.rvm/scripts/rvm; rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv > /dev/null 2>&1
# apply rvm_* and *PATH variables from the captured environment
and grep '^rvm\|^[^=]*PATH\|^GEM_HOME' $env_file | grep -v '_clr=' | sed '/^[^=]*PATH/s/:/" "/g; s/^/set -xg /; s/=/ "/; s/$/" ;/; s/(//; s/)//' | source
# needed under fish >= 2.2.0
and set -xg GEM_PATH (echo $GEM_PATH | sed 's/ /:/g')