Skip to content

Instantly share code, notes, and snippets.

@murayama
murayama / zookeeper.md
Created July 9, 2013 01:54
ZooKeeperについて調査

ZooKeeperについて調査

ZooKeeperとは

分散協調サービス
部分障害を安全に処理できる分散アプリケーションを構築するための一連のツールを提供する
設定情報の集中管理や名前付けなどのサービスを提供する
ZooKeeperのアーキテクチャでは高可用性を冗長サービスにより提供している
クライアントはあるZooKeeperノードへの問い合わせが失敗したらほかのノードに問い合わせることができる
データの更新はマスターノードだけが行うようになっているので、データがノード間で矛盾した内容になることはない(ただし、最新のデータではない可能性はある)

@murayama
murayama / clitool.js
Created July 9, 2013 01:46
node.jsを使った対話型コマンドラインツール
/**
* node.jsを使った対話型コマンドラインツール
* node.jsはイベントループなので、他の言語のようにwhileで入力待ちしたりしなくていいのがすばらしい
* 入出力はreadlineを使う
*/
var rl = require('readline'); // readline
var utl = require('util');
@murayama
murayama / example.js
Last active July 24, 2019 06:40
asyncファンクションで例外が発生したら指定回数リトライする関数
retry(async (abort, num) => {
const res = fetch('https://xxxx').then(res => res.json());
if (condition) {
// 特定の条件の場合にリトライをしないで処理を抜ける場合はabortをコールする
abort(new Error('error message'));
}
}, {retryMax: 3, sleep: 300});
@murayama
murayama / touch.js
Created July 9, 2013 01:35
jsでタッチデバイスの判定
// pcでユーザーエージェントを偽装されてアクセスされていても、これである程度判定できるはず
function isTouchDevice() {
return ($.browser.mobile && (('createTouch' in document) || ('ontouchstart' in document)) && ('orientation' in window));
}
@murayama
murayama / recursive_symbolize_keys.rb
Created July 9, 2013 01:33
rubyでハッシュのキーを再帰的にシンボルに変換する
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
@murayama
murayama / new_gist_file_0
Created December 3, 2013 11:26
homebrewでvimインストール
brew install vim --override-system-vi --with-lua --with-ruby --with-python --with-python3
@murayama
murayama / sidekiq_push_client.php
Created October 22, 2013 08:46
rubyのsidekiqが処理するqueueをpushするPHPのクラス
<?php
namespace SidekiqPush;
/**
* rubyのsidekiqのphp版クライアント
*/
class Client {
private $redis;
private $namespace;
@murayama
murayama / deploy.rb
Created July 9, 2013 01:55
node.jsアプリケーションのcapistranoのdeployファイルの例
require 'capistrano_colors'
require 'capistrano'
require 'capistrano/ext/multistage'
set :application, "app_name"
set :repository, "repo path"
set :scm, "git"
set :branch, "master"
set :deploy_via, :copy
@murayama
murayama / module_sample.rb
Created July 9, 2013 01:50
rubyでモジュールを作るときの賢いやり方
# -*- coding: utf-8 -*-
module SomeModule
def self.included(klass)
klass.send(:include, SomeModule::Methods)
klass.send(:extend, SomeModule::ClassMethods)
end
module Methods