Skip to content

Instantly share code, notes, and snippets.

def insertion_sort(a):
''' implement insertion sort'''
for i in xrange(1, len(a)):
key = a[i]
j = i - 1
while j >= 0:
if a[j] > key:
a[j], a[j+1] = a[j + 1], a[j]
j = j - 1
@Sandy4321
Sandy4321 / binom_interval.py
Last active August 29, 2015 14:27 — forked from paulgb/binom_interval.py
Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
from scipy.stats import beta
def binom_interval(success, total, confint=0.95):
quantile = (1 - confint) / 2.
lower = beta.ppf(quantile, success, total - success + 1)
upper = beta.ppf(1 - quantile, success + 1, total - success)
return (lower, upper)
@Sandy4321
Sandy4321 / scatterplotmatrix.py
Created November 9, 2015 21:34 — forked from adrn/scatterplotmatrix.py
Make a scatter-plot matrix with matplotlib
# coding: utf-8
""" Create a scatter-plot matrix using Matplotlib. """
from __future__ import division, print_function
__author__ = "adrn <adrn@astro.columbia.edu>"
# Standard library
import os, sys
@Sandy4321
Sandy4321 / passer_rating.py
Created December 16, 2015 17:38 — forked from ryanseys/passer_rating.py
Calculates the Passer Rating (passer efficiency or pass efficiency) of a player given some variables. Use at own risk, old-as-fuck code here.
# This Python application will calculate the passer rating
# (passer efficiency or pass efficiency) given the five required variables.
#
# Variables to be used as values are defined below. Set to strings so input
# can be anything. Later the strings will be converted to numbers, given
# they pass a series of error checking tests.
COMP = "null"
ATT = "null"
YARDS = "null"
@Sandy4321
Sandy4321 / buffet_basketball.R
Created December 16, 2015 21:06 — forked from cjbayesian/buffet_basketball.R
What’s Warren Buffett’s $1 Billion Basketball Bet Worth? I look into it in this post http://wp.me/p1C5UP-gF
## Warren Buffet's 1B Basketball Challenge ##
expected_value <- function(p,ngames=63,prize=1000000000){
p^ngames * prize
}
## What is the expected value of an entry
## given a particular level of prediction accuracy
expected_value(p=0.80)
expected_value(p=0.85)
@Sandy4321
Sandy4321 / nba_2014-15_heatmap
Created December 17, 2015 16:00 — forked from abresler/nba_2014-15_heatmap
NBA 2014-15 Heatmap
getBREFTeamStatTable <-
function(season_end = 2015, table_name = 'team', date = T) {
packages <-
c('rvest','dplyr','pipeR','RCurl', 'XML','reshape2', 'tidyr', 'magrittr')
lapply(packages, library, character.only = T)
base <-
'http://www.basketball-reference.com/leagues/'
season <-
(season_end - 1) %>%
paste0("-",season_end)
@Sandy4321
Sandy4321 / nba_top_50_heatmap
Created December 17, 2015 16:04 — forked from abresler/nba_top_50_heatmap
NBA 2014-15 Top 50 Scorer Heatmap
## Custom Basketball Reference Scraper Season Scraper
get_bref_player_season_stats <-
function(season.end, stat_type = c("Advanced","Totals","Per Minute","Per Game"),
team.totals = F , league = 'NBA'){
packages <-
c('rvest','magrittr','dplyr','stringr','tidyr')
lapply(packages, library, character.only = T)
bref_team_base <-
'http://www.basketball-reference.com/leagues/'
@Sandy4321
Sandy4321 / nba_14_15_datacomb.r
Created December 17, 2015 16:06 — forked from abresler/nba_14_15_datacomb.r
Quick data comb for NBA player data
source(
"https://gist.githubusercontent.com/abresler/bc5c6d8753bac661415e/raw/a9cde8afae83777f4fa32d1ac978e843f8398ee0/nba_player_data.r"
)
devtools::install_github('cmpolis/datacomb', subdir = 'pkg')
packages <-
c('datacomb', 'dplyr', 'htmlwidgets', 'magrittr')
lapply(packages, library, character.only = T)
data <-
get_bref_season_player_stats(
@Sandy4321
Sandy4321 / twitter_node_graph_rcharts
Created December 17, 2015 16:11 — forked from abresler/twitter_node_graph_rcharts
Interactive twitter node graph
require(twitteR)
require(devtools)
install_github('rCharts', 'ramnathv') ## install rCharts
require(data.table)
#Register Twitter
## A real example, but using a fictitious consumerkey and consumer
## secret - you'll need to supply your own
#register access to twitter API
@Sandy4321
Sandy4321 / tufte
Created December 17, 2015 16:12 — forked from abresler/tufte
Recreating Edward Tufte's New York City Weather Visualization
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2)
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>%
read.table() %>% data.frame %>% tbl_df -> data
names(data) <- c("month", "day", "year", "temp")
data %>%
group_by(year, month) %>%