Skip to content

Instantly share code, notes, and snippets.

View LeoMcA's full-sized avatar

Leo McArdle LeoMcA

View GitHub Profile
- git clone https://github.com/LeoMcA/discourse-auth0-mozilla.git
- cd discourse-auth0-mozilla
- git checkout 2de31ec2442c4dabf4fc2561b6413b4651af65d4
- cd ../
@LeoMcA
LeoMcA / migrate_bucket.rb
Last active January 24, 2017 11:29
Mozilla Discourse: migrate images from old bucket to new
PostUpload.all.each do |post_upload|
Jobs.enqueue(:pull_hotlinked_images, post_id: post_upload.post.id) unless post_upload.post.nil?
end
@LeoMcA
LeoMcA / setup-local-remotes.sh
Created June 7, 2017 07:51
Setup git remotes for easy pushing like you're fetching
#!/bin/sh
echo "What should this computer be called?"
read this_name
echo "What should the other computer be called?"
read that_name
echo "What's the hostname of the other computer?"
read that_hostname
echo "What's the path to the respository on this computer?"
read this_path
@LeoMcA
LeoMcA / discourse-category-statistics.sql
Last active July 2, 2018 09:34
Get notification level statistics for a Discourse category
SELECT replace(replace(replace(replace(replace(cast(notification_level AS varchar), '0', 'muted'), '1', 'regular'), '2', 'tracking'), '3', 'watching'), '4', 'watching first post') AS notification_level, count(*) FROM category_users WHERE category_id=(SELECT id FROM categories WHERE slug='development' AND parent_category_id=(SELECT id FROM categories WHERE slug='add-ons' AND parent_category_id IS NULL)) GROUP BY notification_level;
@LeoMcA
LeoMcA / nightly.desktop
Last active May 11, 2020 16:25
Firefox Nightly .desktop file
[Desktop Entry]
Version=1.0
Name=Nightly
GenericName=Web Browser
Comment=Browse the Web
Exec=/home/leo/.local/bin/nightly -P default-nightly %u
Icon=/home/leo/.local/share/nightly/browser/chrome/icons/default/default128.png
Terminal=false
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
@LeoMcA
LeoMcA / decrypt.rb
Created January 13, 2019 19:58
decrypt rails session cookie (kinda)
require 'cgi'
require 'active_support'
require 'json'
# def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
# cookie = CGI::unescape(cookie)
# # salt = 'authenticated encrypted cookie'
# salt = Rails.application.config.action_dispatch.encrypted_signed_cookie_salt
# encrypted_cookie_cipher = 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer
@LeoMcA
LeoMcA / reverse_and_collate.sh
Created April 14, 2019 15:22
Collate two pdfs into one, with the second one reversed
#!/bin/sh
A= B= ; qpdf --empty --collate --pages $A $B z-1 -- out.pdf
@LeoMcA
LeoMcA / uk-eu-election-2019-result.js
Created May 26, 2019 22:53
Scrapes UK EU Election Data from BBC website, and adds up Leave and Remain (and Labour) votes
const fetch = require("node-fetch")
const cheerio = require("cheerio")
const url = "https://www.bbc.co.uk/news/topics/crjeqkdevwvt/the-uks-european-elections-2019"
var leave = [{ name: "Leave", value: 0 }]
var remain = [{ name: "Remain", value: 0 }]
var lexit = [{ name: "???", value: 0 }]
var other = [{ name: "Other", value: 0 }]
@LeoMcA
LeoMcA / netflix-zoom.js
Created August 31, 2019 09:20
Zoom letterboxed Netflix content on an ultrawide display
// paste in console, give aspect ratio as the argument, here 2.2 is the aspect ratio of the source material
(x => document.querySelector(".VideoContainer video").style.height = `${x * 9 / 16 * 100}%`)(2.2)
@LeoMcA
LeoMcA / mozilla.rake
Last active September 4, 2019 11:12
Migrate references to one s3 bucket to another on Discourse
# frozen_string_literal: true
# paste this file into /var/www/discourse/lib/tasks/mozilla.rake
# then run it with: rake mozilla:rebake_posts_with_upload["example.s3.dualstack.us-west-2.amazonaws.com"]
require "db_helper"
require "file_store/s3_store"
task "mozilla:rebake_posts_with_upload", [:s3_host] => :environment do |t, args|
s3_host = args[:s3_host]