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 / round.js
Created August 22, 2011 14:05
Very fast rounding in JavaScript
Number.round = function() {
return (this + 0.5) << 0;
};
@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 / grid.py
Created April 4, 2012 22:20
Python grid classes
# Manages a grid of values
class Grid():
def __init__(self, width, height, default=''):
self.width = width
self.height = height
self.data = [[default for y in range(height)] for x in range(width)]
def set(self, x, y, value):
self.data[y][x] = value
@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 / binary-search.js
Last active October 18, 2020 15:16
JavaScript binary search with the same API as indexOf. Performance: http://jsperf.com/binaryindexof-and-indexof
/**
* Performs a binary search on the host array. This method can either be
* injected into Array.prototype or called with a specified scope like this:
* binaryIndexOf.call(someArray, searchElement);
*
* @param {*} searchElement The item to search for within the array.
* @return {Number} The index of the element which defaults to -1 when not found.
*/
function binaryIndexOf(searchElement) {
'use strict';
@Olical
Olical / fish_prompt.fish
Created August 14, 2015 17:05
My fish shell lambda prompt functions (they go in ~/.config/fish/functions) it's extremely fast too! :D
# A lambda (λ) prompt.
# Green and red depending on exit status.
# Underlined if git status is dirty.
# Uppercase (Λ) if ahead of the remote.
function fish_prompt
if is_status_okay
set_color green
else
set_color red
@Olical
Olical / Documentation.md
Created September 22, 2011 12:07
Preloader.js - Preload all assets, ideally for a game, using MooTools

About

This class allows you to preload all of your images, sounds, videos, JSON, JavaScript and CSS files with one call. It provides you with progress reports and lets you know when everything is done.

It requires MooTools and MooTools More with the Assets and Request.JSONP boxes ticked. I have attached a copy of the required MooTools More version to this gist.

Example

You can find an example here on jsFiddle.

@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 / throttle-check
Created April 21, 2015 16:44
Throttle your localhost. (for Linux)
#!/usr/bin/env bash
if [[ -f /tmp/throttle-check ]]; then
echo "Currently throttling at $(cat /tmp/throttle-check). (throttle-off to stop)"
else
echo "Not currently throttling. (throttle-on to start)"
fi