Skip to content

Instantly share code, notes, and snippets.

View caged's full-sized avatar
🎸

Justin Palmer caged

🎸
View GitHub Profile
@caged
caged / point-diff.rb
Last active August 29, 2015 13:56
Get above/below .500 point differential for NBA teams.
#!/usr/bin/env ruby
require 'pg'
require 'pp'
require 'terminal-table'
require 'csv'
conn = PGconn.open(:dbname => 'nba')
seasons = conn.exec 'select distinct(season) from teams'
@caged
caged / toteamscsv.coffee
Created February 9, 2014 08:47
Convert raw NBA JSON to CSV.
#!/usr/bin/env coffee
fs = require 'fs'
csv = require 'csv'
extend = (object, properties) ->
for key, val of properties
object[key] = val
object
@caged
caged / syncteams.sh
Created February 9, 2014 08:46
Sync NBA team data from stats.nba.com
#!/bin/sh
for year in $(seq 1996 2013); do
shortyear=$((year+1))
season="${year}-${shortyear:2:2}"
echo "Fetching ${season}..."
for stat_type in Base Advanced Misc 'Four+Factors' Scoring Opponent; do
url="http://stats.nba.com/stats/leaguedashteamstats?Season=${season}&SeasonType=Regular+Season&LeagueID=00&MeasureType=${stat_type}&PerMode=Totals&PlusMinus=N&PaceAdjust=N&Rank=N&Outcome=&Location=&Month=0&SeasonSegment=&DateFrom=&DateTo=&OpponentTeamID=0&VsConference=&VsDivision=&GameSegment=&Period=0&LastNGames=0&GameScope=&PlayerExperience=&PlayerPosition=&StarterBench=&sortField=PTS&sortOrder=DES&pageNo=1&rowsPerPage=30"
@caged
caged / 2013-14-rank.md
Created January 26, 2014 18:12
NBA bully rankings 2013-14.

Bully - How many points better a team is vs. below .500 teams than above .500 teams. A team with a high bully factor regularly beats up on lesser teams. However, that doesn't necissarily mean they win games.

If you were -1 vs. teams above 500, and +1 vs. below 500 teams then you would have a Bully score of 2. Because you're two points better vs below 500 teams when compared to above 500 teams.

ABOVE_500_DIFF - BELOW_500_DIFF = BULLY or 1 - -1 = 2

Why is OKC at the bottom? - This is good news for OKC. They have positive point differentials against both above and below 500 teams and they beat both of those groups equally as well.

@caged
caged / queries.sql
Last active December 26, 2015 14:08
just a bookmark of random psql queries.
(select buildings.*, neighborhoods.wkb_geometry as bounding_area from buildings INNER JOIN neighborhoods ON ST_Intersects(neighborhoods.wkb_geometry, buildings.wkb_geometry) WHERE neighborhoods.name IN('LAURELHURST')) as "active-neighborhood"
--
(select or_blocks.geom, or_places.geom from or_blocks INNER JOIN or_places ON ST_Intersects(or_places.geom, or_blocks.geom) WHERE or_places.name = 'Portland') as blocks
-- gets all blocks in portland joined with race data
(select or_block_data.*, or_blocks.geom, or_places.geom from or_blocks INNER JOIN or_places ON ST_Intersects(or_places.geom, or_blocks.geom) LEFT JOIN or_block_data on or_blocks.gisjoin = or_block_data.gisjoin WHERE or_places.name = 'Portland') as blocks
-- gets all blocks in portland joined with race data percentages
@caged
caged / create-psql-database.sh
Last active March 1, 2023 06:15
Shell script to import data into Postgres from https://www.nhgis.org. If you use this, you'll need to edit line 14 to include the census data you're importing.
#!/bin/sh
# usage ./create-psql-database DATABASE
#
DB_NAME=$1
FOLDER_NAME="nhgis0004"
# Drop and recreate database
dropdb --interactive "${DB_NAME}"
createdb --encoding UTF8 $DB_NAME
@caged
caged / parks.json
Last active December 23, 2015 12:19
Portland parks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caged
caged / portland-blockgroups.json
Last active December 23, 2015 11:39
Portland blockgroup TopoJSON
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caged
caged / tilemill.sql
Created September 14, 2013 00:43
Tilemill PostGIS layer subquery showing layer clipping via polygon intersection.
(select buildings.*, neighborhoods.wkb_geometry as bounding_area from buildings INNER JOIN neighborhoods ON ST_Intersects(neighborhoods.wkb_geometry, buildings.wkb_geometry) WHERE neighborhoods.name IN('LAURELHURST')) as buildings
@caged
caged / README.md
Last active March 11, 2023 18:50 — forked from mbostock/.block
Using d3-tip to add tooltips to a d3 bar chart