Skip to content

Instantly share code, notes, and snippets.

@dfeng
dfeng / scraper.py
Created September 7, 2012 04:18
Scraper for Fantasy Football mock drafts
import lxml.html
import requests
import csv
import os
base_url = 'http://fantasyfootballcalculator.com/'
folder = "./Drafts"
num = 1
verbose = True
@dfeng
dfeng / horsescrape.py
Created September 26, 2012 02:25
Horse Scrape
import lxml.html
from lxml import etree
import requests
import csv
import os
import datetime
base_url = 'https://gg.com/racing/'
def get_dates_interval(start,finish,format):
@dfeng
dfeng / diving.R
Created October 19, 2012 07:11
Diving Draft
# event (M3mSB, W3mSB, M10mPF, W10mPF)
# round (prelim, semi, final)
# diver (diver names)
# dcountry (hopefully the 3-character country code like USA)
# difficulty (this is a number like 3.2)
# score (scores range from 0 to 10)
# judge (the judge names, not numbers)
# jcountry (same comment applies as above)
dir <- setwd("/Volumes/HDD/Documents/Work/Current/625/Diving")
@dfeng
dfeng / regressionhorse.R
Created November 14, 2012 21:11
regression for horse problem
set.seed(10)
lm.power <- c()
spd.power <- c()
for (n in range) {
spd.pvalue <- c()
lm.pvalue <- c()
for (j in 1:1E2) {
mat <- c()
samplesize <- 1E2
for (i in 1:samplesize) {
@dfeng
dfeng / randomize.R
Last active December 11, 2015 20:58
# randomize 1:nSongs across each iteration (?)
# be aware of the songs in the basedir, so that we don't resing songs
beMarkov <- TRUE # flag: don't do previous songs
Sys.setlocale("LC_ALL", "chs")
basedir <- "D:/Karaoke/To Sing/" #"C:/Users/Susan/Dropbox"
outdir <- "D:/Karaoke/To Sing/"
addLeadZero <- function(x, n=2) {
x <- as.character(x)
@dfeng
dfeng / screenshot_interactive
Created November 14, 2013 21:57
Dropbox Screenshot (Interactive)
#!/bin/sh
FILE=$(date +%Y%m%d-%H%M%S)
cd ~/Dropbox/Public/Screenshots
screencapture -i $FILE.png
echo "https://dl.dropboxusercontent.com/u/*/Screenshots/$FILE.png" | pbcopy
@dfeng
dfeng / a.py
Created November 30, 2013 05:48
GCJ13 Round 1B a
import sys
sys.setrecursionlimit(100000)
# dynamic programming
def fun(A, motes):
# print A, motes
if A == 1:
return len(motes)
if len(motes) == 0:
return 0
@dfeng
dfeng / p60.py
Last active August 29, 2015 13:56
Derek's 60
# The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property.
# Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.
def primes(n):
ret = list()
multiples = set()
for i in xrange(2, n+1):
if i not in multiples:
ret.append(i)
@dfeng
dfeng / 60.R
Created February 8, 2014 03:03
Dana's 60
N <- 100000000
isprime <- rep(1,N)
for (i in 2:(floor(sqrt(N)))) {
if (isprime[i]==1) {
for (k in i:(floor(N/i))) {
isprime[i*k] <- 0
}
}
print(i)
}
@dfeng
dfeng / p93.py
Created February 8, 2014 20:36
Derek's 93
import itertools
# using reverse polish notation
def calculate(expr):
stack = list()
for e in expr:
if type(e) == int:
stack.append(e)
else: