分散協調サービス
部分障害を安全に処理できる分散アプリケーションを構築するための一連のツールを提供する
設定情報の集中管理や名前付けなどのサービスを提供する
ZooKeeperのアーキテクチャでは高可用性を冗長サービスにより提供している
クライアントはあるZooKeeperノードへの問い合わせが失敗したらほかのノードに問い合わせることができる
データの更新はマスターノードだけが行うようになっているので、データがノード間で矛盾した内容になることはない(ただし、最新のデータではない可能性はある)
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
# -*- coding: utf-8 -*- | |
module SomeModule | |
def self.included(klass) | |
klass.send(:include, SomeModule::Methods) | |
klass.send(:extend, SomeModule::ClassMethods) | |
end | |
module Methods |
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
/** | |
* node.jsを使った対話型コマンドラインツール | |
* node.jsはイベントループなので、他の言語のようにwhileで入力待ちしたりしなくていいのがすばらしい | |
* 入出力はreadlineを使う | |
*/ | |
var rl = require('readline'); // readline | |
var utl = require('util'); |
モデルに以下のように、クラス変数を用意し、mattr_accessorでアクセスできるようにしておく
ポイントは、self.setupメソッドのyield self
# app/models/user.rb
class User < ActiveRecord::Base
mattr_accessor :hoge_setting
# デフォルト値を設定しておく
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
# rails3.2からrails newでプロジェクトを作成するときのオプションを書いておくことができる | |
# 実際にプロジェクトを作成するときは`rails new myproject`で下記オプションが勝手に適用される | |
-T -d mysql --skip-bundle |
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
// pcでユーザーエージェントを偽装されてアクセスされていても、これである程度判定できるはず | |
function isTouchDevice() { | |
return ($.browser.mobile && (('createTouch' in document) || ('ontouchstart' in document)) && ('orientation' in window)); | |
} |
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
def recursive_symbolize_keys! hash | |
if hash.is_a? Hash | |
hash.symbolize_keys! | |
hash.values.each {|h| recursive_symbolize_keys! h} | |
elsif hash.is_a? Array | |
hash.map {|v| recursive_symbolize_keys! v} | |
end | |
hash | |
end |