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)
とある文字以降を削除
以降を削除、という書き方は以下。
.+
. は改行を除く任意の一文字のこと。
- は直前の文字列やメタ文字の1回以上の繰り返しのこと。
例)空白以降を削除
.+
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)がなかったので自前のテザリングで参加。
※会場での借りる手続きがうまくされていなかった模様。
お手軽に環境作る話
- 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のアカウントを作っておくこと)
Swaggerは64bitマシン+IEで動かない
32bitは動く。
64bitだと画面が真っ白。
※原因は不明。
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する方法ってどうやるんだろう??