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 reverse_linked_list_recursive(head): | |
| if head is None: # handles empty linked list | |
| return head | |
| if head.next_node is None: # handles linked list with one node | |
| return head |
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 reverse_linked_list_recursive(head): | |
| if head is None: # handles empty linked list | |
| return head |
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 LinkedListNode: | |
| def __init__(self, value = None, next_node = None): | |
| # stores the data for the current node | |
| self.value = value | |
| # stores a reference to the next node in the linked list | |
| self.next_node = next_node |
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
| " https://jeffkreeftmeijer.com/vim-number/ | |
| " Show absolte line number for current line and | |
| " relative line number for surrounding lines | |
| set number relativenumber | |
| " Automatically toggle relative line numbers | |
| augroup | |
| autocmd! | |
| autocmd BufEnter,WinEnter,InsertLeave,FocusGained * set relativenumber |
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 Expr: | |
| def eval(self, env): | |
| raise NotImplementedError | |
| class BinaryOperator(Expr): | |
| def __init__(self, left, right): | |
| super().__init__() | |
| self.left = left | |
| self.right = right |
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 TrieNode: | |
| def __init__(self, char=None, children={}, terminal=False): | |
| self.char = char | |
| self.children = children | |
| self.terminal = terminal | |
| class Trie: | |
| def __init__(self): | |
| self.root = TrieNode() | |
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
| import heapq as heap | |
| class HQNode: | |
| def __init__(self, list_index, val_index, val): | |
| self.list_index = list_index | |
| self.val_index = val_index | |
| self.val = val | |
| def __eq__(self, other): | |
| return self.val == other.val |
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
| -- find recent queries that hit disk | |
| SELECT query, substring | |
| FROM svl_qlog join svl_query_summary using(query) | |
| WHERE starttime > date(getdate()) - interval '1 day' | |
| AND is_diskbased = 't'; | |
| -- see query execution details | |
| SELECT query, step, rows, workmem, label, is_diskbased | |
| FROM svl_query_summary | |
| WHERE query = 321925 |
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
| from knn_from_scratch import knn, euclidean_distance | |
| def recommend_movies(movie_query, k_recommendations): | |
| raw_movies_data = [] | |
| with open('movies_recommendation_data.csv', 'r') as md: | |
| # Discard the first line (headings) | |
| next(md) | |
| # Read the data into memory | |
| for line in md.readlines(): |
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
| Movie ID | Movie Name | IMDB Rating | Biography | Drama | Thriller | Comedy | Crime | Mystery | History | Label | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 58 | The Imitation Game | 8 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | |
| 8 | Ex Machina | 7.7 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | |
| 46 | A Beautiful Mind | 8.2 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 62 | Good Will Hunting | 8.3 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 97 | Forrest Gump | 8.8 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 98 | 21 | 6.8 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | |
| 31 | Gifted | 7.6 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 3 | Travelling Salesman | 5.9 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | |
| 51 | Avatar | 7.9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |