Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Dir.chdir('public')
Dir.glob("**/**").select {|file| File.file?(file)}.each do |file|
File.open(file, 'r').each_with_index do |line, index|
puts "#{file} #{index}: #{line}" if line.include?('I18n.t(')
end
end
@mclosson
mclosson / TriangleClassification.rb
Created July 20, 2011 20:55
Solution to Triangle Classification Challenge from http://onestepback.org/vital_testing/
require 'rspec'
class TriangleClassifier
def classify(len1, len2, len3)
lengths = [len1, len2, len3].sort
raise ArgumentError unless lengths.select {|length| length <= 0}.empty?
raise ArgumentError unless lengths[0] + lengths[1] > lengths[2]
case lengths.uniq.count
when 3 then :scalene
when 2 then :isoceles
@mclosson
mclosson / install_steps_controller.rb
Created September 7, 2011 05:14
How to obtain the installable object from a polymorphic relationship
class InstallStepsController < ApplicationController
before_filter lambda {
if params[:release_id]
@installable = Release.includes(:product).find(params[:release_id])
elsif params[:virtual_machine_id]
@installable = VirtualMachine.find(params[:virtual_machine_id])
else
redirect_to root_url
end
}
@mclosson
mclosson / application.rb
Created August 23, 2012 10:16
Return a JSON response to a malformed JSON request which throws an MultiJson::DecodeError exception in ActionDispatch before a controller is instanciated. Without this the ShowExceptions rack middleware will render an HTML error page to your JSON respons
# config/application.rb
# You must either set the following in this file or set consider_all_requests_local to false in config/environments/development.rb
config.middleware.delete ActionDispatch::DebugExceptions
@mclosson
mclosson / Console Output
Last active December 17, 2015 00:09
Example double error output for https://github.com/rails/rails/issues/10336
$ rails new issue10336
$ cd issue10336
$ rails g model guaranty name:string product_id:integer
$ rails g model product name:string
$ rake db:migrate
$ rails console
Loading development environment (Rails 4.0.0.rc1)
1.9.3-p194 :001 > g = Guaranty.new
@mclosson
mclosson / Espresso-Howto.md
Last active December 18, 2015 00:59
How to make Coffee, Lattes and Cappucinos with the Envy Labs Espresso Machine

Coffee

  • Check appropriate water level (ensure not empty)
  • Check for coffee beans (fill hopper if not full, close to lid not completely though, beans are in cabinet above)
  • Remove porta-filter from espresso machine (this is the thing which holds the coffee grounds / cakes)
  • Press Espresso on grinder to select espresso mode (its timing should be preconfigured for you)
  • Hold porta-filter under grinder and press start (angle porta-filter up to hold mess in)
  • Tap and level off coffee grindings a bit manually
  • Remove tamper from espresso machine and push it down on top of the porta-filter so the line between the black and metal is right at the top and make it level
  • Tap off flattener and return to espresso machine
require 'minitest/autorun'
require 'set'
class FiniteSet < Set
def fetch(item)
if member?(item)
delete(item)
item
end
end
require 'minitest/autorun'
class Bitlib
# Add Implementation Here
end
class Encryptor
# Add Implementation Here
end
@mclosson
mclosson / keybase.md
Last active August 29, 2015 14:05
keybase.md

Keybase proof

I hereby claim:

  • I am mclosson on github.
  • I am mclosson (https://keybase.io/mclosson) on keybase.
  • I have a public key whose fingerprint is E3D7 09DA F9F6 F3B3 0E9E 1D32 9656 6C5B 0883 A308

To claim this, I am signing this object:

# https://blog.spideroak.com/20140814060007-status-reports-transparency-overall-safety
# https://spideroak.com/canary
# https://en.wikipedia.org/wiki/Warrant_canary
# https://www.eff.org/deeplinks/2014/04/warrant-canary-faq
# https://en.wikipedia.org/wiki/National_security_letter
#
# SpiderOak now maintains a warrant canary so they can passively let their users know
# if they have been served a National Security Letter or other legal tool which
# prevents them from actively disclosing to their users that they are being coerced
# or forced into compromising the security or privacy of their userbase.