Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
joeyAghion / match.rb
Created November 29, 2010 07:44
Implements the algorithm used by the National Resident Matching Program (NRMP) to match residency and fellowship applicants to programs.
# Implements the algorithm used by the National Resident Matching Program
# (NRMP) to match residency and fellowship applicants to programs. The
# algorithm is described here:
# http://www.nrmp.org/fellow/algorithm.html
# and again here:
# http://www.nrmp.org/res_match/about_res/algorithms.html
#
# The Test class computes the example match scenario described on those pages.
module Match
@joeyAghion
joeyAghion / mongodb_collection_sizes.js
Last active February 9, 2024 22:37
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
@joeyAghion
joeyAghion / heroku_apps_with_domains.sh
Created December 5, 2014 19:45
List heroku apps that I own with any associated domains.
# apps in the *first* section of heroku apps output (i.e., apps that I own)
apps=( `heroku apps | sed -e '/^$/,$d' | grep -v '^=='` )
# for each app that I own, show associated domains
for (( i = 0 ; i < ${#apps[@]} ; i++ ))
do
echo `heroku domains --app ${apps[$i]}`
done
@joeyAghion
joeyAghion / simple_redis_profile.rb
Created October 13, 2010 16:00
By sampling keys from your redis databases, this script tries to identify what types of keys are occupying the most memory.
#!/usr/bin/env ruby
# Evaluates a sample of keys/values from each redis database, computing statistics for each key pattern:
# keys: number of keys matching the given pattern
# size: approximation of the associated memory occupied (based on size/length of value)
# percent: the proportion of this 'size' relative to the sample's total
#
# Copyright Weplay, Inc. 2010. Available for use under the MIT license.
@joeyAghion
joeyAghion / patch_datadog_sidekiq_traces.rb
Created September 6, 2019 02:01
This patch is based on https://github.com/DataDog/dd-trace-rb/pull/798 and can be added (e.g., as a rails initializer) to provide more meaningful trace labels rather than `Sidekiq::Extensions::DelayedClass`.
module Datadog
module Contrib
module Sidekiq
module Tracing
def job_resource(job)
if job['wrapped']
job['wrapped']
elsif job['class'] == 'Sidekiq::Extensions::DelayedClass'
YAML.load(job['args'].first)[0..1].join('.') rescue job['class'] # rubocop:disable Security/YAMLLoad
else
> "Báe".length
=> 4
> "Báe".encoding
=> #<Encoding:UTF-8>
> "Báe".encode('utf-8', 'utf-8-mac').encoding
=> #<Encoding:UTF-8>
> "Báe".encode('utf-8', 'utf-8-mac').length
=> 3
# In most cases, script proceeds as expected:
$ ruby script.rb
................................................................................ done.
$ ruby script.rb
................................................................................ done.
# Occasionally, fails with empty results:
$ ruby script.rb
........script.rb:59:in `block (3 levels) in <main>': got a nil widget (RuntimeError)
@joeyAghion
joeyAghion / quicktime_steps_to_record_screen_and_face.md
Created September 8, 2017 17:43
Free and easy way to record screen (including slide presentations) as well as your own face (via front-facing camera) using Quicktime.
  • Open Quicktime
  • File > New Movie Recording
  • View > Float on Top
  • Resize and reposition camera view over slide as desired
  • File > New Screen Recording
  • From "record" button drop-down, ensure microphone is enabled
  • Press record button
  • Drag
  • Start recording
  • Advance slides as necessary

Keybase proof

I hereby claim:

  • I am joeyaghion on github.
  • I am joeya (https://keybase.io/joeya) on keybase.
  • I have a public key whose fingerprint is 7388 6671 6CF0 51A2 97BE 5D80 E61F 207F EE3F 0C11

To claim this, I am signing this object:

# In gravity Rails console, for example.
url = app.reset_password_url(a: 'b', c: 'd')
# => "http://www.example.com/reset_password?a=b&c=d"
url.html_safe?
# => false
ERB::Util.h(url) # explicitly call the h() helper that's implicitly called by <%= ... %>
# => "http://www.example.com/reset_password?a=b&amp;c=d"
view = ActionView::Base.new('app/views', {}, ActionController::Base.new)
# => #<ActionView::Base:0x000000110c5a60 ...>
view.render(inline: "<html><body><%= url %></body></html>", locals: {url: url}) # encode implicitly