This file contains hidden or 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(grDevices) | |
rsnake <- function(x=8,y=8, auto=NULL, plot=TRUE, detailed=FALSE) { | |
bodycheck <- function(newhead) { | |
if(newhead[1] < 1 || newhead[1] > x || newhead[2] < 1 || newhead[2] > y) return(FALSE) | |
return(sum(sapply(1:length(snake), function(x){identical(snake[[x]], newhead)})) == 0) | |
} | |
newfood <- function() { | |
while(!bodycheck(food <<- c(round(runif(1, min=1, max=x)), round(runif(1,min=1, max=y))))) FALSE |
This file contains hidden or 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
# plusMonth(time, diff) | |
# POSIXltに変換可能な型で与えられた日付を表すx に対して、diff月増減させた日付をPOSIXctで返す。 | |
# 月だけを増減させ、日付はそのままにするので、検査スケジュールなどを扱うのに適しているか。 | |
# diffは負でもよい。 | |
plusMonth <- function(x, diff=1) { # diff を省略すると1としたことになる | |
cur <- as.POSIXlt(x) | |
mon <- cur$mon | |
cur$year <- cur$year + (mon+diff)%/% 12 | |
cur$mon <- (mon+diff) %% 12 |
This file contains hidden or 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
(to name gist) |
This file contains hidden or 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
( for name ) |
This file contains hidden or 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
serial = require('serialport') | |
mqtt = require 'mqtt' | |
SerialPort = serial.SerialPort | |
sp = new SerialPort("/dev/tty.usbserial-XXXXXXXX", { # replace this to your serial port name. | |
baudrate: 115200, | |
parser: serial.parsers.readline("\n") | |
}) | |
atdesk = 0 |
This file contains hidden or 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
## modified from http://www.r-bloggers.com/how-to-download-complete-xml-records-from-pubmed-and-extract-data/ | |
# Install XML and RCrul package and call library(XML) and library(RCurl) before use this. | |
searchPubMed <- function(query.term) { | |
# change spaces to + in query | |
query.gsub <- gsub(" ", "+", query.term) | |
# change single-quotes to URL-friendly %22 | |
query.gsub <- gsub("'","%22", query.gsub) | |
# Perform search and save history, this will save PMIDS in history | |
pub.esearch <- getURL(paste("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=", |
This file contains hidden or 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
// Main | |
console.log("Start!"); | |
// Espruinoのピンのうち, B8とB9ピンをI2C用として使う | |
I2C1.setup({scl:B8,sda:B9}); | |
console.log("Initialize BME280..."); | |
// BME280用モジュールを読み込んで初期化 | |
var bme = require("BME280").connect(I2C1); | |
// MQTTサーバにつながるまではデータを送らないためのフラグ | |
var mqttconnected = false; |
This file contains hidden or 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
# 早押しクイズでn問先取の時,問題をx問用意した時にどのくらいの確率で勝ち抜け者が出るか.ただし一人も正解がない場合はないものとする. | |
nquiz <- function(x,n) { | |
if(n > x) { | |
stop("n must be smaller than or equal to x") | |
} | |
sum(sapply(n:x, function(xx) { ncol(combn(x,xx))})) / (2^x) | |
} |
This file contains hidden or 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
# Read MediaWiki's WikiTable text and convert it into a dataframe | |
lines <- readLines(file.choose()) | |
columns <- NULL | |
row <- NULL | |
df <- data.frame() | |
ncol <- 0 | |
for(line in lines) { | |
if((m <- sub("^\\! *(.*)$", "\\1", line)) != line){ |
OlderNewer