Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
# my third attempt
module EventSystem
# リスナーレジストリ
# イベント名 Symbol をキーとして、
# 関心を示したオブジェクトの ID の配列を持つ。
# それぞれのオブジェクトは Event モジュールを include している。
@@registry = Hash.new
# -*- coding: utf-8 -*-
# my second attempt
require 'weakref'
module Event
# イベント名 Symbol をキーとして、
# 関心を示したオブジェクトへの WeakRef を持つ。
# オブジェクトは Event モジュールを include している。
@@event_objects_map = Hash.new
# -*- coding: utf-8 -*-
# my third attempt
module EventSystem
# リスナーレジストリ
# イベント名 Symbol をキーとして、
# 関心を示したオブジェクトの ID の配列を持つ。
# それぞれのオブジェクトは Event モジュールを include している。
@@registry = Hash.new
#include <stdio.h>
#include <windows.h>
/* LARGE_INTEGER を表示する */
#define disp_large_int(x) printf(#x " = %lld\n", x.QuadPart)
/* QueryPerformanceFrequency と ...Counter を使って
Sleep(1000) を実行する間にたった時間を表示する */
int main(int argc, char **argv)
{
@plonk
plonk / variadic_templates_test.cc
Created March 16, 2013 05:38
可変長引数テンプレート習作
#include <iostream>
template <typename T>
T inject_plus(T v)
{ return v; }
template <typename T, typename ... Rest>
T inject_plus(T v, Rest ... rest)
{
return v + inject_plus(rest...);
#include <iostream>
#include <typeinfo>
using namespace std;
// コマンドオブジェクト、Job のインターフェース。
// これのポインタを使ってアクセスする。
class IJob {
public:
// インスタンス生成テンプレート関数。
@plonk
plonk / 2013-05-17-e.cc
Created May 16, 2013 22:09
C++でRubyみたいに書きたい病。print文の出来には満足している
#include <sstream>
#include <iostream>
#include <cctype>
#include <list>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;
@plonk
plonk / gist:5639913
Created May 23, 2013 22:18
10 が繰り返す。何度でも初期化されるっぽい
#include <iostream>
using namespace std;
int main()
{
label:
int i(10);
cout << i << endl;
i = 20;
goto label;
}
@plonk
plonk / sum.c
Created June 25, 2013 14:15
リスナーさんに教えてもらった strtok で綺麗にかけた奴
/* 数を空白くぎりで入力すると和を計算します */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int calculate_sum(const char *line)
{
int sum = 0;
char *copy = strdup(line);
@plonk
plonk / snippet.cc
Last active December 19, 2015 16:19
snippet from Design Patterns (pp.71-72)
void SpellingChecker::Check (Glyph* glyph) {
Character* c;
Row* r;
Image* i;
if (c = dynamic_cast<Character*>(glyph)) {
// analyze the character
} else if (r = dynamic_cast<Row*>(glyph)) {
// prepare to analyze r's children