Skip to content

Instantly share code, notes, and snippets.

package main
import (
"math/rand"
"sort"
"testing"
)
func BenchmarkInsertSorted(b *testing.B) {
data := make([]int, b.N)
# update_timezones.py
# Aleksandr Pasechnik
#
# Goes through the Day One jounal and sets the Time Zone of each entry that
# doesn't already have one to the value of the *timezone* variable. Makes a
# backup copy of each entry it modified by adding a '.tzbak' to the filename.
# Ignores any entry that already has a '.tzbak' version.
#
# NOTE: base_dir may need to be adjusted to the correct Journal_dayone location
# NOTE: It is probably a good idea to have a full journal backup just in case
@apiarian
apiarian / citibike-widget.js
Last active January 3, 2022 14:47
CitiBike Status iOS Widget
function lat_lon(thing) {
return {
"lat": thing.lat || thing.latitude,
"lon": thing.lon || thing.longitude,
}
}
function distance(loc1, loc2) {
loc1 = lat_lon(loc1)
loc2 = lat_lon(loc2)
@apiarian
apiarian / Top Chicken.js
Last active August 1, 2022 14:17
a Scriptable (iOS) widget for chicken.photos
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: kiwi-bird;
const home = await (new Request("https://chicken.photos")).loadString()
const chickenLine = home.split("\n").filter(x=>x.match(/<a href="\/\d+">/))[0]
const m = chickenLine.match(/a href="([^"]+)"><img .*src="([^"]+)"/)
const chickenUrl = "https://chicken.photos" + m[1]
@apiarian
apiarian / README.md
Created September 3, 2022 03:49
SCRIPT-8
pingcheck = hs.menubar.new()
function pingUpdate()
pingcheck:setTitle('⥌'..pingcheck:title())
local p = hs.network.ping('example.com', 3)
hs.timer.doAfter(4, function()
p:cancel()
local avg = p:summary():match('%/(%d+)%.%d+%/')
if avg == nil or avg == '0' then
pingcheck:setTitle('∞')
else