Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
pixeltrix / time_vs_datatime.md
Last active April 23, 2025 13:36
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 / osgb36_to_wgs84.rb
Created January 27, 2025 13:32
OpenAI 4o response to being asked to generate a function to convert easting/northing to lat/lng
def osgb36_to_wgs84(easting, northing)
# Ellipsoid parameters
a_airy = 6377563.396 # Semi-major axis (Airy 1830)
b_airy = 6356256.909 # Semi-minor axis (Airy 1830)
a_wgs84 = 6378137.0 # Semi-major axis (WGS84)
b_wgs84 = 6356752.3142 # Semi-minor axis (WGS84)
# OSGB36 Helmert transformation parameters to WGS84
tx = 446.448 # Translation along X-axis (meters)
ty = -125.157 # Translation along Y-axis (meters)
@pixeltrix
pixeltrix / 01.prompt.md
Created January 27, 2025 07:55
Deepseek responses when asked to generate a function to convert OSGB36 to WGS84 co-ordinates using pure Ruby

Generate a Ruby function to convert UK Ordnance Survey OSGB36 co-ordinates to WGS84 latitude and longitude just using pure Ruby and not using a gem.

@pixeltrix
pixeltrix / 01.prompt.md
Last active January 27, 2025 07:54
Deepseek responses when asked to generate a function to convert OSGB36 to WGS84 co-ordinates

Generate a Ruby function to convert UK Ordnance Survey OSGB36 co-ordinates to WGS84 latitude and longitude

@pixeltrix
pixeltrix / 01.prompt.md
Created January 27, 2025 07:52
Deepseek responses when asked to build routes file

Generate a Ruby on Rails routes file that namespaces a resource called 'Page' under the path '/admin' and restrict it to just the index, edit and update actions.

@pixeltrix
pixeltrix / 01.prompt.md
Last active January 27, 2025 07:50
Deepseek responses when asked to build a Ruby on Rails controller

Generate a Ruby on Rails controller for a 'Page' resource that is namespaced inside a module called 'Admin'. Implement the index, edit and update actions using path parameter called 'slug' to find the correct model. For the index action sort the pages by the slug column.

@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 / 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
Loading
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)