Skip to content

Instantly share code, notes, and snippets.

🙌
🙌

Loisaida Sam loisaidasam

Block or report user

Report or block loisaidasam

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@loisaidasam
loisaidasam / wilson.py
Last active Jul 1, 2018
Python implementation - Lower bound of Wilson score confidence interval for a Bernoulli parameter
View wilson.py
"""
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 Jul 24, 2017
Get the URL of a retriever from dog.ceo
View retriever-pic
#!/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 Jun 6, 2017
Sampling with replacement covers ~63.2% of source data
View sampling_with_replacement.py
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 Aug 10, 2017
Search for Fantasy Factory keepers from 2016 draft
View 1_results.txt
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
Get the basename for a URL or path file
View get_basename.sh
#!/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 May 3, 2017
Strip out comments/whitespace/etc. from requirements.txt
View strip-requirements.sh
#!/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 Apr 21, 2017
Clean out virtualenv - uninstall all installed libs
View clean_out_virtualenv.sh
#!/bin/bash
libs=$(pip freeze |cut -d'=' -f1)
#echo $libs
pip uninstall -y $libs
@loisaidasam
loisaidasam / README.md
Last active Apr 10, 2017
Reverse-engineering NextBus realtime data for the Atlanta Streetcar
View README.md

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 Apr 5, 2017
Get the current number of triple doubles by player (NBA)
View triple_doubles.sh
#!/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 Mar 21, 2017
numpy.savez() / load() weirdness
View writeup.md

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')
You can’t perform that action at this time.