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
| namespace :db do | |
| desc "Import production data to ENV['to'] database" | |
| namespace :import do | |
| desc "Import production db to whatever 'ENV['to']' db is set to and s3 sync" | |
| task :production => :environment do | |
| ## example rake db:import:production to=staging s3=true | |
| ## or no s3 | |
| ## example rake db:import:production to=staging |
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 "rubygems" | |
| require "time" | |
| require 'oj' | |
| require "awesome_print" | |
| require 'pry' | |
| class Parser | |
| attr_accessor :info_hash | |
| def initialize |
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
| # gem install awesome_print | |
| # gem install benchmark | |
| # gem install pry | |
| require 'awesome_print' | |
| require 'pry' | |
| require 'benchmark' | |
| # Given an array of -2000 to 2000, find all the combinations of numbers that equal 10 | |
| class SumOfEach |
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
| string = "Oversee.NET" | |
| counter = 1 | |
| string.chars.map do |ch| | |
| case counter % 3 | |
| when 0 then | |
| ch.upcase! | |
| else | |
| ch.downcase! | |
| end | |
| counter += 1 if ch.match(/\w/) |
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 'active_support/core_ext/enumerable' | |
| require 'pry' | |
| class ProjectEuler | |
| attr_accessor :hash, :array | |
| def initialize( args = {} ) | |
| self.hash = {} | |
| self.array = [] | |
| 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 Boolean | |
| end | |
| TrueClass.send :include, Boolean | |
| FalseClass.send :include, Boolean | |
| true.is_a?(Boolean) #=> true | |
| module ArrayExtensions | |
| def rpermute( possibilities = self.uniq.count, p_array = [], index = 0 ) | |
| 0.upto( possibilities - 1 ) do |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
| # You are being asked to implement classes to manage a tree of nodes. This should be done in Ruby. | |
| class TreeNode | |
| attr_accessor :value, :key, :children | |
| def initialize( args = {} ) | |
| self.value = args.fetch(:value, 1) | |
| self.key = args.fetch(:key, 'abandoned') | |
| self.children = args.fetch(:children, {}) | |
| 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
| # You are being asked to implement classes to manage a tree of nodes. This should be done in Ruby. | |
| class TreeNode | |
| attr_accessor :value, :key, :children | |
| def initialize( args = {} ) | |
| self.value = args.fetch(:value, 1) | |
| self.key = args.fetch(:key, 'abandoned') | |
| self.children = args.fetch(:children, {}) | |
| 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 'pry' | |
| require 'benchmark' | |
| require 'benchmark-memory' | |
| class User | |
| def initialize( args = {} ) | |
| raise 'user_ids needs to be an array' unless args[:user_ids].is_a?(Array) | |
| @user_ids = args[:user_ids] | |
| 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 'pry' | |
| require 'benchmark' | |
| require 'benchmark-memory' | |
| class Array | |
| def top_occurrence_0(k) | |
| counter = Hash.new{ |k, v| k[ v ] = 0 } | |
| self.each { |id| counter[ id ] += 1 } | |
| counter.sort_by{ |id, counts| -counts }[0, k].map{ |id_count| id_count[0] } |
OlderNewer