I hereby claim:
- I am notahat on github.
- I am notahat (https://keybase.io/notahat) on keybase.
- I have a public key ASBqO0GTuXC19c1Vf9IeExNNmrbDfTmw47SxvTu6G-P3BAo
To claim this, I am signing this object:
| # Here's everything I have in my .zshrc to set up my PATH for homebrew and asdf: | |
| export PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
| eval "$(/opt/homebrew/bin/brew shellenv)" | |
| source $HOMEBREW_PREFIX/opt/asdf/libexec/asdf.sh | |
| # The resulting $PATH looks like this: | |
| # |
I hereby claim:
To claim this, I am signing this object:
| class PagingEnumerator < Enumerator | |
| def initialize(&block) | |
| super do |yielder| | |
| page = 0 | |
| loop do | |
| items = block.call(page) | |
| break if items.empty? | |
| items.each {|item| yielder.yield(item) } | |
| page += 1 |
| # I have a class that delegates functionality to a couple of objects that it | |
| # constructs. I want to test this in isolation. I want to make sure that the | |
| # objects are constructed with the right arguments. I also want to make sure | |
| # that the results from the objects are handled correctly. | |
| # | |
| # I'm finding it hard to structure the code and test in a way that isn't | |
| # cumbersome. What's below works, but it feels like a lot of stubbing and setup | |
| # for something the should be simpler. | |
| # | |
| # Anyone got a better approach for this? |
| class Dependency | |
| def self.foo | |
| puts "Foo" | |
| end | |
| def self.bar | |
| puts "Bar" | |
| end | |
| end |
| # Put this in spec/support | |
| # Make sure we get stack traces for controller and view exceptions. | |
| ActionController::Base.class_eval do | |
| def rescue_action_without_handler(exception) | |
| raise exception | |
| end | |
| end |
| alias λ lambda | |
| λ {|f| λ {|x| f[λ {|y| x[x][y] } ] }[λ {|x| f[λ {|y| x[x][y] }] }] }[λ {|f| λ {|n| n == 0 ? 1 : n * f[n-1] } }][6] |
| def kata(digits = [], sum = 0, has_pair = false) | |
| if sum < 15 | |
| start = (digits.last || 0) + 1 | |
| (start..9).inject([]) do |result, digit| | |
| result + | |
| kata(digits + [digit], sum + digit, has_pair) + | |
| kata(digits + [digit, digit], sum + digit + digit, true) | |
| end | |
| elsif sum == 15 && has_pair | |
| [digits] |
| def kata(digits = [], has_pair = false) | |
| if digits.inject {|sum, digit| sum + digit } == 15 | |
| has_pair ? [digits] : [] | |
| else | |
| start = (digits.last || 0) + 1 | |
| (start..9).inject([]) do |result, digit| | |
| result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true) | |
| end | |
| end | |
| end |
| # This is a replacement for Ruby's backtick operator that avoids shell | |
| # injection attacks. | |
| # | |
| # In web apps that allow file uploading, it's common to run shell commands that | |
| # operate on those files. For example, you might do this: | |
| # | |
| # `convert -resize 100x100 '#{image_filename}'` | |
| # | |
| # The problem is that a carefully crafted filename could cause trouble. |