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でファイル内の文字列を再帰的に置換するコマンド
Re:dash SQLクエリ内で変数を使う方法
メモ。クエリが複数になるとエラーになるっぽい
SELECT id, (SELECT @date := huga) AS date, FROM hoge
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, } });
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)
も変更する必要がある
参考:
first_nameカラム、last_nameカラムからフルネーム検索するメソッド
Controller:
class ProfilesController < ApplicationController def search @profiles = Profile.search_by_full_name(search_params[:name]) end private def search_params params.require(:search_profile).permit(:name) end end
Model:
class Profile < ApplicationRecord def self.search_by_full_name(query) query.delete!(' ') where("CONCAT_WS('', first_name, last_name) LIKE ?", "%#{query}%") end end
いろいろ応用できそう
Webpack v1からv2へのマイグレーションメモ
自分が使っていたところだけを簡単に。詳しくはhttps://webpack.js.org/guides/migrating
以下、webpack.config.js
の変更点:
resolve.extenstions
空の文字列は必要なくなったので削除する。ちなみにデフォルトでは.js
、.json
がresolveされている。
// v1 resolve: { extensions: ["", ".js", ".json"], }, // v2 resolve: { extensions: [".js", ".json"], },
拡張子を指定することで./foo
がjs
ファイルならばrequire("./foo")
が可能になる。
module.loaders
とmodule.rules
module.loader
のシンタックスはまだサポートされているが、module.rules
にかえるほうが望ましい。
// v1 module: { loaders: [ { test: /\.css$/, loader: [ "style-loader", "css-loader?modules=true" ] } ] } // v2 module: { rules: [ { test: /\.css$/, use: [ { "style-loader" }, { "css-loader", options: { module: true } } ] } ] }
loader
のチェイン
複数のloaderを!
でつなげるのはmodule.loaders
オプションでしか使えない。
// v1 module: { loaders: [ { test: /\.css$/, loader: "style-loader!css-loader" } ] } // v2 module: { rules: [ { test: /\.css$/, use: [ "style-loader", "css-loader" ] } ] }
-loader
の省略はできなくなった
loader
指定時に、-loader
を省略することはできなくなった。
// × module: { rules: [ { use: [ "style", "css", "less" ] } ] } // ○ module: { rules: [ { use: [ "style-loader", "css-loader", "less-loader" ] } ] }
json-loader
を指定する必要はなくなった
json-loader
がなくとも、自動的にJSONファイルを読み込む。
// × module: { rules: [ { test: /\.json/, loader: "json-loader" } ] } // ○ module: { rules: [ ] }
module.preLoaders
とmodule.postLoaders
は削除された
// v1 module: { preLoaders: [ { test: /\.js$/, loader: "eslint-loader" } ] } // v2 module: { rules: [ { test: /\.js$/, enforce: "pre", loader: "eslint-loader" } ] }
UglifyJsPlugin
sourceMap
UglifyJsPlugin
のsourceMap
オプションはデフォルトでfalse
になった。sourceMap
が欲しい場合にはtrue
設定する必要がある。
devtool: "source-map", plugins: [ new UglifyJsPlugin({ sourceMap: true }) ]
UglifyJsPlugin
warnings
UglifyJsPlugin
のcompress.warnings
オプションはデフォルトでfalse
になった。warnings
が欲しい場合にはtrue
設定する必要がある。
devtool: "source-map", plugins: [ new UglifyJsPlugin({ compress: { warnings: true } }) ]
UglifyJsPlugin
minimize loaders
UglifyJsPlugin
はloadersをminimizeモードに切り替えなくなった。
loadersのminimize
モードは webpack 3 以降に削除される。
古いloadersとの互換性を保つために、pluginを用いてminimizeモードに切り替えることができる。
plugins: [ new webpack.LoaderOptionsPlugin({ minimize: true }) ]
DedupePlugin
は削除された
webpack.optimize.DedupePlugin
はもう必要ないのでwebpack
の設定から削除する。
OccurrenceOrderPlugin
はデフォルトで設定される
もうわざわざ指定する必要はない。
debug
webpack 1 では、debug
オプションはloadersをdebugモードに切り替える。
loadersのdebug
モードは webpack 3 以降に削除される。
古いloadersとの互換性を保つために、pluginを用いてdebugモードに切り替える。
plugins: [ new webpack.LoaderOptionsPlugin({ debug: true }) ]