Skip to content

Instantly share code, notes, and snippets.

View ww24's full-sized avatar
🏢
≡GO

Takenori Nakagawa ww24

🏢
≡GO
View GitHub Profile
@ww24
ww24 / GA.coffee
Last active August 29, 2015 13:55
###
GeneticAlgorithm Class
###
Gene = require "./Gene"
class GA
# 個体数, 評価関数
constructor: (@population, @gene_size) ->
@genes = (new Gene(null, @gene_size) for x in [0...population])
@ww24
ww24 / example.js
Created February 6, 2014 05:51
V8 で行番号を取得する。
// test1
console.log(getLineNumber());
// test2
var test = (function test() {
console.log(getLineNumber());
return test;
})();
var obj = {
@ww24
ww24 / logistic_map.R
Last active August 29, 2015 14:00
ロジスティック写像の分岐図
# ロジスティック写像
# 周期倍加分岐図
require(compiler)
# 設定
x0 <- 0.1
aR <- 29000:40000 / 10000
tR <- 1900:2000
@ww24
ww24 / download.js
Created April 26, 2014 17:24
任意のファイルの自動ダウンロード
function download(url, filename) {
var a = document.createElement("a");
a.href = url;
a.download = filename || url.split("/").slice(-1)[0];
a.click();
}
@ww24
ww24 / snowflake.js
Created April 29, 2014 06:17
コッホ雪片
/**
* コッホ雪片
*/
// 設定
/*==========================*/
// 初期座標
var a = {x: 10, y: 580};
var b = {x: 1990, y: 580};
// 描画サイズ
@ww24
ww24 / remove.js
Last active August 29, 2015 14:02
.lightgray 要素の前に半角空白を挿入し、 .lightgray 要素を削除する。
/**
* コピペ防止対策☆
*/
var fakes = [].slice.call(document.getElementsByClassName("lightgray")), fake;
while (fake = fakes.shift()) {
fake.parentNode.insertBefore(document.createTextNode(" "), fake);
fake.parentNode.removeChild(fake);
}
@ww24
ww24 / index.html
Last active August 29, 2015 14:02
Global 名前空間のどの変数名をライブラリに使わせるか、利用者が選べるようにする仕組み。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>mylib</title>
</head>
<body>
<script src="mylib.js" data-mylib="lib"></script>
<script>
addEventListener("load", function () {
@ww24
ww24 / oop.js
Created June 6, 2014 09:06
JavaScript のオブジェクト指向
function F(message) {
this.message = message;
}
F.prototype.print = function () {
console.log(this.message);
};
// F を継承した G
function G(message, name) {
F.call(this, message);
@ww24
ww24 / ca.js
Last active August 29, 2015 14:02
Life Game
/**
* Life Game - Cellular Automaton
*
* Author: Takenori Nakagawa
* License: GPLv3
*/
// cell constructor
function Cell(x, y, init) {
var value;
@ww24
ww24 / fib.rb
Last active August 29, 2015 14:02
フィボナッチ数列 (Ruby の勉強)
fibonacci = Enumerator.new do |y|
i = [0, 1]
loop do
y << i[0]
i = [i[1], i[0] + i[1]]
end
end
# 遅延評価
p fibonacci.lazy.map{|x| x ** 2}.take(20).force