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 / 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 / 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 / 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 / hours.rb
Created November 27, 2017 15:24
Keep a copy in your ~/bin and chmod to 755. Now, you can compute nicely rounded hours at will from the command line.
#!/usr/bin/env ruby
##
# Convert hours to invoice time, which is rounded to 6 minute increments.
time_value = ARGV.last.to_s.strip
if time_value =~ /\A[0-9]*:[0-9]*\Z/
time_elements = time_value.split(':')
minutes = time_elements.first.to_i * 60.0 + 1.0 * time_elements.last.to_f
elsif time_value.to_f > 0.0
minutes = time_value.to_f * 60.0
else
@rietta
rietta / url_validator.rb
Created July 20, 2017 13:56
Create a folder app/validators. Add this to it. Now you can do "validate :some_field, url: true" in your model validations. Works in Rails 3, 4, and 5.
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = begin
URI.parse(value.to_s).kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
unless valid
record.errors[attribute] << (options[:message] || "is an invalid URL")
describe "User can't change the ID" do
login_as user
get :show, id: other_account.id
expect(response).to have_http_status :unauthorized
expect(response.body).to_not include other_account.id
end
@rietta
rietta / hours.rb
Created September 12, 2016 19:45
Command line tool to convert hours into decimal notation suitable for invoices. 2:50 = 2.8 hours, etc.
#!/usr/bin/env ruby
##
# Convert hours to invoice time, which is rounded to 6 minute increments.
time_value = ARGV.last.to_s.strip
if time_value =~ /\A[0-9]*:[0-9]*\Z/
time_elements = time_value.split(':')
minutes = time_elements.first.to_i * 60.0 + 1.0 * time_elements.last.to_f
elsif time_value.to_f > 0.0
minutes = time_value.to_f * 60.0

The anticipated Feinstein-Burr Compliance with Court Orders Act, an anti-security bill, would require the provision of data in an intelligible format to a government pursuant to a court order (scribd.com). A draft copy has appeared online though whether it has been submitted officially within the Senate is not yet clear (vice.com).

This bill essentially says you can not have any conversation or data exchange that the government can not access if it wants to. It is the legal culmination of what the FBI has been lobbying Congress for years. If Feinstein-Burr becomes law, it will be illegal to deploy strong encryption without key escrow maintained by each company. Cryptographers and computer scientists near-unanimously assert key backup systems are insecure at scale.

@rietta
rietta / hello_world_encrypt.sql
Last active January 12, 2016 04:31
Encrypts a hello world greeting to my personal public PGP key that's published at https://keybase.io/rietta.
SELECT
ARMOR(PGP_PUB_ENCRYPT(
'Hello, World',
DEARMOR('-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mQINBFPRvdYBEACeM7pbpqxheVpIkfNSt1I//MLMmmvV/2XlJFj0z4zTOZPU5KTl
DNpfV0bHSUU5pOs9hSkM5WP+uWTAl/X5a5Ty7Vdr0r//sYNYt05ummAZQEwfaSzj
Ys57Ks1yC/31SOM/bOvWOIf/+D/GVAEuJTdfwic/Vv56ixuk8skLjWTmxBBCFpbF
dEXWyxuADvftrhaGq16xaOx0vLFxagL7mpIEjVN2yYadR5iMm1g48lAG6Tc/JEPY