Skip to content

Instantly share code, notes, and snippets.

View pixeltrix's full-sized avatar

Andrew White pixeltrix

View GitHub Profile
@pixeltrix
pixeltrix / mapping.rb
Created April 11, 2024 06:54
Utility functions for converting between OSGB36 and WGS84 co-ordinates
module Mapping
module Utilities
module NationalGrid
# All the values and formula are from the Ordnance Survey publication:
# A guide to coordinate systems in Great Britain
# https://www.ordnancesurvey.co.uk/documents/resources/guide-coordinate-systems-great-britain.pdf
# Scale factor on the central meridian for the Transverse Mercator projection
# https://en.wikipedia.org/wiki/Transverse_Mercator_projection
F0 = 0.9996012717
@pixeltrix
pixeltrix / truffleruby-logo.svg
Last active July 27, 2021 07:30
Truffle logo in SVG with outline shadow layer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / activations_controller.rb
Last active May 26, 2020 10:15
Example of a 'service' object
class ActivationsController < ApplicationController
respond_to :json
def create
new_password = params[:user] && params[:user][:password]
token = params[:confirmation_token]
if !new_password
render_errors({"password"=>["can't be blank"]}.to_json)
@pixeltrix
pixeltrix / anpr.rb
Created May 13, 2020 10:21
Match one of three number plate patterns
formats = [
"[A-Z]{2}[0-9]{2}[A-Z]{3}",
"[A-Z]{1}[0-9]{3}[A-Z]{3}",
"[A-Z]{3}[0-9]{3}[A-Z]{1}"
]
pattern = /\A#{formats.join("|")}\z/
candidates = %w[
RF10AK0
@pixeltrix
pixeltrix / welsh-constituencies.topojson
Created May 11, 2020 16:09
Welsh Electoral Constituencies (TopoJSON Format)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / welsh-regions.topojson
Created May 11, 2020 16:06
Welsh Electoral Regions (TopoJSON Format)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / welsh-constituencies.geojson
Created May 11, 2020 16:03
Welsh Electoral Constituencies
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / welsh-regions.geojson
Last active May 11, 2020 16:00
Welsh Electoral Regions
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / sonar.rb
Last active May 9, 2020 21:53
Ruby implementation of the NHS contact tracing app's messages and how they're decrypted
require "openssl"
require "securerandom"
##########################
### iOS/Android Device ###
##########################
# Installation id - returned by the registration request
uuid = "E1D160C7-F6E8-48BC-8687-63C696D910CB"
uuid_bytes = uuid.scan(/[0-9A-Z]{2}/).map { |s| s.to_i(16) }.pack("C*")
@pixeltrix
pixeltrix / markdown_helper.rb
Last active April 13, 2020 11:19
Stub out requests to GOV.UK Notify, convert them into Mail::Message instances and stash them into ActionMailer::Base.deliveries
# app/helpers/markdown_helper.rb
require "redcarpet/render_strip"
module MarkdownHelper
HTML_DEFAULTS = {
escape_html: false, filter_html: false,
hard_wrap: true, xhtml: true, safe_links_only: true,
no_styles: true, no_images: true, no_links: false,
with_toc_data: false, prettify: false, link_attributes: {}
}