Skip to content

Instantly share code, notes, and snippets.

@haiiro-shimeji
haiiro-shimeji / namespace.js
Last active December 17, 2015 13:19
#js #tddjs
(function() {
var namespaces = {};
function namespace(string) {
var object = namespaces;
var levels = string.split(".");
if (!(levels[0] in object) && levels[0] in window) {
@haiiro-shimeji
haiiro-shimeji / privatemember.js
Last active December 17, 2015 14:29
#js #tddjs
TestCase("Private member", {
"test of object which has private member": function() {
var MyClass = function(value) {
this.getValue = function() {
return value;
}
};
var obj = new MyClass(5);
@haiiro-shimeji
haiiro-shimeji / extend.js
Last active December 17, 2015 15:29
#js #tddjs
TestCase("Extend", {
"test of extended class in ECMA3Script": function() {
var SuperClass = function() {
this.value = "piyo";
};
SuperClass.prototype.value = undefined;
SuperClass.prototype.func = function() { return "hoge"; }
var SubClass = function() {};
@haiiro-shimeji
haiiro-shimeji / range.js
Last active December 17, 2015 15:29
range() #js
TestCase("range", {
"test of range": function() {
function range() {
var s, e, i, j;
if (2 < arguments.length) {
s = arguments[0];
e = arguments[1];
i = arguments[2];
if (0 === i) {
throw new Error("step must be not zero.");
@haiiro-shimeji
haiiro-shimeji / file_uploader.js
Last active December 18, 2015 21:39
canvas を用いて選択されたローカルファイルをリサイズし、ajaxで送信するまでのサンプル 選択されたのがイメージファイルでなければそのまま送信する
FileUploadForm = function(form) {
this.form = form;
form.find("input[type=file]").change(this._handleFileInputChanged.bind(this));
this.changeCallback = $.Callbacks();
this.disposeCallback = $.Callbacks();
}
FileUploadForm.prototype = {
form: undefined,
TestCase("Applicative style on jQuery Deferred", {
setUp: function() {
Function.prototype.$ = function() {
return $.when.apply($, arguments)
.then(this.bind(null));
};
Function.prototype.$$ = function(obj) {
var f = this;
return function() {
return $.when.apply($, arguments)
@haiiro-shimeji
haiiro-shimeji / test.js
Last active December 20, 2015 17:49
usage of sinon.js
TestCase("usage.sinon", {
'test mock for constructor': sinon.test(function() {
var obj = {
hoge: function(id) {
this.id = id
}
};
this.mock(obj)
#include <stdio.h>
int main(int argc, char** argv) {
//関数定義の前に関数利用のコードがあるとコンパイルエラー.
hoge();
}
void hoge() {
puts("hoge");
}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
<form id="form">
Select file to add to database: <input type="file" name="file">
<button type="submit">put into db</button>
@haiiro-shimeji
haiiro-shimeji / gist:6212507
Last active December 20, 2015 23:29
Illegal Invocation in Google Chrome
TestCase("hoge", {
'test for native method': function() {
var f = console.log;
//f("hoge"); //Illegal Invocation
f.bind(console)("hoge");
},
//Native method では Illegal Invocation Error と表示されるが、
//理屈は通常オブジェクトの場合と同じ
'test': function() {
var obj = {