Log.log(work)

いろんな作業メモ

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シルバー試験を受験します!

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


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

data-のカスタム属性に対してtoggleClassしたかったんだけどやり方がわからなかった

環境

jQuery v2.1.4
Google Chrome

やりたいこと

よくECサイトで商品のレビューに☆が5つあって、該当する星を塗るという項目があるが、これをjQueryで実装してみた。

クリックした場所をdata-starで取得して、
それより低い数値のliに「glyphicon-star」(★)を、そうではないliに「glyphicon-star-empty」(☆)をセットしようと考えてみたが、他のdata-startのset方法がよくわからなかった。

<ul id="stars" class="star_list">
  <li class="glyphicon glyphicon-star-empty" data-star="1"></li>
  <li class="glyphicon glyphicon-star-empty" data-star="2"></li>
  <li class="glyphicon glyphicon-star-empty" data-star="3"></li>
  <li class="glyphicon glyphicon-star-empty" data-star="4"></li>
  <li class="glyphicon glyphicon-star-empty" data-star="5"></li>
</ul>
$(function () {
    $('#stars').on("click","li",function () {
        for (var i = 4; i >= 0; i--) {
            if (i < $(this).data("star")|0 ) {
              // 要素の書き方が分からない・・・
              ???.toggleClass("glyphicon glyphicon-star");
            } else {
              ???.toggleClass("glyphicon glyphicon-star-empty");
            }
        }
    });
});


結局、idを振ってattrする方法で実現できたけど、data-に対してクラスをsetする方法ってどうやるんだろう??

rake でversion違うYOっていきなり怒られた。

朝、出社して リモートのmasterをpullして最新にしたのち、branchを作ってローカルで確認していた。
でもこれはcommitするものではなかったので、しばらくしてリモートでローカルを上書きしようとして最新を取り込もうとしたらどうやらこれはまずかったのかもしれない。

statusで確認してコミットしないファイルを

git rm --cached ファイル名

で変更履歴を削除したらそのファイルごと無くなってしまった。
予想と違う動きでちょっと焦り、

git reset --hard origin/master

で変更をなかったことにして、再度branchを切ってrake を実行したら下記のエラーが出た。

rake aborted!
Gem::LoadError: You have already activated rake 10.5.0, but your Gemfile requires rake 10.4.2. Prepending `bundle exec` to your command may solve this.

Gemfile.lockを見たら確かに10.4.2って書いてあるけど、いつのまに10.5.0が有効になっていたのか。。。

$ gem list rake

*** LOCAL GEMS ***

rake (10.5.0, 10.4.2, 10.1.0)

入ってる。
updateした記憶も入れた記憶もないけど、どこで10.5.0を覚えてきたのか。

とりあえず起動時にversionを指定できるので、下記のコマンドで確認はできたが、面倒なのでどうにかしたい。

rake _10.4.2_ routes

参考:
バージョンを指定してRakeを実行する - /var/log/kozy4324