Skip to content

Instantly share code, notes, and snippets.

@maraigue
maraigue / puyo.rb
Created September 22, 2011 15:22
ぷよぷよの連鎖状況を表示するプログラム
#!/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分でした。」
@maraigue
maraigue / declarator.rb
Created August 10, 2011 11:35
[Ruby] 特定の型の値以外を代入できない変数を使うためのライブラリ
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class Declarator
def initialize(description = nil, &condition)
@condition = condition
@description = description
@values = {}
end
@maraigue
maraigue / README.txt
Created July 27, 2011 14:30
[Boost.Test] Where is boost::test_tools::tt_detail::check_impl ?
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, ...)'
@maraigue
maraigue / dish_sample.cpp
Created July 10, 2011 14:46
クラスを使う意味(C++で説明)
#include <string>
#include <iostream>
// (いろいろと説明を省いている部分があります)
// 例えば、「皿」というクラスがあるとすると
class Dish{
private:
// それが持つ変数(構造体のメンバに相当)として、例えば「食べ物の名前」や
// 「食べ物の量」が考えられる。
@maraigue
maraigue / opt-tail-recursion.h
Created July 3, 2011 16:05
「一言書くだけで末尾再帰最適化」をC++でやってみた
// 元ネタ:http://d.hatena.ne.jp/wasabiz/20110118/1295335821
//
// 注意点:
// ここで定義されているTCO_FUNCは、「末尾再帰で書かれた関数の引数が2つである場合」
// に限定された定義です。
// それ以上の場合は、別途マクロを定義しないとならないです。
// Boost.PPとかを使うと何とかなるのかな…?
#ifndef _OPT_TAIL_RECURSION_H_
#define _OPT_TAIL_RECURSION_H_
@maraigue
maraigue / ruby-layer.rb
Created June 27, 2011 09:26
Rubyのコードの範疇で階層構造を定義し、かつ階層構造の解釈の途中に自由な処理を挟めるようにする例
# ここからライブラリ部
class WidgetGenerator
def initialize(level)
@level = level
end
def add_widget(name, &block)
indent = " " * @level
# ここではLispのコードを表示するようにしているが
@maraigue
maraigue / cpp_template_technique.rb
Created June 9, 2011 03:11
Google検索の「もしかして:C++++(中略)++++Template テクニック」の「++」はどこまで伸びるのかを検証するプログラム
#!/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)
@maraigue
maraigue / singleton.py
Created May 18, 2011 18:59
Singleton in Python (as a library)
#!/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):
@maraigue
maraigue / in_array.rb
Created May 18, 2011 09:06
Pythonのitem in list(listの中にitemが含まれているかを返す)に近い表記をRubyで出来るように頑張ってみた
#!/usr/bin/ruby
# 「普通にlist.include?(item)使えよ!」って話ではあるのですが
# 訳あって書いてみました
class Object
def in(list)
list.include?(self)
end
end
@maraigue
maraigue / classname2instance.rb
Created May 15, 2011 09:26
Rubyのクラス名を文字列で与えて(例:"Hoge::Piyo")そのクラスのインスタンスを生成する方法
#!/usr/bin/ruby
#
# = 元ネタ
#
# Kawaz - Pythonで文字列からクラスインスタンスを生成したりメソッドを呼ぶ方法
#
# http://www.kawaz.org/blogs/miiojp/2011/05/15/106/
#
# 上記ページでは、Pythonで "hogehoge.hogenoho.HogeClass" のような文字列に