Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@timblair
timblair / headers-with-ids.rb
Created November 10, 2021 17:45
Generating headers with IDs using CommonMarker
require "commonmarker"
class HeaderWithIdRender < CommonMarker::HtmlRenderer
def header(node)
block do
old_stream = @stream
@stream = StringIO.new(String.new.force_encoding("utf-8"))
out(:children)
content = @stream.string
@stream = old_stream
@timblair
timblair / strava.js
Last active April 12, 2021 19:31 — forked from scottpdawson/strava.js
Bulk download Strava activities
var maxPage = 1; // calculate this using (activities/20 + 1)
var activityType = "Run"; // change to the workout type you want, or blank for all
var p = 1;
var done = 0;
var url;
var nw = window.open("workouts.html");
nw.document.write("[");
while (p <= maxPage) {
url = "https://www.strava.com/athlete/training_activities" +
"?keywords=&activity_type=" + activityType + "&workout_type=&commute=&private_activities=" +
@timblair
timblair / grid-join.go
Created December 22, 2017 10:10
AoC 2017 Day 21: Grid Joining
func join(gs []grid) grid {
n := int(math.Sqrt(float64(len(gs)))) // Number of subgrids across/down the new grid
sgn := len(gs[0]) // Number of values on one side of a subgrid
cg := newGridBySize(n * sgn) // The new, combined grid to populate
// Add each subgrid to the new, combined grid.
for i, g := range gs {
// Calculate the position of the top-left of the subgrid once placed in
// the new, combined grid. We use this plus the offset within the subgrid
// to place the values in the combined grid.
@timblair
timblair / gds-go-workshop-01-cheatsheet.md
Last active November 24, 2016 15:43
GDS Go Workshop #1: Cheatsheet

GDS Go Workshop #1: Cheatsheet

Value assignment

var s1 string         // a new string identifer with its zero value ("")
var s2 string = "foo" // an identifer with a non-zero value
var i1 int            // an int identifer with its zero value (0)
var i2 int = 42       // an int identifer with a non-zero value
@timblair
timblair / CHANGELOG.json
Created November 1, 2016 08:46
A quick stab at a machine-readable CHANGELOG format
{
"project": "some-project",
"url": "https://github.com/someorg/some-project",
"description": "Some project or other for SomeOrg",
"releases": [
{
"version": "1.0.0",
"date": "2014-12-05",
"items": [
require "gviz"
require "optparse"
# Usage: $0 PINFILE [OPTIONS]
#
# -i, --highlight APPS Highlight apps that depend on these
# -x, --exclude APPS Exclude these apps
# -o, --only APPS Only show dependencies and dependants of these
# -s, --hide-solitary Hide apps with no dependecies or dependants
# -f, --out-file FILE The filename to write output to (default: out.png)
@timblair
timblair / Makefile
Created July 22, 2016 07:18
HTTP connection changes between Go 1.5.x and 1.6.x
.PHONY: build clean run
V15 := 1.5.4
V16 := 1.6.3
B15 := http-test-1.5
B16 := http-test-1.6
all: clean build run
@timblair
timblair / kickstart.sh
Created June 29, 2016 10:18
Personal machine kickstart
#!/bin/bash
# Tim's Development Environment Setup
# ===================================
# Stop immediately if anything fails
set -e
############################################
# Handy functions
module.exports = function (robot) {
robot.hear(/ (?:is )(\w+ ?){1,6}/i, function (msg) {
if (Math.random() < 0.001) {
var match = msg.match[0].trim().replace(/^is /,"");
msg.send("You're " + match);
}
});
};
@timblair
timblair / 1-daily-walk.go
Created November 6, 2015 08:51
Quick stabs at these Go concurrency exercises: http://bit.ly/go-concurrency-exercises
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type person string