Skip to content

Instantly share code, notes, and snippets.

@garethrees
garethrees / rsync.sh
Last active July 27, 2026 20:33
rsync & scp through jump host
# Upload
rsync -av -e "ssh -A JUMP_HOST ssh" FILE_TO_SEND DEST_HOST:/home/gareth/
# Download
rsync -av -e "ssh -A JUMP_HOST ssh" DEST_HOST:~/FILE_TO_DOWNLOAD ~/Downloads/
@garethrees
garethrees / sed-delete-after-word.sh
Created August 25, 2015 19:38
sed: Delete After Word
#!/bin/sh
sed '
/ONE/ {
# append a line
N
# if TWO found, delete the first line
/\n.*TWO/ D
}' file
@garethrees
garethrees / format.sh
Created April 28, 2020 15:32
Format USB drive from the command line macOS
diskutil list
diskutil unmountDisk /dev/disk2
diskutil eraseDisk FAT32 SANDISK /dev/disk2
@garethrees
garethrees / pro_sample_data.rb
Last active May 1, 2026 11:38
Alaveteli Pro Sample Data – WARNING: Takes a few hours to run
require 'rspec/rails'
require 'factory_bot'
require Rails.root.join('spec', 'support', 'load_file_fixtures')
require Rails.root.join('spec', 'support', 'email_helpers')
RSpec.configure do |config|
config.fixture_paths = "#{::Rails.root}/spec/fixtures"
end
factory_users = User.pluck(:id) - [1,2,3,4,5,6,7]
@garethrees
garethrees / print_env_vars.rb
Created November 29, 2012 12:58
Set and print environment variables with Ruby
#!/usr/bin/env ruby
class PrintEnvVars
def initialize(a, b)
@arg1 = a
@arg2 = b
@env1 = ENV['API_KEY'] ||= 'API_KEY not found'
@env2 = ENV['PASSWORD'] ||= 'PASSWORD not found'
end
@garethrees
garethrees / gist:eee237afe19b139502c5
Last active October 14, 2025 08:08
Create bootable USB drive
# Find the USB drive
$ diskutil list
# Unmount it
$ diskutil unmountDisk /dev/diskN
# Copy the ISO to the USB drive
$ sudo dd if=/Users/gareth/debian-7.7.0-amd64-CD-1.iso of=/dev/diskN bs=8M status=progress
@garethrees
garethrees / plot.p
Last active January 14, 2024 23:21
Graphing apache benchmark results with gnuplot
# Output to a jpeg file
set terminal jpeg size 1280,720
# Set the aspect ratio of the graph
set size 1, 1
# The file to write to
set output "timeseries.jpg"
# The graph title
@garethrees
garethrees / inbox-labels.js
Last active November 6, 2023 13:07
Print all Gmail labels
// Go to the Inbox
// Unfold label menus (only labels visible to you will be collected)
// Open a console
var elementsWithDataLabel = document.querySelectorAll('[data-label-name]');
var dataLabelValues = Array.from(elementsWithDataLabel).map(el => el.getAttribute('data-label-name'));
dataLabelValues.forEach(value => {
console.log(value);
# Generate Private Key
$ openssl genrsa -out server.key 2048
# Generate CSR
$ openssl req -new -out server.csr -key server.key -config openssl.cnf
# => Fill in info
# Check CSR
$ openssl req -text -noout -in server.csr
# Sign Cert
$ openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt -extensions v3_req -extfile openssl.cnf
@garethrees
garethrees / alaveteli_pull_requests.rb
Created November 12, 2021 14:50
alaveteli_pull_requests.rb
#!/usr/bin/env ruby
require 'octokit'
require 'pp'
require 'csv'
GITHUB_TOKEN = ENV['GITHUB_TOKEN'].freeze
SINCE=ARGV[0].freeze
client = Octokit::Client.new(access_token: GITHUB_TOKEN)