Skip to content

Instantly share code, notes, and snippets.

View natbusa's full-sized avatar

Nate Busa natbusa

View GitHub Profile
DROP TABLE followers;
CREATE TABLE followers (
followed_id text,
follower_id text,
created timestamp,
messages_count int,
likes_count int,
PRIMARY KEY ((followed_id, follower_id))
);
# the following will work (followed_id,follower_id is a partition key)#
cqlsh:test> select * from followers where followed_id='123' and follower_id='567';
followed_id | follower_id | created | likes_count | messages_count
-------------+-------------+--------------------------+-------------+----------------
123 | 567 | 2011-02-03 05:05:00+0100 | 5 | 2
# the following will not work (followed_id,follower_id is a partition key)#
DROP TABLE followers;
CREATE TABLE followers (
followed_id text,
follower_id text,
created timestamp,
messages_count int,
likes_count int,
PRIMARY KEY (followed_id, follower_id)
);
CREATE TABLE table1 (
a1 text,
a2 text,
b1 text,
b2 text,
c1 text,
c2 text,
PRIMARY KEY ( (a1, a2), b1, b2 )
);
@natbusa
natbusa / timelines.integers.R
Created October 14, 2013 14:58
A gist about displaying intervals using R and ggplot
library("ggplot2")
logfile = "
task a,2,9
task b,3,8
task c,1,4
task d,5,12
"
# read in the sample logfile in a data frame
@natbusa
natbusa / timelines.posixlt.R
Created October 14, 2013 15:05
A gist about displaying POSIXlt intervals using R and ggplot
library("ggplot2")
#sample logfile
logfile = "
task a,2013-10-10 11:16:16,2013-10-10 11:21:16
task b,2013-10-10 11:15:16,2013-10-10 11:18:45
task c,2013-10-10 11:20:20,2013-10-10 11:21:00
task d,2013-10-10 11:14:23,2013-10-10 11:19:30
"
@natbusa
natbusa / mean.statistics.R
Created October 14, 2013 22:09
mean statistics from 4 samples out of a population normally distributed N(0,1) behaves as N(0,0.5)
library("ggplot2")
# calculate a 1000 iterations for a selection of four sample from
# a normal population N(0,1)
mean.statistics= sapply(1:1000, function(x) {sum(rnorm(4,0,1))/4})
#base plot, but no functions
p = ggplot(data.frame(mean.statistics), aes(mean.statistics)) + xlim(-2,2)
@natbusa
natbusa / mean.hat.from.sample.statistics
Created October 15, 2013 05:27
Some simple sample statistics to estimate the true mean value from mean monte carlo statistics
> mean.muhat = mean(mean.statistics)
> mean.muhat
[1] 0.007315414
>
> mean.sehat = sd(mean.statistics)
> mean.sehat
[1] 0.4974518
>
> # mean = 0.007 +- 2*0.5
@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')
@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