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
| def pid_path | |
| "~/tmp/pid/" | |
| end | |
| def write_pid(name) | |
| `echo "#{Process.pid}" > #{pid_path}#{name}.pid` | |
| `echo "#{Process.ppid}" > #{pid_path}#{name}.ppid` | |
| end | |
| def delete_pid(name) |
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
| # Include an anonymous module | |
| # | |
| # Useful for defining a class with a base module. So, instead of: | |
| # | |
| # class Foo | |
| # module Base | |
| # def bar | |
| # # ... | |
| # end | |
| # end |
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
| class Array | |
| def map_detect(&block) | |
| result = nil | |
| detect do |item| | |
| result = block.call(item) | |
| end | |
| result | |
| end | |
| end |
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
| def scooby | |
| `say #{yield}` | |
| end | |
| scooby do | |
| "doo-be-doo-be-doo" | |
| end |
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
| def scooby | |
| `say #{yield}` | |
| end | |
| scooby do | |
| "be-doo-be-doo" | |
| end |
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
| /* | |
| * Author: Tiffany Conroy | |
| * RE: http://twitter.com/#!/smashingmag/status/14792918153830400 | |
| * | |
| * Lots of help from here: | |
| * http://24ways.org/2010/intro-to-css-3d-transforms | |
| * http://9elements.com/html5demos/matrix3d/ | |
| * http://www.eleqtriq.com/2010/05/css-3d-matrix-transformations/ | |
| */ |
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
| Enumerable.module_eval do | |
| def with_index | |
| index = -1 | |
| map { |item| [item, index += 1] } | |
| end | |
| end | |
| ['a','x','foo'].with_index.map { |a, index| a * index } | |
| # => ["", "x", "foofoo"] |
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
| Array.class_eval do | |
| def uniq_by(&block) | |
| self & Hash[ | |
| *inject([]) do |memo, item| | |
| memo << block.call(item) << item | |
| end | |
| ].values | |
| end | |
| end |
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
| module Enumerable | |
| def and | |
| inject(true) { |memo, value| memo && value } | |
| end | |
| def or | |
| inject(false) { |memo, value| memo || value } | |
| end | |
| end |
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
| class Class | |
| def self.with_reader(name, &block) | |
| Class.new do | |
| attr_reader :"#{name}" | |
| define_method :initialize do |value| | |
| instance_variable_set("@#{name}", value) | |
| end | |
| class_eval(&block) if block_given? | |
| end | |
| end |