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
| # WORKS: | |
| def retailer | |
| ap 'fuck you ruby' | |
| @my_retailer = Cie::RetailerSettings.find_by_name(name.gsub(/((C|N)m)?Controller/, '')) if @my_retailer.nil? | |
| return @my_retailer | |
| end | |
| #DOES NOT WORK: | |
| def retailer |
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 'simple_logger' | |
| module Cie | |
| class Data | |
| @logger = defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : SimpleLogger.instance | |
| def self.connect(slave_ok) | |
| options = CIE_CONNECTION.merge(:slave_ok => slave_ok) | |
| Mongo::Connection.new(options[:server], options[:port], options).db(CIE_CONNECTION[:db_name]) | |
| 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
| require 'Benchmark' | |
| class OldFashioned | |
| def self.call(i) | |
| x = 2+i | |
| end | |
| end | |
| class NewFangled | |
| def self.call(i) |
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 Cie | |
| class Data | |
| @logger = defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : SimpleLogger.instance | |
| @wrappers = Hash.new | |
| def self.connect(slave_ok) | |
| puts "Cie::Data.connect!" | |
| @logger.debug "Regenerating #{slave_ok ? '' : 'Writable '}Writable Mongo Connection #{CIE_CONNECTION.inspect}" | |
| options = CIE_CONNECTION.merge(:slave_ok => slave_ok) | |
| options[:logger] = @logger if options[:debug] | |
| Mongo::Connection.new(options[:server], options[:port], options).db(CIE_CONNECTION[:db_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
| Each.new('foo'){|x| x.chars} # 'f' 'o' 'o' | |
| Each.new(['foo', 'bar']) | Each.new{|x| x.chars} # 'f' 'o' 'o' 'b' 'a' 'r' |
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 Evens < Stage | |
| def process | |
| value = 0 | |
| loop do | |
| output value | |
| value += 2 | |
| end | |
| 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 Hash | |
| def self.nmerge(*hashes, &block) | |
| keys = hashes.map(&:keys).flatten.uniq | |
| rhashes = hashes.reverse | |
| keys.inject({ }) do |output, key| | |
| if block | |
| output[key] = block.call(key, hashes.map{ |x| x[key]}) | |
| else | |
| rhashes.each do |hash| | |
| if hash[key] |
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
| #prone to cursor timeouts: | |
| def old | |
| thing.find(query, options).each do |item| | |
| Enumerator.new do |y| | |
| y << do_formatting_and_stuff(item) | |
| end | |
| end | |
| end | |
| #immune to cursor timeouts? the block form of find can be run with an infinite timeout cursor. |
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
| claudius = { | |
| :name => 'Claudius', | |
| :bluff => 5, | |
| :diplomacy => 7, | |
| :intimidate => 3, | |
| :perception => 1, | |
| :sense_motive => 2, | |
| :stealth => 7 } | |
| albert = { |
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
| josefrichter: guys, getting this error when trying to start mongodb on mac exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating | |
| [9:17pm] nodokodo joined the chat room. | |
| [9:18pm] josefrichter: any hints please? I'm not good at low level stuff | |
| [9:18pm] mediocretes: well, does the dbpath (/data/db) exist? | |
| [9:19pm] ascarter left the chat room. (Quit: Computer has gone to sleep.) | |
| [9:19pm] linsys: yes do this mkdir -p /data/db | |
| [9:19pm] linsys: chown -R mongodb:mongodb /data/db | |
| [9:19pm] linsys: or chown -R mongod:mongod /data/db | |
| [9:19pm] mediocretes: or put it somewhere else, if you're not comfortable with that | |
| [9:20pm] nofxx left the chat room. (Read error: Connection reset by peer) |