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)" |
View random_hash.sh
#!/bin/sh | |
head -n 4096 /dev/urandom | openssl sha1 |
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. | |
# |
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 |
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' |
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. |
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 |
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 |
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, |
NewerOlder