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
#!/usr/bin/ruby | |
# ぷよぷよの連鎖状況を表示するプログラム by H.Hiro main@hhiro.net | |
# 出題: http://okajima.air-nifty.com/b/2011/01/2011-ffac.html | |
# Ruby1.8, 1.9両対応です。 | |
# | |
# 当の記事に | |
# 「書くのにかかった時間も自己申告してください。 | |
# 目安として、2時間以上かかった人は採用は難しいでしょう。 | |
# 僕が自分で書いてみたら30分でした。」 |
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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
class Declarator | |
def initialize(description = nil, &condition) | |
@condition = condition | |
@description = description | |
@values = {} | |
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
I have just began using Boost.Test (unit test tool contained in Boost). | |
I already compiled Boost from the source code (Boost 1.46.1, gcc4.3.3, Ubuntu9.04). | |
I tried compiling with the following command to run a test I wrote: | |
$ g++ -I/PATH/TO/BOOST -L/PATH/TO/BOOST/bin.v2/libs/test/build/gcc-4.3.3/release/link-static/threading-multi -lboost_unit_test_framework soulgem_test.cpp -o soulgem_test | |
However, I got the following error: | |
/tmp/ccOzdGnC.o: In function `soulgem_status::test_method()': | |
soulgem_test.cpp:(.text+0x3e4): undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned int, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned int, ...)' |
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
#include <string> | |
#include <iostream> | |
// (いろいろと説明を省いている部分があります) | |
// 例えば、「皿」というクラスがあるとすると | |
class Dish{ | |
private: | |
// それが持つ変数(構造体のメンバに相当)として、例えば「食べ物の名前」や | |
// 「食べ物の量」が考えられる。 |
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
// 元ネタ:http://d.hatena.ne.jp/wasabiz/20110118/1295335821 | |
// | |
// 注意点: | |
// ここで定義されているTCO_FUNCは、「末尾再帰で書かれた関数の引数が2つである場合」 | |
// に限定された定義です。 | |
// それ以上の場合は、別途マクロを定義しないとならないです。 | |
// Boost.PPとかを使うと何とかなるのかな…? | |
#ifndef _OPT_TAIL_RECURSION_H_ | |
#define _OPT_TAIL_RECURSION_H_ |
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
# ここからライブラリ部 | |
class WidgetGenerator | |
def initialize(level) | |
@level = level | |
end | |
def add_widget(name, &block) | |
indent = " " * @level | |
# ここではLispのコードを表示するようにしているが |
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
#!/usr/bin/env ruby1.9 | |
# -*- coding: utf-8 -*- | |
require 'open-uri' | |
require 'hpricot' | |
TRIAL_COUNTS = 10 # 何回繰り返すか | |
OUT_ENCODING = 'utf-8' # 結果を出力する際のエンコーディング | |
def read_google_search(path) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Singleton in Python | |
# (based on http://d.hatena.ne.jp/BetaNews/20090607/1244358178 | |
# but some bugs contained) | |
# | |
# For usage, see the code in the bottom of this file. | |
class Singleton(object): |
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
#!/usr/bin/ruby | |
# 「普通にlist.include?(item)使えよ!」って話ではあるのですが | |
# 訳あって書いてみました | |
class Object | |
def in(list) | |
list.include?(self) | |
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
#!/usr/bin/ruby | |
# | |
# = 元ネタ | |
# | |
# Kawaz - Pythonで文字列からクラスインスタンスを生成したりメソッドを呼ぶ方法 | |
# | |
# http://www.kawaz.org/blogs/miiojp/2011/05/15/106/ | |
# | |
# 上記ページでは、Pythonで "hogehoge.hogenoho.HogeClass" のような文字列に |