Skip to content

Instantly share code, notes, and snippets.

@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'
<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>

books

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

lectures

  • 6.046
  • 6.889
    • lectures 1-4
    • psets 1, 2
@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}$$
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
@keyan
keyan / lost.json
Last active October 6, 2019 21:31
Script for converting MTA XML lost and found feed to JSON/XML as well as a sample converted JSON file.
{
"name": "items",
"children": [
{
"name": "Home Furnishings",
"children": [
{
"name": "Wall and Window Covering",
"value": 98
},
@keyan
keyan / appt.sh
Created August 6, 2019 18:58
bash script that curls a url every minute and outputs audio if a regex doesn't match
check_for_opening () {
res=`curl --silent "https://unionpt.fullslate.com/employees/4320?iid=7959&services%5B%5D=208" | grep "Next opening"`
if [ -n "`echo $res | grep -e '.*Thursday, September 5.*'`" ]
then
echo "No openings found, sleeping..."
else
say "Found an appointment opening"
fi
}