【SQL】今週の日曜日・今週の土曜日を求める

メモ:

CURRENT_DATE - interval (DAYOFWEEK(CURRENT_DATE) - 1) day AS THIS_SUNDAY

日曜日始まりとする。 今日の曜日インデックス(DAYOFWEEK(CURRENT_DATE))から日曜日の曜日インデックスを引くと、今日が日曜日から何日目かが分かる。

CURRENT_DATE + interval (7 - DAYOFWEEK(CURRENT_DATE)) day AS THIS_SATURDAY

土曜日の曜日インデックスから今日の曜日インデックスを引くと、土曜日は今日から何日目かが分かる。

もしかしたらそれ用の関数とか用意されてるのだろうか

Alpineでパッケージをインストールしようとしたらエラーがでたので解消する

メモ

ERROR: unsatisfiable constraints:
  py-pip (missing):
    required by: world[py-pip]
ERROR: Service 'web' failed to build: The command '/bin/sh -c apk add py-pip' returned a non-zero code: 1

インストール可能なパッケージ一覧(インデックス)の更新オプションを付けると解消される (--update)

apk add --update py-pip

Macでファイル内の文字列を再帰的に置換するコマンド

カレントディレクトリ以下すべてのファイル内のHOGEという文字列をFUGAに置換する

find ./ -type f | xargs sed -i '' 's/HOGE/FUGA/g'
  • xargs … 標準入力から受け取ったデータを、任意のコマンドに引数として与えるコマンド

  • sed … StreamEditor. 入力ストリームに対する文字列の置換を行う。Linux のものとは微妙に動作が異なるらしい

参考: Macでsedコマンドが思うように動かなくてハマった

Warning: Material-UI: The white color was not parsed correctly, because it has an unsupported format (color name or RGB %). This may cause issues in component rendering.

const muiTheme = getMuiTheme({
  raisedButton: {
    textColor: 'white',
    color: purple900,
  }
});

こんな感じにMaterial-UIの色を変えて遊んでたらエラーが出た:

Warning: Material-UI: The white color was not parsed correctly,
  because it has an unsupported format (color name or RGB %). This may cause issues in component rendering.

ヘックスコードに変えれば問題はない:

const muiTheme = getMuiTheme({
  raisedButton: {
    textColor: '#ffffff',
    color: purple900,
  }
});

参考: https://github.com/callemall/material-ui/issues/6781

Rails5 FactoryGirlでコールバックをスキップする方法

Rails4では使えたFoo.skip_callback(:create, :after, :bar)がRails5では使えない。

ArgumentError:
       After create callback :do_something has not been defined

対策として、次のようにFGにおいてメソッドを上書きする:

class User < ActiveRecord::Base
  after_create :run_something
end
FactoryGirl.define do
  factory :user do

    after(:build) do |user|
      class << user
       def run_something
         true
       end
      end
    end

    factory :user_with_run_something do
      after(:build) do |user|
        class << user
          def run_something
            super
          end
        end
      end
    end
  end
end

コールバックメソッドの発火タイミングによって、after(:build)も変更する必要がある

参考:

http://stackoverflow.com/questions/8751175/skip-callbacks-on-factory-girl-and-rspec/22916595#22916595

https://github.com/thoughtbot/factory_girl/issues/931