Skip to content

Instantly share code, notes, and snippets.

Avatar

Leo McArdle LeoMcA

View GitHub Profile
@LeoMcA
LeoMcA / mozilla.rake
Last active Sep 4, 2019
Migrate references to one s3 bucket to another on Discourse
View mozilla.rake
# 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]
@LeoMcA
LeoMcA / netflix-zoom.js
Created Aug 31, 2019
Zoom letterboxed Netflix content on an ultrawide display
View netflix-zoom.js
// 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 / uk-eu-election-2019-result.js
Created May 26, 2019
Scrapes UK EU Election Data from BBC website, and adds up Leave and Remain (and Labour) votes
View uk-eu-election-2019-result.js
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 / reverse_and_collate.sh
Created Apr 14, 2019
Collate two pdfs into one, with the second one reversed
View reverse_and_collate.sh
#!/bin/sh
A= B= ; qpdf --empty --collate --pages $A $B z-1 -- out.pdf
@LeoMcA
LeoMcA / decrypt.rb
Created Jan 13, 2019
decrypt rails session cookie (kinda)
View decrypt.rb
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 / nightly.desktop
Last active May 11, 2020
Firefox Nightly .desktop file
View nightly.desktop
[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 / discourse-category-statistics.sql
Last active Jul 2, 2018
Get notification level statistics for a Discourse category
View discourse-category-statistics.sql
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 / setup-local-remotes.sh
Created Jun 7, 2017
Setup git remotes for easy pushing like you're fetching
View setup-local-remotes.sh
#!/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 / migrate_bucket.rb
Last active Jan 24, 2017
Mozilla Discourse: migrate images from old bucket to new
View migrate_bucket.rb
PostUpload.all.each do |post_upload|
Jobs.enqueue(:pull_hotlinked_images, post_id: post_upload.post.id) unless post_upload.post.nil?
end
View gist:0e92073d37c23c695c5d9b66f80f171a
- git clone https://github.com/LeoMcA/discourse-auth0-mozilla.git
- cd discourse-auth0-mozilla
- git checkout 2de31ec2442c4dabf4fc2561b6413b4651af65d4
- cd ../