2014/07/17

git 理解深める

git config --global alias.co checkout ==>カスタマイズ
git config --global core.editor "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
.gitignore
==>
/.bundel
/db/*.sqlite3
/db/*.sqlite3-
/log/*.log


git log

remote/master
--->git clone ../...を実行する
local:master

リモートサーバーは更新された!
git fetch origin ==>リモートの更新を取得する

git remote add theName address ==>remote サーバー追加、ローカルでtheNameの名前で
git fetch name==>


Git 開発者の多くはこの考え方にもとづいた作業の流れを採用しています。つまり、完全に安定したコードのみを master ブランチに置き、いつでもリリースできる状態にしているのです。それ以外に並行して develop や next といった名前のブランチを持ち、安定性をテストするためにそこを使用します。常に安定している必要はありませんが、安定した状態になったらそれを master にマージすることになります

・git push -u origin masterとすると、次回からは git pushだけでorigin masterにpushする
==>For every branch that is up to date or successfully pushed, add
           upstream (tracking) reference

・git checkout -b modified-locally 
git branch==->全てのブランチ

・localで、
git checkout old-branch
git merge new-branch
==>new-branchをold-branchにmergeする
git branch -d new-branch
git branch -D new-branch--->mergeしていない物があってもDELETE!

・config
git config  --add receive.denyCurrentBranch ingore
git push
===>git config --unsetall key

・ちなみにcommit -vをすると、今から何をコミットしようとしているかのdiffなどが見れるからより安心

ansible 特殊 オプション

対象ホスト:
    hosts:
    [test-sever]
    test-test-[1:2][1:6]

テストオプション
★--list-hosts 対象ホスト名をリストするだけ、ほかに何もしない
    ansible test-server -m ** -a "...." -i hosts --list-hosts
    =>
    test-test-11..test-test-16
    test-test-21..test-test-26

★-l されにホストのfilterである!
  ansible test-server -m ** -a "...." -i hosts -l test-test-11 ==>test-test-11だけ対象になる
  ansible test-server -m ** -a "...." -i hosts -l test-test-1* ==>test-test-11~16 対象になる

★-f 一回実行する数
★-C テストモード

2014/07/15

Ruby On Rails

・ruby をインストールする
==>環境変数に追加する
・DevKit
ーー>downloadして解凍し、インストールする
ruby dk.rb init
==>rubyのディレクトリをconfi.ymlにincludeする
ruby dk.rb install

gem update --system
gem update rake
gem install rails

エラー==>x86_64-w64-mingw32-gcc command not found
    ==>devkitのバージョンが間違った!!


rails new blog
==>project作成

bundle install
==ー>projectを配置する

rake db:create
=->dbを作成する、sqlite is default

rails server
==>serverを起動する

=->地雷:no source of timezone data
----------
Try changing the tzinfo-data line in your Gemfile to gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin] and then running bundle update.

The :x64_mingw platform option is needed to match 64-bit Windows MinGW builds of Ruby (such as the RubyInstaller x64 builds).
bundel update
---------

rails g controller home index
rails g scaffold post name:string title:string content:text
=>postのapp Templateみたいな物!



class Post < AcitveRecond :: Base
end

==>AcitveRecond :: Baseを継承しているから、CRUD、validate、などすごい機能があります。

==>何となくPLAY Frameworkに似っている!!。同じスタイル!

rails g model comment commenter:string body:text post:references

rake db:migrate===>dbを更新する,modle更新の後で。。

linux awk

ファイルを行ベースで読み込んで、ディフォルトにスペースを使ってその
行をsplitする

awk '{pattern + action}' {filename}
 -F フィルド分割用
 

cat /etc/passwd | awk -F ':' '{print $1}'
=>etc/passwdのアカウントだけ
cat /etc/passwd | awk -F ':' '{print $1"\t"$7}'

・header,tailerを出力
cat /etc/passwd | awk -F ':' 'Begin {print "name,shell"} {print $1"\t"$7} {print "blue,/bin/nosh"}'

・awk -F: '/root/' /etc/passwd
==>rootを含める行を出力する

linux vi 置換 行

%1,10s/a/b/g
==>1行目から10行目まで

%11s/a/b/g
==>11行目から

2014/07/14

bash pass array as paramater

baba=booba
variable=baba
echo ${variable} # baba
echo ${!variable} # booba
==>!の使い方==>更にこれを変数として扱う

bashの引数はそもそもARRAYに入れている!こいつです==>$@

---------
show_array(){
for port in $@
do
    echo $port
done
}
show_array 1 2 3
==>OK

show_array(){
arrayParam=$@
for port in $array
do
    echo $port
done
}
show_array 1 2 3
==>OK

arr=(1 2 3)
show_array(){
for port in $@
do
    echo $port
done
}
show_array ${arr[@]}
=>OK

${arr[@]}==>[@]がないと、C言語と同じ、始めの一つのパラメータだけ対象になる

#===>長さの意味で。。。

2014/07/03

ajax



借助于Ajax,可以在用户单击钮时,使用JavaScriptDHTML立即更新用户页面,并向服出异步行更新或查询数据操作。当求返回,就可以使用JavaScriptCSS来相地更新面中的某一部分,而不是刷新整个面(節約!!)最重要的是,用甚至不知道浏览器正在与服器通信(危ない?水面下のやりとりで、複雑になるWeb站点看起来像是即作出响

基于Ajax用需要增加大量JavaScript,增加大量JavaScript后的Web面在第一次加载时速度将比传统Web面慢==>複雑

avaScript本身不是面向象的言,这严重限制了JavaScript的可重用性。JavaScript并没有一个完善的调试工具,无形中也加重了程序担==>今のところ何となく改善された?

Ajax术则是用入一个字符,用都将向服送一次求==>監視
ちょっと使って、痒いところを少し触って、ユーザーに少し快感を与える程度でいいと思う。。。。。。。

angularJS scope.$apply

JavaScript is Turn Based
私たちが記述するJavaScriptのコードは一度に全て実行されるのではなく、ターンベースで実行される。各ターンは始めから終わりまで中断せずに走り、ターンが走っている間はブラウザ上では何も起きない。他のどのJavaScriptのコードも走っていない時は、Webページインタフェースは完全に固まる。だから不十分なJavaScriptコードはウェブページの動きを止めてしまう。

変更した時に通知でき、ページを更新できる。==>EmberJS や KnockoutJS

どのJavaScriptコードのターンが終わった時でも、値が変化したことを確認する。=>AngularJS
この戦略を動かすためには、データが変更された可能性がある時点を知る必要がある。そしてこれが $scope.$apply が動き始める場所だ。
  $scope.$apply(function () { $scope.msgs.push(JSON.parse(msg.data)); });

==>このapplyの中の物は、後で実行される感じだね。。。

JavaScript EventSource

・どこの仕様?Server-Sent Eventsで
var source = new EventSource("/chatFeed/");

# receive messages
$scope.chatFeed.addEventListener("message", $scope.addMsg, false);
/** handle incoming messages: add to messages array */
    $scope.addMsg = function (msg) {
        $scope.$apply(function () { $scope.msgs.push(JSON.parse(msg.data)); });
    };

