Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Frank Rietta rietta

🏠
Working from home
View GitHub Profile
@rietta
rietta / remove_and_reinstall_homebrew.sh
Created Mar 17, 2013
Reinstall Homebrew (Mac OS X)
View remove_and_reinstall_homebrew.sh
# 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 / random_hash.sh
Created Sep 5, 2012
Easy command line random hash generator for Mac OS X, Linux, and FreeBSD.
View random_hash.sh
#!/bin/sh
head -n 4096 /dev/urandom | openssl sha1
@rietta
rietta / pdf_text_extractor.rb
Created Sep 14, 2020
Ruby extract plain text for PDF by wrapping pdftotext shell command.
View pdf_text_extractor.rb
# 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 Aug 8, 2020
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.
View plpgsql.rake
#
# 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 Jun 4, 2020
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.
View amex-ofx-downgrader.rb
#!/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 Mar 6, 2015
SQL Views rake task implementing `rake db:views`
View sql_views.rake
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.
@rietta
rietta / hours.rb
Created Nov 27, 2017
Keep a copy in your ~/bin and chmod to 755. Now, you can compute nicely rounded hours at will from the command line.
View hours.rb
#!/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 Jul 20, 2017
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.
View url_validator.rb
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")
View url-tweaker-abuser-story-test.rb
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 / superpolynomial.txt
Last active Oct 12, 2016
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.
View superpolynomial.txt
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,