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 / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@pixeltrix
pixeltrix / truffleruby-logo.svg
Last active July 27, 2021 07:30
Truffle logo in SVG with outline shadow layer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pixeltrix
pixeltrix / routes.rb
Created October 29, 2010 13:21
Examples of advanced Rails 3.0 routes
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@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)
Loading
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)
Loading
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
Loading
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.