Skip to content

Instantly share code, notes, and snippets.

View natbusa's full-sized avatar

Nate Busa natbusa

View GitHub Profile
@natbusa
natbusa / elements.scala
Last active August 29, 2015 13:56
elements as case classes
case class ToastedBread(slices: Int)
case class FriedEggs(num: Int)
case class CrispyBacon(strips: Int)
case class OrangeJuice(glasses: Int)
case class HotCoffee(mugs: Int)
case class MainDish(eggs: FriedEggs, bacon: CrispyBacon)
case class SideDish(toast: ToastedBread)
case class Drinks(juice: OrangeJuice, coffee: HotCoffee)
@natbusa
natbusa / elements.json.scala
Last active August 29, 2015 13:56
json conversion by decoration of the element case classes
object JsonImplicits extends DefaultJsonProtocol {
//main dish
implicit val impCrispyBacon = jsonFormat1(CrispyBacon)
implicit val impFriedEggs = jsonFormat1(FriedEggs)
implicit val impMainDish = jsonFormat2(MainDish)
//side dish
implicit val impToastedBread = jsonFormat1(ToastedBread)
implicit val impSideDish = jsonFormat1(SideDish)
@natbusa
natbusa / cassie.cql
Created December 12, 2013 13:17
Little cassandra table
CREATE KEYSPACE ks WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 } ;
create table ks.tb (
a1 TEXT,
b1 TEXT,
b2 INT,
d INT,
v INT,
PRIMARY KEY ( a1, b1, b2 )
);
@natbusa
natbusa / currying.R
Created December 2, 2013 10:52
currying in R
#function
myfunc.x.a.b.c = function(x,a,b,c) {
a*x*x+ b*x +c
}
myfunc.x.a.b.c(1,2,3,4)
myfunc.x.a.b = function(x,a,b){
function(c) {myfunc.x.a.b.c(x,a,b,c)}
}
@natbusa
natbusa / parametric.plotting.R
Last active September 8, 2016 16:59
parametric plotting using ggplot2 and currying
library("ggplot2")
#function
myfunc = function(x,a,b,c) {
a*x*x+ b*x +c
}
#basic plot, fixed parameter a = 1, b=0, c=0
p = ggplot(data.frame(x = c(-10, 10)), aes(x))
p + stat_function(fun=function(x) { myfunc(x,1, 0, 0) } )
@natbusa
natbusa / create_ts.cql
Created November 11, 2013 21:39
Cassandra timeseries: a signal decomposition.
CREATE KEYSPACE iot WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 } ;
USE iot;
create table signals (
sid bigint,
year int,
month int,
day int,
hour int,
@natbusa
natbusa / us.treasury.rates.R
Last active October 8, 2020 04:03
retrieving us treasury rates
library('XML')
library('RCurl')
# Save the URL of the xml file in a variable
fileUrl="http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData?$filter=year(NEW_DATE)%20eq%202010"
###Using the rcurl package, first download, then parse
#Get the content
fileContent = getURL(fileUrl)
@natbusa
natbusa / dutch.elections.2010.R
Last active December 27, 2015 09:19
Basic statistics on dutch election 2010
# read in ducth election file as provided by http://www.engagedata.eu/dataset/14399
# https://engagefp7.s3.amazonaws.com/resources/dataset_14399/TK2010.csv
dat = read.csv2('http://engagefp7.s3.amazonaws.com/resources/dataset_14399/TK2010.csv', skip=31, header=FALSE)
#define column names
columns = '
Gemeente;
geldige stemmen;
ongeldige stemmen;
@natbusa
natbusa / basic.R
Last active December 27, 2015 08:59
Basic R tryouts
library('ggplot2')
#basics
3*4
2^3
1/2 + 1/2*sqrt(5)
#those two are identical
(1+2+3+4)/4
@natbusa
natbusa / cars93.extract.csv.R
Last active October 6, 2016 03:29
Extract Cars93 to a cvs file using R and the MASS library
library("MASS")
write.csv(Cars93, 'cars93.csv')