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
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."
else
@rietta
rietta / random_hash.sh
Created September 5, 2012 17:01
Easy command line random hash generator for Mac OS X, Linux, and FreeBSD.
#!/bin/sh
head -n 4096 /dev/urandom | openssl sha1
@rietta
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: http://writeonly.wordpress.com/2009/03/20/adjacency-list-of-states-of-the-united-states-us/
AK
AL,MS,TN,GA,FL
AR,MO,TN,MS,LA,TX,OK
AZ,CA,NV,UT,CO,NM
CA,OR,NV,AZ
CO,WY,NE,KS,OK,NM,AZ,UT
@rietta
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:
- http://www.xent.com/FoRK-archive/oct00/0429.html
- http://www.cryptorights.org/events/2000/superpolynomial.html
For a 2000 example of how to use this song in a lecture format, see http://permalink.gmane.org/gmane.comp.encryption.general/4856 by Eric Hughes.
To the tune of Mary Poppins:
Superpolynomial subexponential runtimes.
Even though in practice it would take you several lifetimes,
@rietta
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
rietta / remove_and_reinstall_homebrew.sh
Created March 17, 2013 03:01
Reinstall Homebrew (Mac OS X)
# Thanks to http://dev.enekoalonso.com/2011/08/09/uninstalling-brew-so-i-can-reinstall/
cd `brew --prefix`
rm -rf Cellar
brew prune
rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
rm -rf ~/Library/Caches/Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
@rietta
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
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
#
# CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
# COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
#
namespace :db do
@rietta
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
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 = File.new(file_name, 'r')
if source_file and (sql_content = source_file.read)
ActiveRecord::Base.transaction do
# Each statement ends with a semicolon followed by a newline.