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
| Please follow this steps to install ruby | |
| 1. `brew install gnupg` | |
| 2. Install rvm | |
| - `gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB` | |
| - `\curl -sSL https://get.rvm.io | bash -s stable --ruby` | |
| - `rvm autolibs disable` | |
| - `rvm get master` | |
| 3. Install openssl | |
| - `brew install rbenv/tap/openssl@1.0` |
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 'benchmark' | |
| array = [] | |
| 1000.times { | |
| array << rand(100) | |
| } | |
| sort_count = 10_000 | |
| default_sort_time = Benchmark.realtime do |
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
| [{"id":1,"text":"Root node","children":[{"id":2,"text":"Child node 1"},{"id":3,"text":"Child node 2"}]}] |
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
| Original code | |
| def paginated(resources, per_page=Settings.pagination.default) | |
| if resources.present? | |
| unless resources.kind_of?(Array) | |
| resources = resources.page(params[:page]).per(per_page) | |
| else | |
| resources = Kaminari.paginate_array(resources).page(params[:page]).per(per_page) | |
| 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
| def sum_of_subarray(array) | |
| largest = { | |
| :sum => array[0], | |
| :start => 0, | |
| :end => 0 | |
| } | |
| (0 .. array.length-1).each do |start_at| | |
| sum = 0 | |
| start_num = array[start_at] | |
| next if largest[:sum] > start_num and start_num < 0 |
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
| # Promoter Campaigns | |
| select_blocked_campaign_of_promoter = Campaign::Campaign.joins(:user_campaign_short_links).where(["user_campaign_short_links.is_blocked = :is_blocked AND user_campaign_short_links.user_id = :user_id", {user_id: user.id, is_blocked: true}]).map(&:business_user_id) | |
| @blocked_bu_campaign_ids = Campaign::Campaign.where("business_user_id IN(?) ", select_blocked_campaign_of_promoter).map(&:id) | |
| # Influencer Campaigns | |
| select_blocked_campaign_of_influencer = Campaign::Campaign.joins(:user_campaign_short_links).where(["user_campaign_short_links.is_blocked = :is_blocked AND user_campaign_short_links.user_id = :user_id", {user_id: user.id, is_blocked: true}]).map(&:user_id) | |
| @blocked_influencer_campaign_ids = Campaign::Campaign.where("user_id IN(?)", select_blocked_campaign_of_influencer).map(&:id) |
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 EventsVersionUpdater < Struct.new(:id, :time) | |
| def perform | |
| event = Event.find(id) | |
| event.increment_version! | |
| end | |
| def schedule! options = {} | |
| event = Event.find(id) | |
| options = options.dup | |
| if run_every = options.delete(:run_every) |