Skip to content

Instantly share code, notes, and snippets.

@keyan
keyan / phabricator_lines_modified.js
Created January 27, 2021 21:05
Tapermonkey script that adds a text element to the top of a phabricator diff page with the total diff size. Doesn't have a +/- breakdown because that info isn't easy to access. This is to circumvent maintainers that refuse to add features, see https://secure.phabricator.com/T11768.
// ==UserScript==
// @name Show Total Number of Lines Modified in Diff
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show total number of lines modified in diff at bottom of table of contents
// @author lyahdav
// @match https://phabricator.dropboxer.net/D*
// @grant none
// ==/UserScript==
@keyan
keyan / string_hash.py
Created January 27, 2021 03:46
example of a simple hash function for strings
some_big_prime = 16908799
def hash_string(s: str) -> int:
hash_val = 0
for letter in s:
hash_val = ((127 * hash_val) + ord(letter)) % some_big_prime
return hash_val
hash_table = [None for _ in range(size_of_my_hash_table)]
value = 'foobar'

books

  • important parts of "algorithm engineering"
  • "effective c++"

lectures

  • 6.046
  • 6.889
    • lectures 1-4
    • psets 1, 2
<hmtl>
<div id="map-canvas"></div>
<style>
html, body, #map-canvas {
height: 90%;
margin: 5px;
padding: 1px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
@keyan
keyan / jfk.py
Last active February 25, 2020 21:47
stop matching
"""
python3 jfk.py
"""
from collections import namedtuple
Stop = namedtuple('Stop', ['sid', 'seq'])
stops_data = [
Stop(sid=0, seq=0),
Stop(sid=1, seq=1),
@keyan
keyan / matching.md
Created January 12, 2020 19:45
Drawing matching graphs in Latex

First include the graph drawing library tkz-berge by adding it the the \usepackage directive in the document preamble.

The follow code block produces this graph of a simple stable matching:

matching

\begin{tikzpicture}[]
\GraphInit[vstyle=Normal]
    \SetUpVertex[Math,Lpos=-180,LabelOut]
@keyan
keyan / gevent.md
Created January 7, 2020 20:54
Background processing in python

For flask servers using gunicorn, which can be configured to use any type of worker. We use gevent workers (flag -k) (which use the libuv event loop under-the-hood, see http://flask.pocoo.org/docs/0.12/deploying/wsgi-standalone/): http://docs.gunicorn.org/en/latest/settings.html#worker-class

This means we can push tasks into the gevent event loop and have them execute outside of a flask request context. As long as all the gunicorn workers aren’t processing these tasks and blocking flask request execution, this should not affect performance.

@keyan
keyan / cases.tex
Created December 13, 2019 15:26
latex cases
$$T(\omega) = \begin{cases}
1, & \text{if } \omega > \$0, \\
0, & \text{otherwise}.
\end{cases}$$
@keyan
keyan / etcd_upgrade.md
Last active October 16, 2019 06:17
Upgrading etcd cluster from APIv2 data storage to APIv3 data storage for Kubernetes

Checklist for offline etcd v2 API -> v3 API

Adapted from https://coreos.com/etcd/docs/latest/op-guide/v2-migration.html#migrate-data

Note that this strategy results in kube-apiserver downtime, but this should not affect the state of the cluster, it will only prevent changes during the migration

  • Ensure there is no v3 data in etcd as this will be overwritten during the migration, verify that the output of the following command is 0:
ETCDCTL_API=3 etcdctl get "" --from-key --keys-only --limit 1 | wc -l
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Incidents
11
14
6
39
3
9
6
1
8