Skip to content

Instantly share code, notes, and snippets.

View clarkfitzg's full-sized avatar

Clark Fitzgerald clarkfitzg

  • Mathematics and Statistics Department, CSU Sacramento
  • Sacramento
View GitHub Profile
@clarkfitzg
clarkfitzg / test_gist
Created September 3, 2013 04:17
Test
# Checking to see how this saves. What will it look like?
# Not sure
x <- 1:10
@clarkfitzg
clarkfitzg / graph_conv_rate.R
Created October 4, 2013 02:20
This is from a brief talk given at a BARUG meetup on October 2013. It creates a powerpoint friendly graph of some currency conversion rate data points.
# Clark 9/27/13
#
# This script graphs the conversion rate data
# You'll need to change the file.path parameter to the location of your data.
file.path <- "/home/shared/barug_oct13/hourly_rate.csv"
require(ggplot2)
require(grid)
@clarkfitzg
clarkfitzg / get_conv_rate.R
Last active December 24, 2015 15:28
This script scrapes a current exchange rate and writes it to a csv file. It's meant to be automated using Linux crontab. To have it run every hour you would type something like this: ~$ crontab -e 0 * * * * sudo R CMD BATCH /home/shared/barug_oct13/get_conv_rate.R
# Clark Fitzgerald 23 Sep 13
#
# This script gets current exchange rates and writes to csv file.
csv.path <- "/home/shared/barug_oct13/hourly_rate.csv"
library("XML")
# We'll compare the conversion rate from US to South Korea.
country <- "korea"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@clarkfitzg
clarkfitzg / ddR_parts.R
Last active July 14, 2016 19:04
Creating and accessing the parts of a nonuniform distributed array
> library(ddR)
Welcome to 'ddR' (Distributed Data-structures in R)!
For more information, visit: https://github.com/vertica/ddR
Attaching package: ‘ddR’
The following objects are masked from ‘package:base’:
cbind, rbind
@clarkfitzg
clarkfitzg / keyvalue.R
Created July 18, 2016 18:02
Use serialization to store arbitrary R objects as key value pairs in Spark DataFrames
# Mon Jul 18 08:08:09 PDT 2016
# Goal: Store arbitrary objects in DataFrames as bytes to make dapply more
# general
#
# Inefficient- this uses CLOB rather than BLOB
# Comments throughout this question are helpful
# http://stackoverflow.com/questions/5950084/how-to-handle-binary-strings-in-r
library(SparkR)
@clarkfitzg
clarkfitzg / simple_parallel.R
Created November 17, 2016 05:11
For tutorial on Nov 17, 2016
# A very simple parallel program
#
# We specify the probability that each individual
# votes for a candidate, and then simulate the counts
# for n such voters.
#
# count_votes and count_votes_slow are the functions
# to parallelize. Typically each run will take some
# time to complete.
#
@clarkfitzg
clarkfitzg / ripser.md
Created December 17, 2016 01:05
Calling "ripser" from R

First install ripser.

Then make it locatable on your system PATH, something like:

$ ln -s /home/clark/dev/ripser/ripser /usr/local/bin/ripser

After this your system should be able to find ripser:

$ which ripser
x = 1:3
y = 11:13
# Given vectors x, y, what's the cleanest general way to make z?
# z = c(1, 11, 2, 12, 3, 13)
shuffle = function(x, y)
{
as.vector(mapply(c, x, y))
}
@clarkfitzg
clarkfitzg / recursive_normal.py
Last active March 24, 2017 23:35
Comparing groupby speed in pandas versus R data.table
"""
http://stackoverflow.com/questions/41886507/data-table-faster-row-wise-recursive-update-within-group/41891693#41891693
require(data.table) # v1.10.0
n_smpl = 1e6
ni = 5
id = rep(1:n_smpl, each = ni)
smpl = data.table(id)
smpl[, time := 1:.N, by = id]
a_init = 1; b_init = 1