・サーバー側は、必ず text/event-stream という MIME type で返さなければならない。
 /** Controller action serving activity based on room */
  def chatFeed(room: String) = Action { req =>
    println(req.remoteAddress + " - SSE connected")
    Ok.feed(chatOut
      &> filter(room)
      &> Concurrent.buffer(50)
      &> connDeathWatch(req.remoteAddress)
      &> EventSource()
    ).as("text/event-stream")
  }
 
==>
handle data streams reactively
I know, the method's name "&>" can make some of you go away. Please stay! This sign is like the pipe in bash. It is very easy to understand:
fileLineStream(file) &> lineParser
==>fileLineStream(file).through(lineParser)


Server-Send Events
When we want to send events in "real time" to the browser, what technologies are available?

    polling: the browser pools the server every x milliseconds to check if there is a new message. This method is not very efficient, because a lot of requests are necessary to give the illusion to update the application in real time.
    long-polling (or Comet): the browser opens a connection to the server (for example in a iframe), and the server keeps the connection opened. When the server wants to push data to the client, it sends this data with the opened connection. The client receives the data, and opens a connection again for further messages. With this method, the browser is always showing that it is waiting for data. This technology does not scale on threaded system, as each opened connection uses a thread. In JEE environment, we need an asynchronous servlet 3.1 not to make the server exploding.
    Server-Send Events (SSE) are quite similar to Comet. The main difference is that the browser manages this connection. For example, it opens the connection again if it falls.
    WebSockets provide a bi-directional, full-duplex communications channels. It is a different protocol than HTTP.

I choose to use Server-Send Events instead of WebSockets because of the following reasons:

    I've already played with WebSockets and wanted to try something new.
    WebSockets are great and can communicate in both directions. But this technology is a new protocol, sometimes difficult to integrate in an existing infrastructure (Proxy, Load-Balancer, Firewall...) Server-Send Events, on the other hand, use the HTTP protocol. The PaaS Heroku does not support WebSockets yet, but support SSE. When pushing data from the server to clients is all what you need, SSE can be what is the most appropriate and is well supported (except in IE for the moment)