Skip to content

Instantly share code, notes, and snippets.

View brianhempel's full-sized avatar

Brian Hempel brianhempel

View GitHub Profile
brianhempel / remove_rightslink_images
Last active April 23, 2021 20:31
Remove ugly “RightsLink” images in PDFs from the new ACM Digital Library.
View remove_rightslink_images

Keybase proof

I hereby claim:

  • I am brianhempel on github.
  • I am brianhempel ( on keybase.
  • I have a public key whose fingerprint is 599A 31A4 A090 2699 AA81 9770 110B F56B 2900 4272

To claim this, I am signing this object:

brianhempel /
Created June 27, 2015 23:46
Compare the live Javascript with Github to insure it's not going to send your secret unencrypted or something fishy like that.
# Probably want to spoof all your headers to be just like a normal web browser
# so an attacker can't guess that you're trying to rat them out, but here's a
# start.
USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
curl -A "$USER_AGENT" -sS > send_live
curl -A "$USER_AGENT" -sS > get_live
curl -A "$USER_AGENT" -sS > send_github
curl -A "$USER_AGENT" -sS > get_github
brianhempel / bench_rails_memory_usage.rb
Last active October 6, 2022 12:47
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
View bench_rails_memory_usage.rb
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
brianhempel / enumerator_to_json.rb
Created February 17, 2015 17:32
Lazily convert an Enumerator or Enumerator::Lazy to a JSON array. Save as config/initializers/enumerator_to_json.rb
View enumerator_to_json.rb
# Natively, Enumerators get JSONized like "#<Enumerator::Lazy:0x007f8714807080>", or they explode, either of which is a problem.
# We want them to make an array, and do it lazily so we don't have to keep the items in memory!
class Enumerator
def to_json(state)
state.depth += 1
string = "[\n"
first_item = true
self.each do |item|
brianhempel / files_using_shorthand.txt
Created December 1, 2014 14:08
Usage of Ruby constructs in the ruby/ruby repo; as parsed by Ripper.sexp
View files_using_shorthand.txt
brianhempel / ruby_construct_frequencies.txt
Created November 30, 2014 20:01
Usage of Ruby constructs in the top 1000 Ruby repos on Github (by stars); as parsed by Ripper.sexp
View ruby_construct_frequencies.txt
15621016 :@ident
6122824 :var_ref
5547844 :args_add_block
4507766 :@tstring_content
4490030 :"."
4125221 :string_content
4125221 :string_literal
3757094 :call
2890433 :method_add_arg
2696463 :arg_paren
brianhempel / delete_matching_snitches.rb
Created November 10, 2014 15:32
How to delete all snitches matching a regular expression.
View delete_matching_snitches.rb
require "json"
api_key = "your api key here"
regexp = /Project X/
snitches = JSON.parse(`curl -u #{api_key}:`)
snitches.each do |snitch|
if snitch["name"] =~ regexp
puts "Deleting #{snitch["token"]} #{snitch["name"]}..."
brianhempel / has_secure_password_password_validation_bug_test.rb
Created May 16, 2014 17:07
Has_secure_password `validate :password, if: :present?` not working on an existing record
View has_secure_password_password_validation_bug_test.rb
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.1'
require 'sqlite3'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
brianhempel /
Last active April 5, 2019 05:41
A working proposal for a BREACH-safe DEFLATE compressor.