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
static VALUE | |
rb_str_each_line(argc, argv, str) | |
int argc; | |
VALUE *argv; | |
VALUE str; | |
{ | |
VALUE rs; | |
int newline; | |
char *p = RSTRING(str)->ptr, *pend = p + RSTRING(str)->len, *s; | |
char *ptr = p; |
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
var http = require('http'); | |
var port = 1337; | |
var obj = {}; | |
var server = http.createServer(function(req, res) { | |
var remoteAddress = req.connection.remoteAddress; | |
var header = {'Connection': 'close', 'Content-Length': 0}; | |
var key = req.url | |
switch (req.method) { | |
case 'POST': |
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
# -*- coding: utf-8 -*- | |
# モンキーパッチには二つの問題がある。 | |
# ・変更の範囲が「グローバル」である事。 | |
# ・変更が行われた事が「見えづらい」事。 | |
# | |
# 変更が見えづらい点への対応策として、ActiveSupportではモジュールを利用してモンキーパッチを明示的にしている。 | |
# rails/activesupport/lib/active_support/core_ext配下。 | |
# モジュールにメソッドを定義して、オープンクラスでインクルードする事で、#ancestors()などで確認する事が出来る。 | |
# もちろんこれだけでは、「グローバル」な変更への配慮は出来ていないが。 |
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
# -*- coding: utf-8 -*- | |
# sort_byの実装イメージ(公式リファレンスより) | |
class Array | |
def sort_by | |
self.map {|i| [yield(i), i] }. | |
sort {|a, b| a[0] <=> b[0] }. | |
map {|i| i[1]} | |
end | |
end |
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
# language: ja | |
フィーチャ: 自販機でジュースを購入できる | |
自販機にお金を投入したら、ジュースが選択可能になる | |
ジュースを決定すれば、ジュースとお釣りが出てくる | |
シナリオ: お金を投入したら、ジュースが購入可能になる | |
前提 トップページを表示している | |
もし "100"円を投入する | |
かつ "10"円を投入する | |
かつ "10"円を投入する |
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
var http = require('http'); | |
server = http.createServer(function (req, res) { | |
console.log(req.url); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
req.on('end', function() { | |
req.connection.end(); | |
}); | |
}); | |
server.on('connection', function() { |
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
var http = require('http'); | |
server = http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
server.close(); | |
}); | |
server.listen(8080, 0, function () { | |
console.log('Server running at http://localhost:8080/'); | |
}); |
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
var net = require('net'); | |
var readline = require('readline'); | |
var util = require('./util'); | |
var server = net.createServer(); | |
server.maxConnections = 3; | |
function Client(socket) { | |
this.socket = socket; | |
} |
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
# -*- coding: utf-8 -*- | |
class Janken | |
HAND = %i(グー チョキ パー) | |
def hand | |
@hand = HAND.shuffle.first | |
end | |
def versus(other) | |
other = other.hand |
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
separator = %Q(+#{"-" * ARGV.size}+) | |
result = ARGV.map do |arg| | |
[separator, "|" << arg.ljust(ARGV.size) << "|"] | |
end | |
puts result << separator |