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 BinaryIndexedTree | |
| def initialize(n) | |
| @freq = Array.new(n, 0) | |
| @btree = Array.new(n + 1, 0) | |
| end | |
| def sum(index) | |
| sum = 0 | |
| index += 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
| class BrailleReader | |
| def read(braille) | |
| # Convert [[O. .O O. O.], [.. OO OO O.], [.O .O .. OO]] [] to [O....O .OOO.O O.OO.. O.O.OO] | |
| lines = ([] << braille[0].split(' ') << braille[1].split(' ') << braille[2].split(' ')) | |
| chars = lines[0].zip(lines[1], lines[2]).map {|ch| ch.join('')} | |
| char_reader = BrailleCharReader.new | |
| chars.map {|ch| char_reader.decipher(ch)}.join | |
| 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
| # Code for Exception Anti-Pattern #1: blah rescue nil | |
| require 'time' | |
| class DoSomeWork | |
| # Bad: Fatal exceptions are swallowed up. | |
| def self.milliseconds(ms) | |
| Time.now.iso8601(ms) rescue nil | |
| end | |
| # Good: Specific about which exception we care about |
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 'json' | |
| module PrettyPrintJSON | |
| CUCUMBER_JSON_DELIMETER = '"""' | |
| def self.from_file(filename) | |
| in_json_block = false | |
| json_block = "" | |
| formatted_file = "" |
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 'set' | |
| namespace :query do | |
| task :validate => :environment do | |
| users = User.all | |
| differences = 0 | |
| failed_users = [] | |
| users.each do |u| | |
| old_apps = old_way u | |
| new_apps = u.messaging_apps |