Skip to content

Instantly share code, notes, and snippets.

View briandk's full-sized avatar

Brian A. Danielak briandk

View GitHub Profile
@briandk
briandk / scaleFillManualProblems.R
Created February 8, 2012 03:52
Problems with scale_fill_manual in ggplot2 v0.9.0
# These problems are current as of
# commit fe93b8ae11c43f8e33cb0252a25d260a769d4ded in ggplot2
# A data frame with four levels of 'g'
dat2 <- data.frame(x=factor(1:5),
y=3,
g=c("B","A","C","D","D"))
p2 <- ggplot(dat2, aes(x=x,y=y,fill=g)) + geom_bar()
@briandk
briandk / printFourPlotsPerPageTest.R
Created February 22, 2012 23:33
Testing print.four.plots.per.page
library(granovaGG)
# Explicitly printing four plots per page
pdf(file="~/Desktop/BrianTest1.pdf", onefile = TRUE)
data(rat)
fake.contrasts <- matrix(c(1, 1, 1, -1, -1, -1, -1, 1, 0, -1, 1, 0, 1, 1, -2,
1, 1, -2, -1, 1, 0, 1, -1, 0, 1, 1, -2, -1, -1, 2), ncol = 5)
fake.contrasts <- fake.contrasts[ ,1:3]
granovagg.contr(data = rat[ ,1],
@briandk
briandk / parameterMatching.R
Created February 23, 2012 17:10
Fun with parameter matching in R
foo <- function(..., values) {
return(values)
}
bar <- function(values, ...) {
return(values)
}
# foo() will fail to match on "values" and claim there's no default
foo(value = "red")
@briandk
briandk / granovaGGpre-commit.sh
Created May 16, 2012 16:53
precommit hook for granovaGG git repository
#!/bin/bash
D=`date +%Y%m%d%H%M%S` # store the current system-clock as a date-stamp, down to the second
branch=`git status|grep -ie 'on branch master'`
if [ -z "$branch" ]; then # if the length of the string in variable "branch" is zero;
# or, in other words, if you're not on the master branch
cat DESCRIPTION | sed -e 's/^\(Version: [0-9]*\.[0-9]*\).*/\1.'$D'/' > DESCRIPTION.temp # cat the DESCRIPTION
# match on the version number
# append the full datestamp to the matched version number
test<-data.frame(a=c(2,2,2,4,4,4,4,6,6,6,6,6,6,8,8,8,10,10,10,10,10,10,10),Pre=c(100,110,90,100,120,130,170,150,150,120,140,150,120,90,90,100,40,50,40,40,20,60,30),Post=c(b-15))
testMelt <- melt(
test,
id = c("a"),
measured = c("Pre", "Post")
)
p <- ggplot(
@briandk
briandk / gitLogCommands.sh
Created February 13, 2013 01:06
A few simple one-liners for generating git logs with commit messages
# This gives a short-hash (%h), a simple date, and just the subject line of the commit
git log --format="%h | %ad | %s" --date=short
# an alternative, which omits the date
git log --oneline
# the standard git log, which usually has way too much information to be useful
git log
@briandk
briandk / test.rkt
Created February 18, 2013 14:44
A quick test of a function to find the length of a list in Racket.
(define (my-length lst)
(cond
[(empty? lst) 0]
[else (+ 1 (my-length (rest lst)))]))
@briandk
briandk / kernighanAndRitchie.c
Created November 14, 2013 20:43
Comparison of brace styles
int main ()
{
// Do stuff
}
int main () {
// Do Stuff
}
@briandk
briandk / applebuggycode.c
Created February 24, 2014 22:34
The SSL bug in Apple's code
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
uint8_t *signature, UInt16 signatureLen)
{
OSStatus err;
...
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
@briandk
briandk / nestingComplexity.py
Created April 1, 2014 17:42
Nesting complexity in Data Structures.
{"pages": [ {"playerName": "Boris",
"livesLeft": 1},
{"playerName": "Anna",
"livesLeft": 1} ],
"items": ["broadsword", "healingPotion", "mirrorShield"]
"timestamp": 12593829349045 }