Skip to content

Instantly share code, notes, and snippets.

View onelharrison's full-sized avatar

Onel Harrison onelharrison

View GitHub Profile
@onelharrison
onelharrison / reverse_linked_list_recursive_one_node.py
Last active April 19, 2020 17:14
Increment of a recursive function that reverses a 0- and 1-node linked list
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
@onelharrison
onelharrison / reverse_linked_list_recursive_zero_nodes.py
Last active April 19, 2020 17:15
Increment of a recursive function that reverses an empty linked list
def reverse_linked_list_recursive(head):
if head is None: # handles empty linked list
return head
@onelharrison
onelharrison / linked_list_node.py
Created April 19, 2020 17:02
Definition of a linked list node
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
@onelharrison
onelharrison / numbertoggle.vim
Created April 13, 2020 11:27
Vimscript to enable hybrid line numbers and autotoggle relative line numbers
" 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
class Expr:
def eval(self, env):
raise NotImplementedError
class BinaryOperator(Expr):
def __init__(self, left, right):
super().__init__()
self.left = left
self.right = right
@onelharrison
onelharrison / trie.py
Last active February 20, 2020 15:50
Implementation of the Trie data structure
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()
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
@onelharrison
onelharrison / aws_redshift_queries.sql
Created February 24, 2019 23:44
Useful queries for working with AWS Redshift
-- 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
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():
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