Skip to content

Instantly share code, notes, and snippets.

View duncanjbrown's full-sized avatar
🍃

Duncan Brown duncanjbrown

🍃
View GitHub Profile
(def nums (take 100 (repeatedly (partial rand-int 10))))
(->> nums
(map-indexed vector)
(partition-by second)
(map (juxt (comp second first) (partial map first)))
(map (fn [[num indexes]]
(let [bounds (distinct ((juxt first last) indexes))]
(str (clojure.string/join "-" bounds) ": " (apply str (repeat num "#"))))))
(run! println))
@duncanjbrown
duncanjbrown / ons_shapefile_to_bigquery.py
Created June 30, 2023 12:46
Prepare an ONS shapefile for BigQuery
import geopandas as gpd
from shapely.geometry import Polygon, MultiPolygon
gdf = gpd.read_file('zip://Regions_December_2022_EN_BUC-shapefile.zip')
# Convert to EPSG:4326 from OSGB36
gdf = gdf.to_crs("EPSG:4326")
def correct_ring_orientation(geometry):
if isinstance(geometry, Polygon):
@duncanjbrown
duncanjbrown / custom_formatter.rb
Last active October 6, 2022 09:55 — forked from mcoms/custom_formatter.rb
When you're having a bad day and just want to skip every failing RSpec test
# frozen_string_literal: true
class CustomFormatter
RSpec::Core::Formatters.register self, :example_failed
def initialize(output)
@output = output
end
def example_failed(notification)
[
{
"userName": "DFE-Digital",
"repo": "apply-for-postgraduate-teacher-training"
},
{
"userName": "DFE-Digital",
"repo": "apply-for-postgraduate-teacher-training-prototype"
}
]
@duncanjbrown
duncanjbrown / Gemfile
Created February 27, 2018 13:13
OpenAPI validation for an Apiary spec
source 'https://rubygems.org'
gem 'open_api_parser'
gem 'pry'
gem 'json_schema'
@duncanjbrown
duncanjbrown / moving-commits.sh
Created February 22, 2018 22:44
Move commits from one repo to another using git
# I was moving a vanilla WP site to Bedrock but wanted to start
# working in Bedrock sooner, so I needed to backport commits
# from Bedrock to the old repo. Bedrock uses a different folder structure, so
# whereas my commits were in in web/app/themes/mytheme, the old
# repo needed changes in wp-content/themes/mytheme.
# In Bedrock
cd web/app/themes/mytheme
git format-patch --relative <commit-hash-at-branch-base> --stdout > ~/patches-from-bedrock
@duncanjbrown
duncanjbrown / core.cljs
Created December 1, 2017 16:29
Basic circle packing with ClojureScript and d3.js
(ns bubble.core
(:require [d3 :as d3]))
(enable-console-print!)
(.format d3 "d") ; we will use integers for our data
; set up a color sequence. Later on we will pass numbers to the
; 'color' function defined here and it will give us back colours one
; by one.
@duncanjbrown
duncanjbrown / decorators.js
Last active December 12, 2016 23:47
Decoration with mixins in ES6
// The object to be decorated
class Coffee {
price() {
return 10;
}
notify(message) {
console.log('coffee got a message: ' + message);
}
}
@duncanjbrown
duncanjbrown / callback.php
Created March 2, 2016 00:05
"WP API and OAuth – Using WordPress without WordPress": updated code for Guzzle 6 and latest WP-API/Oauth1
<?php
require_once 'vendor/autoload.php';
session_start();
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
@duncanjbrown
duncanjbrown / gist:5048763
Created February 27, 2013 15:30
WordPress implementation of the AfterShip API (http://aftership.com).
<?php
// could do with some DRYing up
/**
* Usage:
*
* $aftership = AfterShip::get_instance();
*
* // get the tracking info (returns WP_Error with message on failure, JSON on success)