Skip to content

Instantly share code, notes, and snippets.

View natbusa's full-sized avatar

Nate Busa natbusa

View GitHub Profile
@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 / 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 / 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 / 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
CREATE TABLE table1 (
a1 text,
a2 text,
b1 text,
b2 text,
c1 text,
c2 text,
PRIMARY KEY ( (a1, a2), b1, b2 )
);
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 followers (
key text,
created timestamp,
messages_count int,
likes_count int,
PRIMARY KEY (key)
);
@natbusa
natbusa / markov.snakesandladders.py
Created January 25, 2013 10:13
Snakes and Ladders. Game analysis using stationary markov chains. Written in python. It uses the numpy for matrix operations and matplotlib for graph visualization
# Natalino Busa
# twitter.com/natalinobusa
# linkedin.com/in/natalinobusa
# www.natalinobusa.com
import numpy as np
from matplotlib import pyplot
size=100