This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Usage: | |
| # Example command ./coverflowify.rb source.png 30 20 50 true output.png | |
| # | |
| # The values are: | |
| # * shrink percent - specifies by how much percent to shrink the background images | |
| # * skew percent - specifies how much 3d rotation (inward) to give background images | |
| # * visible percent - specifies how much of background images stick out on left and right | |
| # * add_shadow - if true, adds default shadow, also accepts full shadow spec, like "70x4+5+5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'minitest/autorun' | |
| class FooTest < MiniTest::Unit::TestCase | |
| def test_foo | |
| assert_equal('0x0', '0x1') | |
| end | |
| end | |
| # Running tests: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> GC.disable | |
| => false | |
| >> | |
| >> def foo | |
| >> file = Tempfile.new('test') | |
| >> file.path | |
| >> end | |
| => nil | |
| >> | |
| >> path = foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = { foo: 'foo', bar: 'bar' } | |
| b = { foo: 'fooo' } | |
| # Reconcile duplicate keys | |
| a.merge(b) {|k, old_v, new_v| [old_v, new_v].min} | |
| # => { foo: 'foo', bar: 'bar' } | |
| # Ever wanted Hash#map to return a hash? This is a workaround | |
| a.merge(a) {|k, v| v.upcase} | |
| # => { foo: "FOO", bar: "BAR" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> obj = Object.new | |
| => #<Object:0x007ff6bd6b07e0> | |
| >> def obj.to_hash; { bar: 'bar' } end | |
| => nil | |
| >> { foo: 'foo' }.merge(obj) | |
| => {:foo=>"foo", :bar=>"bar"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ["a b.c d.e"[/\.(\S+)$/, 1].split('.'), $`].reverse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Something like this in initializer | |
| Paperclip.interpolates(:s3_eu_url) { |attachment, style| | |
| "#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}" | |
| } | |
| # And then this in attachment options | |
| url: ':s3_eu_url', | |
| storage: :s3, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if Rails.env.development? | |
| module Kernel | |
| def with_query_trace | |
| Rails.backtrace_cleaner.add_silencer do |line| | |
| line.include?('query_trace.rb') | |
| end | |
| callback = lambda do |*args| | |
| bt = Rails.backtrace_cleaner.clean(caller[1..-1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| # This script is an astonishing feat of top notch | |
| # rockstar craftsmanship. It totally uses artificial | |
| # intelligence to extract colors out of tmTheme and | |
| # build an itermcolors scheme file for iTerm2. | |
| # | |
| # I know this sounds crazy, but it actually knows | |
| # approximately what colors should be used in the | |
| # ANSI list, and tries to find nearest colors from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is an example of how to use database_cleaner gem and | |
| # RSpec tags to make `after_commit` hook play nice with | |
| # `use_transactional_fixtures`. | |
| # Simply mark the specs that use after_commit with | |
| # `:uses_after_commit` tag. | |
| # ... | |
| require 'database_cleaner' |