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
| """Classic interview question to check if two words are anagram.""" | |
| import collections | |
| import itertools | |
| import pytest | |
| def is_anagram(first: str, second: str) -> bool: | |
| """Implementation of anagram checker with 3 different methods. | |
| Note: |
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
| " File: ~/.vimrc | |
| " | |
| " Author: Victor I. Afolabi | |
| syntax enable | |
| colorscheme desert | |
| " highlight Normal guibg=none | |
| " ============================================================================= |
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
| // Author: Victor I. Afolabi | |
| // Implementing the Fibonacci series using Rust's Iterator | |
| #[derive(Debug, PartialEq, PartialOrd)] | |
| pub struct Fib { | |
| current: usize, | |
| next: usize, | |
| } | |
| impl Fib { |
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
| // Author: Victor I. Afolabi | |
| // | |
| // Exploring Iterator Traits in Rust to implement Flatten functionality of 2D-iterators. | |
| // | |
| pub trait IteratorExt: Iterator { | |
| fn flatten_ext(self) -> Flatten<Self> | |
| where | |
| Self: Sized + std::fmt::Debug, | |
| Self::Item: IntoIterator, |
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
| """ | |
| # Tokenizers | |
| Provides an implementation of today's most used tokenizers, with a focus on performance and versatility. | |
| ## Main features: | |
| - Train new vocabularies and tokenize, using today's most used tokenizers. | |
| - Extremely fast (both training and tokenization), thanks to the Rust implementation. Takes less than 20 seconds to tokenize a GB of text on a server's CPU. | |
| - Easy to use, but also extremely versatile. |
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
| /// Computes the greatest common divisor of two integers using Euclid's algorithm | |
| /// (https://en.wikipedia.org/wiki/Euclidean_algorithm). | |
| /// | |
| /// # Example | |
| /// | |
| /// ```rust | |
| /// assert_eq!(gcd(3, 5), 1); | |
| /// | |
| /// assert_eq!(gcd(2 * 3 * 5 * 11 * 17, 3 * 7 * 11 * 13 * 19), 3 * 11); | |
| /// ``` |
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
| """ | |
| # Using Python's `collections.defaultdict`. | |
| ```python | |
| >>> import collections | |
| >>> dct = collections.defaultdict(int) | |
| >>> int() | |
| 0 | |
| >>> dct['a'] | |
| 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
| import sys | |
| import time | |
| import multiprocessing as mp | |
| DELAY = 0.1 | |
| DISPLAY = ['|', '/', '-', '\\'] | |
| def spinner_fn(before='', after=''): | |
| write, flush = sys.stdout.write, sys.stdout.flush | |
| pos = -1 |
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 time | |
| def power(base, exp): | |
| """Implement the `pow(...)` function recursively.""" | |
| # Base case. | |
| if exp == 0: | |
| return 1 | |
| elif exp == 1: | |
| return base | |
| # Compute: a^b = a^(c+d) = (a^c) * (a^d) |
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
| """Convert the text/attention list to latex code, | |
| which will further generates the text heatmap based on attention weights. | |
| """ | |
| import numpy as np | |
| latex_special_token = ["!@#$%^&*()"] | |
| def generate(text_list, attention_list, latex_file, color='red', rescale_value = False): | |
| assert(len(text_list) == len(attention_list)) |