Skip to content

Instantly share code, notes, and snippets.

View rietta's full-sized avatar
Working from home

Frank Rietta rietta

Working from home
View GitHub Profile
rietta / batch-convert-heic.rb
Created July 6, 2021 22:47
Shell script to batch convert HEIC files to jpeg, leaving the original and its converted side by side. Requires Mac OS or Linux, the find command line tool, and ImageMagick
#!/usr/bin/env ruby
require 'shellwords'
files = `find . -iname '*.heic'`.split("\n")
files.each do |original_file|
output_file = original_file.gsub(/\.heic\z/i, ' Converted.jpg')
if File.exist?(output_file)
STDERR.puts "Skipping output #{output_file} exists."
rietta /
Created September 5, 2012 17:01
Easy command line random hash generator for Mac OS X, Linux, and FreeBSD.
head -n 4096 /dev/urandom | openssl sha1
rietta / us_states_adj.txt
Created November 19, 2012 18:17
United States' State Adjacency Lists
# Author Gregg Lind
# License: Public Domain. I would love to hear about any projects you use if it for though!
# Original location:
rietta / superpolynomial.txt
Last active November 14, 2022 01:18
Memorize the RSA encryption algorithm as a song! This is a mirrored copy of the RSA, Superpolynomial song which has become hard to find on the Internet.
These original sources are now no longer available:
For a 2000 example of how to use this song in a lecture format, see by Eric Hughes.
To the tune of Mary Poppins:
Superpolynomial subexponential runtimes.
Even though in practice it would take you several lifetimes,
rietta / fullstop.rb
Created April 13, 2021 17:43
Shell script (Ruby language) to stop all docker-compose projects in any folder on the system.
#!/usr/bin/env ruby
# Find all the directories with a docker-compose.yml file and stop the services.
# Place this file in your path, such as ~/bin/fullstop and chmod 755.
DOCKER_COMPOSE_COMMAND = 'docker-compose'.freeze
files = `locate docker-compose.yml`.split
files.each do |docker_compose_file|
next unless File.basename(docker_compose_file) == 'docker-compose.yml'
parent_directory = File.dirname(docker_compose_file)
rietta /
Created March 17, 2013 03:01
Reinstall Homebrew (Mac OS X)
# Thanks to
cd `brew --prefix`
rm -rf Cellar
brew prune
rm -rf Library .git .gitignore bin/brew share/man/man1/brew
rm -rf ~/Library/Caches/Homebrew
ruby -e "$(curl -fsSL"
rietta / pdf_text_extractor.rb
Created September 14, 2020 13:09
Ruby extract plain text for PDF by wrapping pdftotext shell command.
# frozen_string_literal: true
# Primary responsibility is extracting text from a PDF or confirming if
# text is available in the PDF.
# Security note: This simple wrapper assumes that the PDF filename that you give it has been
# chosen by an internal method, such as a tempfile name. Do not pass unsafe user supplied file names
# into this class.
rietta / plpgsql.rake
Last active August 8, 2020 15:05
Are you using PostgreSQL and don't want to make your app run as PostgreSQL super user, then add this custom rake task to your `lib/tasks` folder and be happy.
# PostgreSQL writes two optional commands to the database schema
# file, called db/structure.sql, that can only be run as a root
# database user. These are not needed actually, so comment them
# out automatically
# COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
namespace :db do
rietta / amex-ofx-downgrader.rb
Created June 4, 2020 18:48
American Express updated their online banking interface and provides an XML-based QFX format that the GnuCash updater cannot import. This Ruby script converts the new format back to the QFXSGML format that GnuCash knows how to import. Experimental; use at your own risk. It works for me.
#!/usr/bin/env ruby
# frozen_string_literal: true
# Convert new American Express QFX files (since June 2020) to older SGML format
# that GnuCash can import.
require 'nokogiri'
def show_usage
warn 'Usage: amex-ofx-downgrader.rb /path/to/source/file.qfx /path/to/output.qfx'
rietta / sql_views.rake
Created March 6, 2015 21:00
SQL Views rake task implementing `rake db:views`
namespace :db do
desc "Update and create SQL views"
task :views => :environment do
Dir["#{Rails.root}/db/sql_views/*.sql"].each do |file_name|
STDERR.puts "Applying the SQL view at #{file_name}"
source_file =, 'r')
if source_file and (sql_content =
ActiveRecord::Base.transaction do
# Each statement ends with a semicolon followed by a newline.