Skip to content

Instantly share code, notes, and snippets.

@so-c
so-c / num_books_in_2013.R
Created December 17, 2013 15:43
2013年に読んだ本のバーチャートをggplot2で書く。
library("ggplot2")
entries <- data.frame(label=factor(c("小説", "読書", "漫画", "新書"),
levels=c("小説", "読書", "漫画", "新書")),
num=c(64, 48, 44, 2))
g <- ggplot(entries, aes(x=label, y=num, fill=label))
p <- g + geom_bar()
p <- p + xlab("ラベル") + ylab("投稿数") + ggtitle("2013年に読んだ本") + theme(legend.position = "none")
@so-c
so-c / addLineGraph.js
Created June 23, 2013 08:23
Google DocsのSpreadSheetにエクスポートしたSimpleDietのデータから折れ線グラフを作るための、Container-Bound Script。
/**
* Make a line chart with the data exported from iOS App SimppleDiet to Google Docs Spreadsheet.
*/
function addLineGraph() {
var sheets = SpreadsheetApp.getActiveSpreadsheet();
var sheet = sheets.getSheets()[0];
var allRange = sheet.getDataRange();
var range = sheet.getRange(1, 1, allRange.getLastRow(), 2);
var chart = sheet.newChart().asLineChart()
@so-c
so-c / array.js
Last active December 17, 2015 11:08
『JavaScriptパターン』の「5.1.1 汎用の名前空間関数」と「5.4.2 コンストラクタを構成するモジュール」
// コンストラクタを構成するモジュール
MYAPP.namespace('MYAPP.utilities.Array');
// 使い方
// var arr = new MYAPP.utilities.Array(obj);
MYAPP.utilities.Array = (function () {
// 依存関係
var upbj = MYAPP.utilities.object,
ulang = MYAPP.utilities.lang,
// プライベートのプロパティとメソッド
@so-c
so-c / ajaxexample.js
Last active December 17, 2015 00:49
Sinon.JSのGetting started (http://sinonjs.org/) サンプルコードを、JsTestDriverに合わせて書き換えた。
// Example of ajax
TestCase('AjaxExample', {
'test makes a GET request for todo items':sinon.test(function(stub) {
this.stub($, 'ajax');
getTodos(42, sinon.spy());
assertTrue($.ajax.calledWithMatch({url: '/todo/42/items'}));
})
});
@so-c
so-c / interval_moleskine.R
Last active December 11, 2015 09:19
Moleskineを1冊使い切る日数。
library("ggplot2")
p# acquire
# 下記形式のinterval.csvから日付を取得
# "number","start","end"
# "1","2013-1-1","2013-1-31"
interval <- read.csv(file="interval.csv", as.is=TRUE)
# parse
interval$start <- as.Date(interval$start)
@so-c
so-c / num_books_in_2012.R
Created December 30, 2012 01:36
2012年に読んだ本のバーチャートをggplot2で書く。
library("ggplot2")
entries <- data.frame(label=factor(c("小説", "読書", "漫画", "新書"),
levels=c("小説", "読書", "漫画", "新書")),
num=c(69, 34, 17, 3))
g <- ggplot(entries, aes(x=label, y=num, fill=label))
p <- g + geom_bar()
p <- p + xlab("ラベル") + ylab("投稿数") + ggtitle("2012年に読んだ本") + theme(legend.position = "none")