Skip to content

Instantly share code, notes, and snippets.

@jonforums
jonforums / yahoo_pull.r
Created January 9, 2013 17:36
Simple R script to pull historical stock data from Yahoo
# Revision: 2013-01-09 12:34:09 -0600
getYahooStockUrl <- function(symbol, start, end, type="m") {
# Creates a Yahoo URL for fetching historical stock data
#
# Args:
# symbol - the stock symbol for which to fetch data
# start - the date (CCYY-MM-DD) to start fetching data
# end - the date (CCYY-MM-DD) to finish fetching data
# type - daily/monthly data indicator ("d" or "m")
@ChewingPencils
ChewingPencils / Drafts: Search Tweetbot (No Retweets)
Created January 24, 2013 13:29
-filter:retweet -"RT " lang:en
drafts://x-callback-url/import_action?type=URL&name=Search%20Tweetbox&url=tweetbot%3A%2F%2F%2Fsearch%3Fquery%3D%5B%5Bdraft%5D%5D%2520lang%253Aen%2520-filter%253Aretweet%2520-%2522RT%2520%2522
vif_func<-function(in_frame,thresh=10,trace=T,wts=NULL,...){
library(fmsb)
if(any(!'data.frame' %in% class(in_frame))) in_frame<-data.frame(in_frame)
if(is.null(wts))
wts <- rep(1, ncol(in_frame))
if(!is.null(wts))
if(length(wts)!=ncol(in_frame)) stop('length of weights must equal number of variables')
@ludwigschubert
ludwigschubert / kripp.alpha.R
Created March 17, 2013 20:39
Extraction of R's package irr's source code of Krippendorf's alpha
kripp.alpha<-function (x, method = c("nominal", "ordinal", "interval", "ratio")) {
if(missing(x))
stop("kripp.alpha(x,method=c(\"nominal\",\"ordinal\",\"interval\",\"ratio\"))\n",
"\twhere x is a classifier by object matrix of classifications or scores\n")
method <- match.arg(method)
coincidence.matrix<-function(x) {
levx<-(levels(as.factor(x)))
nval<-length(levx)
cm<-matrix(rep(0, nval * nval), nrow = nval)
dimx<-dim(x)
#---from your local---#
ssh -i yhat.pem ubuntu@your-ec2-ip-address
#---on the server---#
# let's add a user
sudo adduser greg
# update
sudo apt-get update
@wihoho
wihoho / TumblrCrawler.py
Created July 11, 2013 03:21
Crawl images from a tumblr blog
import urllib2
import urllib
from bs4 import BeautifulSoup
def processURL(url):
subEntryRequest = urllib2.Request(url, headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36'})
try:
return urllib2.urlopen(subEntryRequest).read()
except:
return None
cols <- names(train)[1:12]
system.time(clf <- randomForest(factor(quality) ~ ., data=train[,cols], ntree=20, nodesize=5, mtry=9))
# user system elapsed
# 0.366 0.006 0.372
table(test$quality, predict(clf, test[cols]))
# 3 4 5 6 7 8 9
# 3 0 0 4 5 0 0 0
# 4 0 0 35 22 1 0 0
# 5 0 0 375 137 6 1 0
@rich-iannone
rich-iannone / subset.POSIXct.R
Last active April 8, 2022 08:48
Several examples in R on creating subsets of data via a POSIXct time object.
# Create a simple data frame for testing
df <- data.frame(POSIXtime = seq(as.POSIXct('2013-08-02 12:00'),
as.POSIXct('2013-08-06 05:00'), len = 45),
x = seq(45))
# The Subset Examples
#
# All data on 2013-08-06
sub.1 <- subset(df, format(POSIXtime,'%d')=='06')
@wihoho
wihoho / 1.cpp
Created December 1, 2013 08:50
数据结构与算法 / 第2周 栈与队列 作业题
#include <iostream>
using namespace std;
struct PocketCard {
char x;
int y;
};
@wihoho
wihoho / 1.cpp
Created December 1, 2013 08:55
第3周 字符串 作业题
#include <iostream>
using namespace std;
void getResult(char str[]){
int numbers[26];
for(int j = 0; j < 26; j ++)
numbers[j] = 0;