Log.log(work)

いろんな作業メモ

MEANスタックの環境をつくる(途中)

OS: CentOS 6.7

Node.jsとnpmをinstall

sudo yum install epel-release
sudo yum install nodejs
node -v

バージョンでたらインストール完了

yum install -y npm --enablerepo=epel

npm も入れとく

Expressいれる

npm install express

MVSサイト構築

express コマンドを使ってサイトの雛形生成からサイトの動作確認まで行う

mkdir dev

cd dev

express myapp -e ejs

cd myapp 

npm install

npm start

サーバーが立ち上がったらローカルホスト:3000 で確認。


参考:
Node.js モジュール追加(Express) - Qiita

bootstrapをいれる

見た目よくするためにbowerを使ってインストール。
インストールしたら初期化しておく。

npm install -g bower

bower init

初期化の質問は下記参照:
Bowerまとめ(概要・導入・コマンド一覧) - Qiita


作業DIR上でbootstrapインストール ※依存関係にあるjqueryも同時に入る

bower install bootstrap --save


あとはMongoとAngular入れてひと段落。

sublime3 のPackage Controlのインストール

  • Proxyなしの場合
import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
  • Proxy環境下の場合

http://user:pass@address:port のユーザー名やパスワードは各自設定。

import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler('http': 'http://user:pass@address:port')) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

Gitでうっかり違うメアドでコミットしちゃった件

なんか知らない人がコミットしているというのがばれないように後で修正する。

rebaseの魔法を唱える

$ git rebase -i HEAD~2

エディタが開いて、行頭に pick がついたリストが出てくるので、
修正対象を「edit」に修正して:wq。

すると修正チャンス到来。

$ git rebase -i HEAD~2
Stopped at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx... hoge
You can amend the commit now, with

        git commit --amend

Once you are satisfied with your changes, run

        git rebase --continue

メアドとユーザーを変更してコミット。

shinomiya@foo ~foo (branch|REBASE-i 2/2)
$ git commit --amend --author="user.name <user@example.com>"
[detached HEAD 0000000] hoge
 Date: Thu Jun 16 19:46:27 2016 +0900
 1 file changed, 18 insertions(+), 18 deletions(-)

あとはrebase --continue で残りのコミットを走らせる。

shinomiya@foo ~foo (branch|REBASE-i 2/2)
$ git rebase --continue
Successfully rebased and updated refs/heads/branch.

Rails memo

Railsの話聞いてきた。
Railsの学びとキャリア02 ~未経験から無料のワンポイント研修とキャリアのノウハウ~ - Railsの学びと就業 | Doorkeeper

お手軽に環境が作れる話とRails(Silver)問題集が1000円で買えるという話につられてつい。
ネット環境(Wifi)がなかったので自前のテザリングで参加。
※会場での借りる手続きがうまくされていなかった模様。


Rails

ここらへんの話はもうちょっと聞きたかった。
キャリアアップ会社の人の話だったから仕方がないけど。

お手軽に環境作る話
  • Cloud9

割りとお手軽に環境を作れるサービス。
Web上で動いてる。
サーバーはUbuntu
c9.io

  • Cloud9内のRailsはバージョンが古いので

新しい方いれとく(古いままだと動かないことがあるらしい)
gem install rails -v 4.2.2

  • DBはPostgres。

installしとく(Postgres)
sudo service postgresql start

ログ:

shinomiya_1:~/workspace $ sudo service postgresql start
 * Starting PostgreSQL 9.3 database server
   ...done.
shinomiya_1:~/workspace $ sudo service postgresql stop
 * Stopping PostgreSQL 9.3 database server
   ...done.
shinomiya_1:~/workspace $ 
  • Cloud9コマンド

Cloud9の中のパラメータを引数として渡さんとあかんらしい。
→サーバー起動時のコマンド例
rails s -b $IP -p $PORT

  • Railsの試験勉強するにはCloud9はらくだね。

Railsの擬似問題
@ITに結構のっているので練習するにはOK。


  • Cloud9 上でRailsを作成する

今回は「achieve」という名前で作成。DBはpostgresql

rails _4.2.2_ new achieve -d postgresql


ログ:

shinomiya_1:~/workspace $ rails _4.2.2_ new achieve -d postgresql
      create  (省略)
         run  bundle install
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Resolving dependencies..........
Installing rake 11.1.2
Using i18n 0.7.0
Using json 1.8.3
Installing minitest 5.9.0
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types-data 3.2016.0221
Using arel 6.0.3
Installing debug_inspector 0.0.2 with native extensions
Using bundler 1.12.4
Installing byebug 9.0.4 with native extensions
Installing coffee-script-source 1.10.0
Installing execjs 2.7.0
Using thor 0.19.1
Using concurrent-ruby 1.0.2
Installing multi_json 1.12.1
Installing pg 0.18.4 with native extensions
Installing sass 3.4.22
Installing tilt 2.0.4
Installing spring 1.7.1
Installing rdoc 4.2.2
Using tzinfo 1.2.2
Using nokogiri 1.6.7.2
Using rack-test 0.6.3
Using mime-types 3.0
Installing binding_of_caller 0.7.2 with native extensions
Installing coffee-script 2.4.1
Installing uglifier 3.0.0
Using sprockets 3.6.0
Installing sdoc 0.4.1
Using activesupport 4.2.2
Using loofah 2.0.3
Using mail 2.6.4
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.3.6
Using activemodel 4.2.2
Installing jbuilder 2.4.1
Using rails-html-sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using activejob 4.2.2
Using activerecord 4.2.2
Using actionview 4.2.2
Using actionpack 4.2.2
Using actionmailer 4.2.2
Using railties 4.2.2
Using sprockets-rails 3.0.4
Installing coffee-rails 4.1.1
Installing jquery-rails 4.1.1
Using rails 4.2.2
Installing sass-rails 5.0.4
Installing web-console 2.3.0
Installing turbolinks 2.5.3
Bundle complete! 12 Gemfile dependencies, 55 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
         run  bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted
shinomiya_1:~/workspace $ 
Cloud9内部にGitが入っている

nameと emailは適当でもOK。

HerokuのToolbeltが入っているので

Cloud9で作成したアプリをHerokuに公開することもできる。
(Herokuのアカウントを作っておくこと)

宣言

2016年6月末までにRails4シルバー試験を受験します!

せっかく業務でも触れたので受験しようと思います。


追記:
キャンペーンで本がもらえるというのがあったので応募しようと思ったが、住所と氏名を送るフォームがセキュリティなしっぽいので自腹で買おうか考え中。