Skip to content

Instantly share code, notes, and snippets.

View mharris717's full-sized avatar

Mike Harris mharris717

View GitHub Profile
load "lib/baseball_lottery.rb"
MGC.connect! :production
def big_hash
res = {}
(1..100).each do |i|
res[i] = {}
50.times do
res[i][rand(100000000000)] = rand(1000000000000).to_s
end
@mharris717
mharris717 / ufc.R
Created October 13, 2014 17:17
Parse UFC
library(rvest)
page <- html("http://www.sherdog.com/events/UFC-Fight-Night-MacDonald-vs-Saffiedine-35509")
rows <- page %>%
html_nodes("tr[itemprop=subEvent]")
for (row in rows) {
names <- row %>%
html_nodes("span[itemprop=name]") %>%
html_text()
@mharris717
mharris717 / Kill-The-Loop-Man.R
Created October 16, 2014 21:31
We must kill the Loop .... Man.
# pretending to fetch HTML
getBody <- function(url) {
if (url == "http://garbage.broken") return(0)
else return(paste("this is the html for ",url))
}
sites.names <- c("Google","ESPN","Garbage","ROK")
sites.urls <- c("http://google.com","http://espn.com","http://garbage.broken","http://returnofkings.com")
sites.df <- data.frame(Name=sites.names, Url=sites.urls, stringsAsFactors=FALSE)
import Ember from 'ember';
import Mixin from './../../mixins/pagination';
export
default Ember.ArrayController.extend(Mixin, {
// setup our query params
queryParams: ["page", "perPage", "filter", "order"],
// setup orders
selOrders: [{
label: 'Recente',
value: 'created_at-asc'
import Ember from 'ember';
export default Ember.Mixin.create({
changeOrder: function() {
this.get('model').setOtherParam('order',this.get('order'));
}.observes('order')
});
@mharris717
mharris717 / Highlights.md
Last active August 29, 2015 14:10
Ember NYC Lightning Talk

2.5 Addons and a Call for Help.

Ember CLI Pagination

Pagination Addon for Ember CLI.

Great documentation and test coverage.

Supports multiple types of pagination

@mharris717
mharris717 / scrape.rb
Created January 16, 2015 18:28
scrape.rb
require 'open-uri'
require 'nokogiri'
def links
res = []
doc = Nokogiri::HTML(open("http://www.perfectgame.org/Rankings/Players/Default.aspx?gyear=2015&num=500"))
doc.css("tr.ranking_row, tr.ranking_alt_row").each do |row|
row.css("td:eq(4) a").each do |link|
res << link.attr('href')
@mharris717
mharris717 / players.rb
Last active August 29, 2015 14:14
players.rb
require 'nokogiri'
require 'open-uri'
def players
list_of_players = []
f = File.open("PGpage.htm")
doc = Nokogiri::HTML(f)
rows = doc.css("tr.ranking_row a text(), tr.ranking_alt_row")
1153 Sure Gamble (Core Set)
1086 Hedge Fund (Core Set)
963 Jackson Howard (Opening Moves)
625 Corroder (Core Set)
593 Same Old Thing (Creation and Control)
586 Clone Chip (Creation and Control)
560 R&D Interface (Future Proof)
533 Diesel (Core Set)
529 Plascrete Carapace (What Lies Ahead)
526 NAPD Contract (Double Time)
@mharris717
mharris717 / home_chance.rb
Last active August 29, 2015 14:25
Home Chance
# the home team's win chance for a normal team not at a neutral field
def home_chance_normal(sim_context,away_team_arg,home_team_arg)
# away team dvoa, minus 5% if it's the divisional round
away = sim_context.dvoa(away_team_arg) - home_extra_bonus.to_f
# home team dvoa, capped at 40%
home = [0.40,sim_context.dvoa(home_team_arg)].min
# min_max(-0.35..0.35) restricts the value to between -35% and 35%
# abs_exp(2) squares it and returns the absolute value