I hereby claim:
- I am alexbowe on github.
- I am alexbowe (https://keybase.io/alexbowe) on keybase.
- I have a public key ASASPBNsdnHoE-uJo2gxeVYU0sQsQnIAEG3CBPQVNtz4zgo
To claim this, I am signing this object:
| import inspect | |
| import argparse | |
| from importlib import import_module | |
| from difflib import unified_diff | |
| # If Rich is available, use it to colorize the diff. | |
| # NOTE: Users can also use other tools like `colordiff` | |
| try: | |
| from rich.console import Console |
| import requests | |
| READWISE_API_KEY = "" # Go to readwise.io/access_token | |
| def get_readwise_data(): | |
| next_page = None | |
| while True: | |
| # See https://readwise.io/api_deets for more info | |
| response = requests.get( | |
| url="https://readwise.io/api/v2/export/", |
I hereby claim:
To claim this, I am signing this object:
| ''' | |
| Interview hack: Memorize preorder/inorder/postorder tree ITERATORS (no recursion) and their reverses. | |
| It simplifies a disproportionate number of questions to simple for loops (see below). | |
| I consider the implementations below the simplest way to memorize the iterative tree traversal algorithms, | |
| because they are so similar to each other, and to their respective recursive versions. | |
| Notes: | |
| - We only visit a node after we have expanded its children (i.e. added them to the stack) in the desired order. | |
| - `x is curr` does the expanded flagging for us, because we always expand the current node. |
| # To run, from shell type: python tweet_finder.py | |
| # Must be run in the same directory as the downloaded csv file. | |
| import csv | |
| # Modify this number if you want a different nth Tweet | |
| # Should be 1-based (i.e. first tweet is the 1th, not 0th) | |
| num = 40000 | |
| # Change the path if you want to run it from a different directory | |
| path = "tweets.csv" |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <!-- http://chasen.org/~taku/software/TinySegmenter/ --> | |
| <script type="text/javascript" src="tiny_segmenter.js" charset="UTF-8"></script> | |
| <script> | |
| var segmenter = new TinySegmenter(); | |
| function countWords() { | |
| s = document.getElementById("inputText").value; |
| # here is a tidy way to get a hashable object (such as a word) to map to a unique int in python | |
| from collections import defaultdict | |
| mapper = defaultdict(lambda: len(mapper)) | |
| mapper["hello"] # 0 | |
| mapper["world"] # 1 | |
| mapper["and"] # 2 | |
| mapper["hello"] # 0 | |
| mapper["alex"] # 3 |
| /* | |
| I have read a bunch of posts about function pointers, | |
| such as http://denniskubes.com/2013/03/22/basics-of-function-pointers-in-c/ | |
| but I rarely see this *one weird trick*. | |
| It is C's (admittedly clunky) syntax for typedefing a function pointer of a given signiature. | |
| Hide the clunkiness in the typedef to keep your code tidy and maintainable. | |
| */ | |
| #include <stdio.h> |
| def gam_to_lam(c, n): | |
| i, m = 0, 0 | |
| L = [0] * n | |
| while 1: | |
| i = i+1 | |
| if c[i-1] > 0: | |
| for j in range(1, c[i-1] + 1): | |
| m = m + 1 | |
| L[m-1] = i |
| The following is an interesting problem I found in the book Introduction to Computer Theory (2nd edition), | |
| by Daniel Cohen, Wiley, 1997. See what you think ... | |
| “ In the English language, we can observe that some adjectives apply to themselves. For example, the word | |
| “short” is a fairly short word. We mighy say, “short” is short. Also, the adjective “polysyllabic” is indeed | |
| polysyllabic. Some other possible adjectives of this type are “unfrequent”, “melodious”, “arcane”, | |
| “unhyphenated”, “English”, “non-palindromic”, and “harmless”. Let us call all these adjectives that describe | |
| themselves homothetic. Let us call all other adjectives (those that do not decribe themselves) heterothetic. | |
| For example, the words “gymnastic”, “myopic”, and “recursive” are all heterothetic adjectives The word | |
| “heterothetic” is an adjective, and therefore like all adjectives it is either homothetic or heterothetic. |