Skip to content

Instantly share code, notes, and snippets.

View davingee's full-sized avatar

Scott Smith davingee

View GitHub Profile
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
require "rubygems"
require "time"
require 'oj'
require "awesome_print"
require 'pry'
class Parser
attr_accessor :info_hash
def initialize
@davingee
davingee / gist:8278b9f6c66f0c53f5e9
Last active December 15, 2015 22:32
Given an array of -2000 to 2000, find all the combinations of numbers that equal 10
# 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
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/)
require 'active_support/core_ext/enumerable'
require 'pry'
class ProjectEuler
attr_accessor :hash, :array
def initialize( args = {} )
self.hash = {}
self.array = []
end
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|
# 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
# 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
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
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] }