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
# Canceling and reactivating Stripe subscriptions | |
# https://stripe.com/docs/billing/subscriptions/canceling-pausing#reactivating-canceled-subscriptions | |
subscription = Stripe::Subscription.create(customer: 'cus_XXX', items: [{ plan: 'XXX' }]) | |
# Cancel at period end | |
subscription.delete(at_period_end: true) | |
# Reactivate | |
subscription.cancel_at_period_end = false |
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 merge(a, b, c): | |
# Result list | |
d = [] | |
# Indices used for iterating through a, b and c | |
i = j = k = 0 | |
# Calculate lengths just once | |
lena, lenb, lenc = len(a), len(b), len(c) | |
while i < lena and j < lenb and k < lenc: | |
if a[i] <= b[j] and a[i] <= c[k]: |
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_index(x, v, left=0, right=None): | |
# Set `right` to a proper value for the first iteration | |
if right is None: | |
right = len(x) | |
while left < right: | |
mid = (left+right) // 2 | |
if v < x[mid]: | |
right = mid | |
else: |
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
class CreateClients < ActiveRecord::Migration | |
def change | |
create_table :clients do |t| | |
t.string :type | |
t.references :party, index: true | |
t.references :master_client, index: true | |
t.timestamps | |
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
# Happy birthday, Andrew! |
__call__
examples: http://stackoverflow.com/a/5824909/433940
Memoization: http://stackoverflow.com/a/5824909/433940
Singleton pattern: http://stackoverflow.com/q/6760685/433940