dogwood008の開発メモ!

最近のマイブームは機械学習, Ruby on Rails。中でも機械学習を使った金融商品の自動取引に興味があります。

【JavaScript】console.group() を使ったログのグルーピング

要旨

console.log('lv. 0')
console.group()
console.log('lv. 1')
console.groupEnd()
console.group()
console.group()
console.log('lv. 2')
console.groupEnd()
console.log('lv. 1')
console.groupEnd()
console.log('lv. 0')

console.group() を使ったログのグルーピング
console.group() を使ったログのグルーピング

詳細

複数回 console.group() を呼べば入れ子も可能。

参考

developer.mozilla.org

【git】カレントブランチをpushするワンライナー

要旨

git push origin `git rev-parse --abbrev-ref HEAD`

詳細

git rev-parse --abbrev-ref HEADは、現在居るブランチの名前を返してくれる。下記がその例。

$ git rev-parse --abbrev-ref HEAD
feature/add_comission

git push origin ${BRANCH_NAME} は、 origin に対し、 ${BRANCH_NAME} をpushする。

なのでこれを組み合わせると、ワンライナーで現在居るブランチをリモートにpushできる。

ちなみに、筆者は下記のようにエイリアスに登録して使っている。

alias gpuo-='git push origin `git rev-parse --abbrev-ref HEAD`'

参考

git-scm.com

git-scm.com

【JavaScript】classの使い方、Rubyとの対比

要旨

class Person {
  constructor(name, height, weight) {
    this.name = name
    this.height = height
    this.weight = weight
  }

  getData () {
    return {
      name: this.name,
      height: this.height,
      weight: this.weight,
    }
  }
}
taro = new Person('taro', 180, 60)
console.log(taro.getData())  // => {name: 'taro', height: 180, weight: 60}

classをJSで使用する例
classをJSで使用する例

詳細

Rubyで書いたらこんな感じ。

class Person
  def initialize(name, height, weight)
    @name = name
    @height = height
    @weight = weight
  end

  def getData
    return {
      name: @name,
      height: @height,
      weight: @height,
    }
  end
end

taro = Person.new('taro', 180, 60)
taro.getData  # => {:name=>"taro", :height=>180, :weight=>180}

classの定義はホイスティングされないので注意。

参考

developer.mozilla.org