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
-- This function is designed to duplicate all live INSERTS/UPDATES/DELETES from one table (referred to as "source_table_name" | |
-- to a second partitioned table (referred to as "destination_table_name"). The function should be set to trigger after insert/ | |
-- update/delete on the source table. | |
-- This function is designed to be leveraged for partitioned table migration through this method: | |
-- 1) Create an empty partitioned copy of the "source_table_name". Alter primary key as necessary, as partitioned Postgres | |
-- tables do not support unique/primary keys not included in the partition key. | |
-- 2) Create the following function, and attach it as a trigger to "source_table_name". At this point, incoming new DML is | |
-- being copied successfully to the partitioned table, so only historical data will need to be backfilled. | |
-- 3) Target rows in "source_table_name" with an updated_at value BEFORE the trigger was attached, and backfill them into |
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
### Keybase proof | |
I hereby claim: | |
* I am chelseadole on github. | |
* I am pikachel (https://keybase.io/pikachel) on keybase. | |
* I have a public key ASCdQzswDouhiWSRmylpp4tFutSDuoAzdgg2kCup7NMHXAo | |
To claim this, I am signing this object: |
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
""" | |
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. | |
M = width | |
N = height | |
""" | |
def zero_matrix(matrix): | |
zero_cols = set() | |
zero_rows = set() | |
for lst in matrix: |
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
"""Add Linked Lists of Numbers.""" | |
def add_lists(list1, list2): | |
"""Function to create new LL based off sums of both other LLs.""" | |
added_link = LinkedList() | |
temp = [] | |
leftover = 0 | |
while list1.head is not None and list2.head is not None: | |
if list1.head: | |
val_1 = list1.pop() |
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
"""Gist to organize LinkedList. All vals higher than x go after "x", all vals lower go before.""" | |
# NOTE: I'm not totally sure these work... there was an issue with my LinkedList and I wasn't able to properly test | |
# This version is solved using lists: | |
def org_list(x, link): | |
""".""" | |
new_list = LinkedList() | |
while link.head is not None: |
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 anagram(word1, word2): | |
"""Check if word1 and word2 are anagrams.""" | |
listed_w1, listed_w2 = list(word1), list(word2) | |
sorted_w1, sorted_w2 = listed_w1.sort(), listed_w2.sort() | |
if listed_w1 == listed_w2: | |
return True | |
return 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 parse_query(query): | |
query_dictionary = {} | |
split_query = query[1:].split('&') | |
for item in split_query: | |
item_key, item_val = item.split('=')[0], item.split('=')[1] | |
if item_key not in query_dictionary: | |
query_dictionary[item_key] = item_val | |
elif item_key in query_dictionary: | |
prev_contents = query_dictionary[item_key] | |
query_dictionary[item_key] = [prev_contents] |