This file contains 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 "formula" | |
class BrowsermobProxy < Formula | |
homepage "http://bmp.lightbody.net/" | |
url "https://github.com/lightbody/browsermob-proxy/releases/download/browsermob-proxy-2.1.4/browsermob-proxy-2.1.4-bin.zip", :using => :curl | |
sha1 "27c4080411adff919586e909c664c73bebb8ba8bfcaea259ce58327222e5e8fb" | |
version "2.1.4" | |
def install | |
prefix.install Dir["*"] | |
end |
This file contains 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 ActiveRecord | |
module Type | |
class Json < ActiveModel::Type::Value | |
include ActiveModel::Type::Helpers::Mutable | |
def deserialize(value) | |
value = '{}' if value.is_a?(::NilClass) | |
return value unless value.is_a?(::String) | |
ActiveSupport::JSON.decode(value) rescue nil | |
end | |
end |
This file contains 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
d |
This file contains 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 'rspec' | |
class Array | |
def flatten_ints(all=[]) | |
self.each do |item| | |
if item.class == Array | |
item.flatten_ints(all) | |
else | |
unless item.class == Fixnum | |
raise TypeError.new "This Methos is only for flattening Fixnums" |
This file contains 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] } |
This file contains 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 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 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 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 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 |
NewerOlder