Skip to content

Instantly share code, notes, and snippets.

View loisaidasam's full-sized avatar
🙌
🙌

Loisaida Sam loisaidasam

🙌
🙌
View GitHub Profile
@loisaidasam
loisaidasam / wilson.py
Last active July 23, 2019 19:18
Python implementation - Lower bound of Wilson score confidence interval for a Bernoulli parameter
"""
Python implementation - Lower bound of Wilson score confidence interval for a Bernoulli parameter
- http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
- https://news.ycombinator.com/item?id=15131611
- https://stackoverflow.com/questions/10029588/python-implementation-of-the-wilson-score-interval/45965534
- https://stackoverflow.com/questions/10029588/python-implementation-of-the-wilson-score-interval/45965534#45965534
"""
import math
@loisaidasam
loisaidasam / retriever-pic
Created July 24, 2017 18:37
Get the URL of a retriever from dog.ceo
#!/bin/bash
# Requires `curl` and `jq`
# Nice use case: $ open "$(retriever-pic)"
curl -Ss "https://dog.ceo/api/breed/retriever/images/random" | jq -r '.message'
@loisaidasam
loisaidasam / sampling_with_replacement.py
Created June 6, 2017 19:03
Sampling with replacement covers ~63.2% of source data
In [1]: import random
In [2]: import numpy as np
In [3]: SIZE = 1000000
In [4]: data = range(SIZE)
In [5]: results = []
@loisaidasam
loisaidasam / 1_results.txt
Last active August 10, 2017 15:02
Search for Fantasy Factory keepers from 2016 draft
1. David Johnson (D'Pez Poopsie) round: 1 draft_position: 8
2. Le'Veon Bell (Hyde yo kids Hyde yo wife) round: 1 draft_position: 9
3. Antonio Brown (You'll Shoot Your Eye Out!) round: 1 draft_position: 5
4. Ezekiel Elliott (Show me your Hogan) round: 1 draft_position: 4
5. Odell Beckham Jr. (Winning is not my Forte) round: 1 draft_position: 6
6. Julio Jones (Skippin Showers Switching Socks) round: 1 draft_position: 7
7. LeSean McCoy (Hyde yo kids Hyde yo wife) round: 2 draft_position: 16
8. Mike Evans (Ha Ha Cinton-Dix) round: 3 draft_position: 26
9. Jordy Nelson (CamNThBlkPnthrs Lives Matter) round: 2 draft_position: 24
10. A.J. Green (Iron Fist Commish) round: 1 draft_position: 12
@loisaidasam
loisaidasam / get_basename.sh
Last active May 24, 2017 04:31
Get the basename for a URL or path file
#!/bin/bash
# Turn a URL or path like this:
#
# "https://lastfm-img2.akamaized.net/i/u/300x300/daa535a86371482ec8fd7f3451114367.png"
#
# into this:
#
# "daa535a86371482ec8fd7f3451114367.png"
@loisaidasam
loisaidasam / strip-requirements.sh
Last active October 11, 2023 07:30
Strip out comments/whitespace/etc. from requirements.txt
#!/bin/bash
# Strip out comments/whitespace/etc. from requirements.txt
if [ -z "$1" ]
then
echo "Missing input requirements.txt dep!"
exit 1
fi
@loisaidasam
loisaidasam / clean_out_virtualenv.sh
Created April 21, 2017 20:38
Clean out virtualenv - uninstall all installed libs
#!/bin/bash
libs=$(pip freeze |cut -d'=' -f1)
#echo $libs
pip uninstall -y $libs
@loisaidasam
loisaidasam / README.md
Last active April 10, 2017 18:01
Reverse-engineering NextBus realtime data for the Atlanta Streetcar

Realtime data for the Atlanta Streetcar doesn't seem to be available via an API, and yet this page exists with a realtime map:

https://www.nextbus.com/googleMap/?a=atlanta-sc

I decided that I would reverse-engineer it, for fun.

It seems they utilize a nonce-like concept for validation, although it's not fully baked. They hard-code an initial key in the javascript of the actual pageload, which you can use for all subsequent lookups. On the actual page, they take the response key from each subsequent request and pass the new one each time along with a count variable called cnt, but in practice it seems that isn't actually required. The only limitation seems to be you have to fake the referer header.

Here's how I got it to work:

@loisaidasam
loisaidasam / triple_doubles.sh
Created April 5, 2017 16:21
Get the current number of triple doubles by player (NBA)
#!/bin/bash
# Data via https://www.espn.com/nba/statistics/player/_/stat/double-doubles/sort/tripleDouble
# Requires curl, pup, and jq
# Steps:
# 1. Download the html
# 2. Parse the html
# 3. Filter out the empty/zero rows
@loisaidasam
loisaidasam / writeup.md
Created March 21, 2017 20:50
numpy.savez() / load() weirdness

Some weirdness about saving/loading some non-array/vector datatypes (int/str/float in numpy:

In [1]: import numpy as np

In [2]: np.savez('foo.npz', my_int=5, my_float=5.0, my_vec=np.array([0.2, 0.5, 0.9]), my_str='foo on
   ...:  the bar', my_dict={'foo': 'bar'}, my_list=[1, 2, 3])

In [3]: data = np.load('foo.npz')