Created
May 12, 2011 22:12
-
-
Save wactbprot/969579 to your computer and use it in GitHub Desktop.
couchdb R chat see http://wactbprot.tumblr.com/post/5431085881/couchdb-r-chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RJSONIO, quietly =TRUE) | |
goOn <- TRUE | |
while(goOn){ | |
jIn <- scan('stdin', | |
'', | |
n=1, | |
quiet=TRUE, | |
sep="\n") | |
## 4 debuging purposes one can: | |
## save(a,file="wactbprot/a.oo", ascii=TRUE) | |
## | |
rIn <- fromJSON(jIn) | |
## try catch stuff needed here | |
query <- rIn$query | |
if(length(query$do) == 1){ | |
switch(query$do, | |
this = rOut <- list(reply="this done"), | |
that = rOut <- list(reply="that done") | |
) | |
}else{ | |
rOut <- list(reply="nothing done") | |
} | |
jOut <- gsub("\n","",toJSON(rOut)) | |
cat(paste("{ \"code\":200,\"json\":",jOut,"}\n" ,sep="")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment