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
gem install rubocop | |
gem install htmlbeautifier |
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
json.extract! document, :id, :documentable_type, :documentable_id, :created_at | |
json.url rails_blob_url(document.doc) |
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
# Binary Search Algorithm | |
# Time Complexity = o(log n + 1) | |
# Precondition: List should be sorted | |
class BinarySearch | |
def search_func (array, to_search) | |
low = 0 | |
high = array.length - 1 | |
while low <= high |
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 'binary_search' | |
RSpec.describe BinarySearch, "#sort_func" do | |
context "with array searches the required" do | |
it "searches!" do | |
binary_search = BinarySearch.new | |
expect(binary_search.search_func([1, 2, 3, 4, 5, 6, 7, 8], 5)).to eql 4 | |
end | |
it "return string if not found" do | |
binary_search = BinarySearch.new |
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
def find_fixed_point(array) | |
n = array.length | |
high = n - 1 | |
low = 0 | |
while low <= high | |
mid = low + (high - low / 2) | |
if array[mid] == mid | |
return mid |
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
RSpec.describe BinarySearch, "#find_fixed_point" do | |
context "should have a sorted array" do | |
it "searches for the fixed point" do | |
binary_search = BinarySearch.new | |
expect(binary_search.find_fixed_point([0, 2, 3, 4, 5, 6, 7, 8])).to eql 0 | |
expect(binary_search.find_fixed_point([0, 1, 2, 4, 5, 6, 7, 8])).to eql 2 | |
end | |
it "returns -1 if not found" do | |
binary_search = BinarySearch.new | |
expect(binary_search.find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8])).to eql -1 |
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
{ | |
"rubocop": { | |
"lint": true, //enable all lint cops. | |
"only": [/* array: Run only the specified cop(s) and/or cops in the specified departments. */], | |
"except": [/* array: Run all cops enabled by configuration except the specified cop(s) and/or departments. */], | |
"forceExclusion": true, //Add --force-exclusion option | |
"require": [/* array: Require Ruby files. */], | |
"rails": true //Run extra rails cops | |
}, | |
"ruby.lint": { |
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 'HTTParty' | |
require 'Nokogiri' | |
class RubygemsScrapper | |
attr_accessor :parse_page | |
# initialize repo for ruby gems requires query string | |
def initialize(q) | |
doc = HTTParty.get("https://rubygems.org/search?query=#{q}") | |
@parse_page ||= Nokogiri::HTML(doc) |
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 'aws-sdk' | |
require 'HTTParty' | |
## This class uploads a file to s3 with public-read access and return the public url | |
class AwsUploader | |
# s3 obj after initializing the aws sdk | |
attr_reader :s3 | |
# initialization requires aws key id, secret, s3 region and s3 bucket data all are env variables |
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 spec_helper | |
--format documentation |
OlderNewer