Skip to content

Instantly share code, notes, and snippets.

@jarvist
jarvist / twitter_archive.py
Created August 29, 2011 17:15
Python script with Beautiful soup to rip Tweets from twitter account, prints as HTML for inclusion in webpage with Date/Time stamp
#!/usr/bin/python
#Original from here: http://code.activestate.com/recipes/576594/
#rips Tweets from twitter account, prints as HTML for inclusion in webpage with Date/Time stamp
import time
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
# Replace USERNAME with your twitter username
url = u'http://twitter.com/USERNAME?page=%s'
@rudimeier
rudimeier / .gitignore
Created September 22, 2011 09:13
comfortable shell script for running TWS
*~
*.o
@jonathan-taylor
jonathan-taylor / execute_and_save.py
Created June 8, 2012 08:09
A script to load an .ipynb file, execute all cells in order and output the resulting notebook. Depends on https://github.com/jonathan-taylor/nbconvert/tree/json2json
"""
simple example script for running notebooks and saving the resulting notebook.
Usage: `execute_and_save.py foo.ipynb [bar.ipynb [...]]`
Each cell is submitted to the kernel, and the outputs are overwritten and
stored in new notebooks foo_executed.ipynb, etc.
"""
import os,sys,time
@milktrader
milktrader / create_R_package.r
Created June 30, 2012 14:45
Create R package from commandline prompts
[~]
✈ R --silent
> boo = function(x) x*8
> boo(33)
[1] 264
> package.skeleton('boo', name='qux')
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
@harperreed
harperreed / peter-thiels-cs183-startup-class-01-notes-essay.md
Created July 29, 2012 21:20
Notes Essays—Peter Thiel’s CS183: Startup—Stanford, Spring 2012

Here is an essay version of my class notes from Class 1 of CS183: Startup. Errors and omissions are my own. Credit for good stuff is Peter’s entirely.

CS183: Startup—Notes Essay—The Challenge of the Future

Purpose and Preamble

@cjbayesian
cjbayesian / bayes_update.R
Created August 16, 2012 20:23
generate a video demonstrating Bayesian updating
## Corey Chivers, 2012 ##
sim_bayes<-function(p=0.5,N=100,y_lim=20,a_a=2,a_b=10,b_a=8,b_b=3)
{
## Simulate outcomes in advance
outcomes<-sample(1:0,N,prob=c(p,1-p),replace=TRUE)
success<-cumsum(outcomes)
for(frame in 1:N)
{
png(paste("plots/",1000+frame,".png",sep=""))
@timelyportfolio
timelyportfolio / chartTimeSeries and chartsPerformanceSummary.r
Last active August 23, 2018 00:43
plot.xts replacements of PerformanceAnalytics chart.TimeSeries and charts.PerformanceSummary
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
require(PerformanceAnalytics)
require(xtsExtra) #if you get error, please install xtsExtra from r-forge as shown in the top line
require(RColorBrewer)
#function add alpha or transparency to colors
addalpha <- function(cols,alpha=180) {
rgbcomp <- col2rgb(cols)
rgbcomp[4] <- alpha
@dsparks
dsparks / Making k-folds.R
Created September 11, 2012 01:55
Random, equally-sized partitions
# Randomly allocating observations into groups, for, e.g. cross-validation
kk <- 10 # Number of partitions, as in "kk-fold cross-validation."
# Here is a data.frame full of good data:
nn <- 1003
myData <- data.frame(matrix(rnorm(nn * 3), ncol = 3))
colnames(myData) <- LETTERS[1:3]
# This does not work:
whichK <- sample(LETTERS[1:kk], nrow(myData), replace = T)
@kroger
kroger / gist:3856749
Created October 9, 2012 05:14
Show code examples in Sphinx
from __future__ import division
import os
import sys
import codecs
import textwrap
from StringIO import StringIO
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.directives.code import LiteralInclude
from sphinx.util.nodes import set_source_info
@joshuaulrich
joshuaulrich / CBOE_csv_to_xts
Created October 19, 2012 02:15 — forked from jaredwoodard/CBOE_csv_to_xts
pulls csv files from the CBOE and converts them to xts
library(quantmod)
# we're pulling the Google VIX index (VXGOG) but this also works for VXAPL, VXGS etc.
# see http://www.cboe.com/micro/equityvix/introduction.aspx
url <- "http://www.cboe.com/publish/ScheduledTask/mktdata/datahouse/VXGOGDailyPrices.csv"
# use read.zoo to read the data directly into a zoo object
z <- read.zoo(url, header=TRUE, sep=",", skip=1, FUN=as.Date, format="%m/%d/%Y")
# convert to xts