Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew White pixeltrix

View GitHub Profile
@pixeltrix
pixeltrix / activations_controller.rb
Last active May 26, 2020
Example of a 'service' object
View activations_controller.rb
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
Match one of three number plate patterns
View anpr.rb
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
Welsh Electoral Constituencies (TopoJSON Format)
View welsh-constituencies.topojson
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
Welsh Electoral Regions (TopoJSON Format)
View welsh-regions.topojson
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
Welsh Electoral Constituencies
View welsh-constituencies.geojson
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
Welsh Electoral Regions
View welsh-regions.geojson
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
Ruby implementation of the NHS contact tracing app's messages and how they're decrypted
View sonar.rb
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 Apr 13, 2020
Stub out requests to GOV.UK Notify, convert them into Mail::Message instances and stash them into ActionMailer::Base.deliveries
View markdown_helper.rb
# 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: {}
}
@pixeltrix
pixeltrix / signals.json
Created Mar 24, 2020
List of signals on Ubuntu 18.04 / Ruby 2.6.5
View signals.json
{
"EXIT": 0,
"HUP": 1,
"INT": 2,
"QUIT": 3,
"ILL": 4,
"TRAP": 5,
"ABRT": 6,
"IOT": 6,
"FPE": 8,
@pixeltrix
pixeltrix / migration_status.rb
Created Aug 30, 2019
Glue code required to get an Active Record rake task working outside of Rails
View migration_status.rb
require 'rake'
require 'active_record'
require 'erb'
require 'yaml'
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [File.expand_path('db/migrate')]
module Rails
def self.env
'development'