__call__
examples: http://stackoverflow.com/a/5824909/433940
Memoization: http://stackoverflow.com/a/5824909/433940
Singleton pattern: http://stackoverflow.com/q/6760685/433940
__call__
examples: http://stackoverflow.com/a/5824909/433940
Memoization: http://stackoverflow.com/a/5824909/433940
Singleton pattern: http://stackoverflow.com/q/6760685/433940
# Happy birthday, Andrew! |
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 |
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: |
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]: |
# 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 |