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
// ................................ | |
// behavior in moment.js v2.x.x | |
// ................................ | |
const momentWithUndefinedArg = moment(undefined); | |
const momentWithNoArgs = moment(); | |
// expected result | |
momentWithNoArgs.isValid(); // true | |
momentWithNoArgs.format("YYYY-MM-DD"); // today's date |
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
[] + [] | |
// "" | |
[] + {} | |
// "[object Object]" | |
{} + [] | |
// 0 |
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 collections import Counter | |
import math | |
def knn(data, query, k, distance_fn, choice_fn): | |
neighbor_distances_and_indices = [] | |
# 3. For each example in the data | |
for index, example in enumerate(data): | |
# 3.1 Calculate the distance between the query example and the current | |
# example from the data. |
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 |
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
-- 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
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
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
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
" 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 |