Skip to content

Instantly share code, notes, and snippets.

@linkyndy
linkyndy / stripe.rb
Created August 15, 2018 12:22
Canceling (immediately/at period end) and reactivating Stripe subscriptions
# 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
@linkyndy
linkyndy / merge_sorted_lists.py
Created January 24, 2016 09:18
Merge 3 sorted list in a single sorted list
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]:
@linkyndy
linkyndy / insertion_sort_with_binary_search.py
Created January 16, 2016 15:13
Insertion sort based on binary search
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:
@linkyndy
linkyndy / 20150414115444_create_clients.rb
Created April 14, 2015 12:33
Working example of searching self-joined, nested models with ransack. With Rails >4.0 join is made on the wrong association while on Rails 4.0 it works as expected
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
@linkyndy
linkyndy / andrew.py
Created November 30, 2014 17:07
St. Andrew's Day Facebook Greeter
# Happy birthday, Andrew!
@linkyndy
linkyndy / stackoverflow_python_answers.md
Last active December 23, 2015 05:59
Wonderful stackoverflow.com answers involving Python