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 / 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
@rietta
rietta / arcdir.sh
Created October 2, 2013 04:29
Tarbar a directory and move the original to the Trash. First, install these from Hamebrew: brew install trash brew install pigz
#!/usr/bin/env bash
# Archive a directory into a compressed tar file
# and prepare a text file that lists all of the files in each archive.
###
# The trash command is OS X specific ane requires a 3rd party tool -
# brew install trash
# brew install pigz
###
@rietta
rietta / hidden.sh
Created October 2, 2013 04:26
Mac OS X, show/hide files in Finder. I keep it in ~/bin/
#!/usr/bin/env bash
if [ "$1" == "show" ]
then
echo 'Enabling hidden files in Finder'
defaults write com.apple.finder AppleShowAllFiles -bool YES
else
echo 'Turn off hidden files in Finder'
defaults write com.apple.finder AppleShowAllFiles -bool NO
fi
@rietta
rietta / arcall.sh
Created October 2, 2013 04:31
Usage: arcdir /PATH It tarball ALL subdirectories under the and moves the originals to the Trash First, install these from homebrew: brew install trash brew install pigz
#!/usr/bin/env bash
# Archive all of the children directories of a directory into compressed tar files
# and prepare a text file that lists all of the files in each archive.
# Therefore, for directories foo ane bar, produce
# foo.tar.bz2, foo.tar.txt, bar.tar.bz2, and bar.tar.txt.
###
# The trash command is OS X specific ane requires a 3rd party tool -
# brew install trash
@rietta
rietta / pngcrushall.sh
Created October 2, 2013 04:34
Aggressively compress all png files in a folder. Install the following from homebrew first:
#!/bin/sh
for png in `find $1 -name "*.png"`;
do
echo "crushing $png"
pngcrush -brute "$png" temp.png
mv -f temp.png $png
done;