This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image, ImageDraw | |
def get_colors(infile, outfile, numcolors=10, swatchsize=20, resize=150): | |
image = Image.open(infile) | |
image = image.resize((resize, resize)) | |
result = image.convert('P', palette=Image.ADAPTIVE, colors=numcolors) | |
result.putalpha(0) | |
colors = result.getcolors(resize*resize) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Automate Chunks of Analysis in R Markdown | |
======================================================== | |
```{r setup, echo=FALSE} | |
library(knitr) | |
library(DT) | |
``` | |
```{r create-datasets, echo=FALSE} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(proto) | |
stat_smooth_func <- function (mapping = NULL, data = NULL, geom = "smooth", position = "identity", | |
method = "auto", formula = y ~ x, se = TRUE, n = 80, fullrange = FALSE, | |
level = 0.95, na.rm = FALSE, ...) { | |
StatSmoothFunc$new(mapping = mapping, data = data, geom = geom, position = position, | |
method = method, formula = formula, se = se, n = n, fullrange = fullrange, | |
level = level, na.rm = na.rm, ...) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plot.xts with horizons | |
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org") | |
require(PerformanceAnalytics) | |
require(quantmod) | |
require(xtsExtra) #if you get error, install xtsExtra from r-forge | |
horizon.panel <- function(index,x,...) { | |
#get some decent colors from RColorBrewer | |
#we will use colors on the edges so 2:4 for red and 7:9 for blue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def split(filehandler, delimiter=',', row_limit=10000, | |
output_name_template='output_%s.csv', output_path='.', keep_headers=True): | |
""" | |
Splits a CSV file into multiple pieces. | |
A quick bastardization of the Python CSV library. | |
Arguments: |