Skip to content

Instantly share code, notes, and snippets.

View mhw's full-sized avatar

Mark H. Wilkinson mhw

View GitHub Profile
@joelmoss
joelmoss / post-checkout.rb
Last active October 20, 2023 09:49
Maintain branch specific databases and switch on checkout
# frozen_string_literal: true
# rubocop:disable Metrics/LineLength
require 'yaml'
require 'digest'
require 'erb'
return if ENV['NO_DB_SWITCH'] == '1'
@mareksuscak
mareksuscak / utf8mb4.sql
Last active February 23, 2024 10:23
MySQL utf8 to utf8mb4 conversion
-- adapted from https://dba.stackexchange.com/a/104866/247902
USE information_schema;
SELECT CONCAT("SET foreign_key_checks = 0;") AS _sql UNION
SELECT CONCAT("ALTER DATABASE `",table_schema,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;") AS _sql
FROM `TABLES` WHERE table_schema LIKE "<YOUR_DATABASE>" AND TABLE_TYPE='BASE TABLE' GROUP BY table_schema UNION
SELECT CONCAT("ALTER TABLE `",table_schema,"`.`",table_name,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;") AS _sql
FROM `TABLES` WHERE table_schema LIKE "<YOUR_DATABASE>" AND TABLE_TYPE='BASE TABLE' GROUP BY table_schema, table_name UNION
SELECT CONCAT("ALTER TABLE `",`COLUMNS`.table_schema,"`.`",`COLUMNS`.table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci",IF(column_default IS NOT NULL," DEFAULT \'",""),IF(column_default IS NOT NULL,column_default,""),IF(column_default IS NOT NULL,"\'",""),IF(is_nullable="YES"," NULL"," NOT NU
source "https://rubygems.org"
ruby File.read(".ruby-version").strip
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "activeadmin"
gem "activeadmin_json_editor"
gem "ahoy_email"
gem "ahoy_matey"
@pedrocarmona
pedrocarmona / something_lookup.rb
Created March 16, 2021 19:45
Polymorphic lookup - collection
class SomethingLookup < ApplicationRecord
self.table_name = 'something_lookups'
belongs_to :something, polymorphic: true
def self.load_schema!
# rubocop:disable Naming/MemoizedInstanceVariableName
@columns_hash ||= {}
# rubocop:enable Naming/MemoizedInstanceVariableName
end
// DISCLAIMER : You can now probably use `data-turbo-action="advance"` on your frame to perform what this controller is aiming to do
// https://turbo.hotwired.dev/handbook/frames#promoting-a-frame-navigation-to-a-page-visit
// Note that you probably want to disable turbo cache as well for those page to make popstate work properly
import { navigator } from '@hotwired/turbo'
import { Controller } from '@hotwired/stimulus'
import { useMutation } from 'stimulus-use'
export default class extends Controller {
connect (): void {
@al45tair
al45tair / gist:73be245ab87a66a885742b98be91ac14
Last active April 10, 2024 09:00
Files installed by Zoom for mac OS

The Zoom install package for macOS is mad. Rather than actually using the installer to install things, it does everything in the preinstall script. That's bonkers, and also means that the system won't have a list of the files it installed, because it's doing it using shell script.

The script appears to install two items, namely:

/Applications/zoom.us.app
~/Library/Internet Plug-Ins/ZoomUsPlugIn.plugin

If the user opening the package isn't an administrator, it looks like it will install the app in the user's home folder instead. If they are an administrator, Zoom will delete the ZoomUsPlugIn.plugin from /Library if it's there, but it still installs to ~/Library.

It also adds Zoom to your Dock automatically, without asking.

@chriscpritchard
chriscpritchard / tutorial.md
Last active September 9, 2024 17:44
Technicolor DWA0120 - Obtain PPPOE Password
  1. Connect to the router via ssh, the username is "engineer" and the password is the access key on the bottom of your router
  2. You will be greeted with something akin to the following:
          |                 |           o             |
          |---  ,---. ,---. |---. ,---. . ,---. ,---. |     ,---. ,---.
          |     |---' |     |   | |   | | |     |   | |     |   | |
          `---' `---' `---' `   ' `   ' ` `---' `---' `---' `---' `
                     N E X T   G E N E R A T I O N   G A T E W A Y
     --------------------------------------------------------------------
    

NG GATEWAY SIGNATURE DRINK

@darwin
darwin / readme.md
Last active April 9, 2024 22:30
APFS Container cloning/replicating under Catalina (with a bootable system)

Today I wanted to move existing APFS-resident macOS Catalina installation to a new disk. I upgraded my late 2014 Mac Mini with a shiny new 1TB SSD. This took way too many hours of my life I will never get back. Hope this saves some time to you.

Good news:

  1. it is possible to create a DMG image from existing APFS container with macOS Catalina installation including metadata needed for complete restore (the DMG contains OS, OS Data, Preboot, Recovery and VM volumes)
  2. it is possible to restore this DMG image into empty APFS container and get a bootable copy of the original system

This information is relevant for Catalina (I'm currently running macOS 10.15.1).

@hopsoft
hopsoft / prefetch.js
Last active December 27, 2023 02:45
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {
@nsommer
nsommer / time_zone_validator.rb
Created February 7, 2018 17:28
ActiveModel Validator that checks whether the string value of an attribute is a valid ActiveSupport::TimeZone
class TimeZoneValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless ActiveSupport::TimeZone[value]
record.errors[attribute] << (options[:message] || 'is not a valid time zone!')
end
end
end
# Usage with rails:
#