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 move_disbursements_from_vendor_relationship_and_merge_users(from_user, to_user) | |
| ActiveRecord::Base.transaction do | |
| old_vendor_relationship = from_user.vendor_relationships.first | |
| new_vendor_relationship = to_user.vendor_relationships.first | |
| new_customer_id = new_vendor_relationship.customer_id | |
| old_disbursements = old_vendor_relationship.disbursements | |
| # Update old VR's disbursements' vendor_relationship and customer associatons |
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 balance | |
| # Works but exposes potential race condition | |
| ledger.items.where("created_at <= ?", created_at).sum(:amount_cents) | |
| # Doesn't work consistently, seems to do a string comparison of the UUIDs... | |
| #ledger.items.where("id <= ?", id).sum(:amount_cents) | |
| 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
| Deposit.find_in_batches(batch_size: 500) do |batch| | |
| GC.start | |
| batch.each { |deposit| | |
| item = deposit.ledger_item || next | |
| unless item.try(:created_at) == deposit.created_at | |
| item.update_column(:created_at, deposit.created_at) | |
| 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
| [1] pry(main)> class Animal | |
| [1] pry(main)* @@kingdom = "Animalia" | |
| [1] pry(main)* end | |
| => "Animalia" | |
| [6] pry(main)> class Dog < Animal | |
| [6] pry(main)* end | |
| => nil | |
| [7] pry(main)> Dog.class_variable_get "@@kingdom" | |
| => "Animalia" | |
| # NOTE: Not specifying the original superclass of Animalia from the original class definition of the Dog class |
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 ApplicationController | |
| private | |
| def authenticate_mt_user! | |
| # returns the resource when signed in | |
| # returns nil if not | |
| super if additional_logic_check_passes? | |
| 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
| require 'faker' | |
| class Person | |
| attr_reader :first_name, :last_name | |
| def initialize(hash_like_object = {}) | |
| @first_name = hash_like_object[:first_name] | |
| @last_name = hash_like_object[:last_name] | |
| 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
| public class BinarySearch { | |
| public static int BinarySearch(int[] a, int key) | |
| { | |
| int lo = 0, hi = a.length-1; | |
| while (lo <= hi) | |
| { | |
| int mid = lo + (hi - lo) / 2; | |
| if (key < a[mid]) hi = mid - 1; | |
| else if (key > a[mid]) lo = mid + 1; | |
| else return mid; |
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
| - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
| NSString *price = [self getDataFrom:@"https://api.coinbase.com/v1/prices/spot_rate"]; | |
| NSLog(@"The current spot price is: %@", price); | |
| [self activateStatusMenu:price]; | |
| } | |
| - (void)activateStatusMenu:(NSString *)price { | |
| _statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; | |
| NSLog(@"The status item's class is: %@", NSStringFromClass([_statusItem class])); |
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 CheckMessageStatusJob | |
| include SuckerPunch::Job | |
| def perform(status, message) | |
| @message = message | |
| previous_status = status | |
| # If status hasn't changed, it's stuck so re-send the message | |
| resend_message! if message.reload.status == previous_status | |
| 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
| rails_env = new_resource.environment["RAILS_ENV"] | |
| bitgo_env = rails_env == "production" ? "live" : "test" | |
| Chef::Log.info("Starting Bitgo proxy with Rails env of #{rails_env} and Bitgo env of #{bitgo_env}...") | |
| execute "start Bitgo proxy" do | |
| cwd release_path | |
| command "nodejs ./node_modules/bitgo/bin/bitgo-express --debug --port 3080 --env #{bitgo_env} --bind localhost" | |
| end |