Skip to content

Instantly share code, notes, and snippets.

@kasei-san
kasei-san / gist:10003192
Last active August 29, 2015 13:58
スレッド操作いろいろ
#include <stdio.h>
#include <pthread.h>
#include <iostream>
class LedMatrix {
private:
pthread_t thread; // スレッドハンドラ
pthread_mutex_t mutex; // ミューテックス(排他処理で優先権を決めるやつ)
int data;
public:
class StringListerViewer
attr_reader :items, :type
def initialize(items, type)
@items = items
@type = type
end
def string_lister(items)
Object.const_get("#{type.to_s.capitalize}StringLister").new(items)
end
引数 klass で指定したクラスだけに対して、ブロックで指定した機能を提供で きるモジュールを定義します。定義した機能は Module#refine を使用せずに直 接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。 そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。
アルゴリズムを実行時に選択することができるデザインパターンである。
# ファイルを生成して、upload するという流れ
class FileUploader # Client
def initialize(factory)
@file_maker = factory.file_maker
@uploader = factory.uploader
end
def make_flie(items)
@file = file_maker.make(item)
end
require "open-uri"
class Titles
include Enumerable
def initialize
@urls = []
end
def <<(url)
@urls << url
@kasei-san
kasei-san / file0.txt
Created July 28, 2014 22:34
ActiveSupport::Concern と、Module#concerning ref: http://qiita.com/kasei-san/items/c016c626836da09a5a70
関心事、関連、利害関係 など
Singleton パターンを用いると、そのクラスのインスタンスが1つしか生成されないことを保証することができる。 ロケールやLook&Feelなど、絶対にアプリケーション全体で統一しなければならない仕組みの実装に使用される
@kasei-san
kasei-san / test.js
Created July 28, 2015 22:46
関数・メソッド・コンストラクタ
function test(){ // 関数
console.log("test");
}
function Animal(type, voice){ // コンストラクタ
this.type = type;
this.bark = function(){ // メソッド
console.log(voice);
};
}
@kasei-san
kasei-san / application.rb
Last active December 11, 2015 08:58
RSpec on Railsで、controllerで使うライブラリのテストをする (環境 : ruby 1.9.2, rails : 3.0.9, rspec-rails : 2.1.12)
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module AppLibTest
class Application < Rails::Application