Skip to content

Instantly share code, notes, and snippets.

@mec
mec / snippet.rb
Last active March 20, 2024 08:33
Rails default form errors
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
fragment = Nokogiri::HTML.fragment(html_tag)
field = fragment.at('input,select,textarea')
error_message = instance_tag.error_message.join(", ")
html = if field
debugger
field.add_class("is-danger")
html = <<-HTML
@mec
mec / command.md
Last active November 11, 2023 22:53
Install Ruby with OpenSSL 1.1
ruby-install ruby 3.1.4 -- --with-openssl-dir=/opt/homebrew/opt/openssl@1.1

This is for Apple Silicon, change the path to open ssl for Intel, you can find the path with brew info openssl@1.1

@mec
mec / academies_database_provisioning.md
Last active September 30, 2022 14:06
DfE Complete conversions, transfers and changes

Provision the Academies database for complete

Document the steps we took to setup the academies database.

Access to the database

The following will be required:

  • SQL server admin (sa) login or equivilent persmissions
  • The database itself to exist on the server, here the database name is sip

Create the login

@mec
mec / notes.md
Created March 25, 2022 13:08
Ruby - Prepend, Extend and Include

include will add the module after the class in the ancestor chain, can call the instance methods, you will not see the methods in ls class

prepend will add the module before the class in the ancestor chain, can call the instance methods, you will not see the methods in ls class

extend will add the module methods but not effect the ancestor chain, any methods will be added as class methods and you will see instance methods in ls class

Measuring development practice

Aims

  • Measure and monitor interval between production deploys
  • Measure and monitor how long code takes between first local commit to being live on production
  • Measure and monitor some metrics about pull requests
    • Total changes
    • Changes per commit

Dependencies

@mec
mec / no_zoom_ff_mac.md
Last active October 5, 2021 21:22
Disable touchpad zooming in Firefox on a Mac

Disable touchpad zoom in Firefox for Mac

  • open Firefox
  • type about:config in the address bar
  • search for zoom
  • set apz.allow_double_tap_zooming to false
  • set apz.allow_zooming to false
  • set apz.mac.enable_double_tap_zoom_touchpad_gesture to false

Tested in Firefox 93.0b9

@mec
mec / simple.md
Last active April 6, 2020 14:00
ffmpeg video to gif
ffmpeg -i video.mov -vf "fps=10,scale=420:-1:flags=lanczos" -loop 0 animated.gif
@mec
mec / ack_sed_find_replace.md
Created January 23, 2020 09:05
ack and sed to find and replace accross a project
ack <search term> -l --print0 | xargs -0 sed -i '' 's/<search term>/<replacement term>/g'
  • ack takes a search term, and with the -l flag, it outputs only filenames
  • --print0 separates filenames with a null byte instead of a newline. This is nice for filenames that contain spaces (non programmers!)- We take the resulting list and pipe it to xargs which will iterate over each listing and applies the following command. Note the -0 flag so that it knows to look for the null byte character
@mec
mec / development.rb
Created October 25, 2019 13:02
Rails development environment with asset pipeline in production mode
config.assets.debug = false
config.assets.compile = false
config.assets.digest = true
@mec
mec / export_obj.rb
Last active August 29, 2019 11:16
Export objects to csv from the Rails console
require 'csv'
file = "path/to/file"
CSV.open("tmp/schools_mp.csv", "wb") do |csv|
csv << School.attribute_names
School.includes(:local_authority, :local_authority_district).select(&:condition?).each do |school|
csv << school.attributes.values
end
end