Skip to content

Instantly share code, notes, and snippets.

View flada-auxv's full-sized avatar
🎯
Focusing

flada-auxv flada-auxv

🎯
Focusing
View GitHub Profile
@flada-auxv
flada-auxv / string.c
Created December 4, 2012 02:00
pryからのテスト投稿
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;
@flada-auxv
flada-auxv / http_server_restfuljson.js
Created December 3, 2012 14:06
[写経]Node.js入門10.3
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':
@flada-auxv
flada-auxv / monky_patch.rb
Created December 2, 2012 15:38
モンキーパッチの影響と対応策。ActiveSupportに見られるモジュールを利用する手法とRuby2.0から導入されるrefinments
# -*- coding: utf-8 -*-
# モンキーパッチには二つの問題がある。
# ・変更の範囲が「グローバル」である事。
# ・変更が行われた事が「見えづらい」事。
#
# 変更が見えづらい点への対応策として、ActiveSupportではモジュールを利用してモンキーパッチを明示的にしている。
# rails/activesupport/lib/active_support/core_ext配下。
# モジュールにメソッドを定義して、オープンクラスでインクルードする事で、#ancestors()などで確認する事が出来る。
# もちろんこれだけでは、「グローバル」な変更への配慮は出来ていないが。
@flada-auxv
flada-auxv / sort_by.rb
Created November 28, 2012 14:13
sort()とsort_by()と安定ソートについて
# -*- 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
@flada-auxv
flada-auxv / vending_machine.feature
Created November 27, 2012 14:48
cucumber_handsonで書いた
# language: ja
フィーチャ: 自販機でジュースを購入できる
自販機にお金を投入したら、ジュースが選択可能になる
ジュースを決定すれば、ジュースとお釣りが出てくる
シナリオ: お金を投入したら、ジュースが購入可能になる
前提 トップページを表示している
もし "100"円を投入する
かつ "10"円を投入する
かつ "10"円を投入する
@flada-auxv
flada-auxv / answer.js
Created November 23, 2012 12:11
Node.js道場(第一回目)の課題
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() {
@flada-auxv
flada-auxv / hello.js
Created November 23, 2012 08:51 — forked from shigeki/hello.js
第1回Node.js入門勉強会 レポート課題
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/');
});
@flada-auxv
flada-auxv / server.js
Created November 20, 2012 15:46
node.js入門勉強会第1回目で作った簡単なTCPサーバ
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;
}
@flada-auxv
flada-auxv / janken.rb
Created November 10, 2012 10:02
じゃんけんプログラムを作ろうhttps://codeiq.jp/ace/suginoy/q72
# -*- coding: utf-8 -*-
class Janken
HAND = %i(グー チョキ パー)
def hand
@hand = HAND.shuffle.first
end
def versus(other)
other = other.hand
@flada-auxv
flada-auxv / enclose.rb
Created November 10, 2012 09:14
rubyでちょこっとテキスト処理https://codeiq.jp/ace/suginoy/q77
separator = %Q(+#{"-" * ARGV.size}+)
result = ARGV.map do |arg|
[separator, "|" << arg.ljust(ARGV.size) << "|"]
end
puts result << separator