Skip to content

Instantly share code, notes, and snippets.

@wokamoto
wokamoto / file0.txt
Last active April 8, 2019 08:11
[WordPress] 負荷がかかっている処理を見つけるのに wp profile がとても便利だった ref: https://qiita.com/wokamoto/items/3902278e658ba856f1a9
$ wp package install git@github.com:wp-cli/profile-command.git
Installing package wp-cli/profile-command (dev-master)
Updating /home/ec2-user/.wp-cli/packages/composer.json to require the package...
Registering git@github.com:wp-cli/profile-command.git as a VCS repository...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Dependency resolution completed in 0.212 seconds
@wokamoto
wokamoto / file0.txt
Last active February 23, 2018 11:36
[WordPress][Nginx] Nginx 1.13.9 に実装された http2_push_preload を使って HTTP/2 push してみる ref: https://qiita.com/wokamoto/items/63b47c1b320807d6380b
$ sudo /opt/local/provision
$ nginx -v
nginx version: nginx/1.13.9
@wokamoto
wokamoto / http2_push.php
Last active June 8, 2018 07:48
[WordPress]http2_push.php
<?php
add_action('template_redirect', function(){
if ( headers_sent() ) {
return;
}
do_action('wp_enqueue_scripts');
foreach( array('style' => wp_styles(), 'script' => wp_scripts()) as $as => $wp_links ) {
$link = '';
@wokamoto
wokamoto / cloudwatch-events-iam-role.tf
Last active November 21, 2019 09:01
[AWS][Terraform] Terraform で Amazon Inspector を導入する ref: https://qiita.com/wokamoto/items/3a331a7d30a26d6ce9f1
esource "aws_iam_role" "run_inspector_role" {
name = "cloudwatch-events-run-inspector-role"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
@wokamoto
wokamoto / cf_wp_is_mobile-fx.php
Created January 24, 2018 01:46
[WordPress] wp_is_mobile() を CloudFront に対応させる
<?php
add_filter( 'wp_is_mobile', function( $is_mobile ) {
// CloudFront でスマートフォンと判定された場合、true を返す。
if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] ) {
$is_mobile = true;
}
// CloudFront でタブレットと判定された場合、true を返す。
// (タブレットはPCと同じ扱いにしたい場合は、$is_mobile を false にする
if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] ) {
@wokamoto
wokamoto / gist:6ca10bced5ca18562273745b50a7a428
Created January 22, 2018 08:04
[WordPress][CloudFront] ログイン時にプレビューが即時反映されない問題に対する fix 案
<?php
// CloudFront で Cookie key wordpress_last_visit をオリジンに渡すようにしておくこと
add_action( 'plugins_loaded', function(){
if ( is_user_logged_in() ) {
setcookie( 'wordpress_last_visit', time() );
}
});
@wokamoto
wokamoto / file0.txt
Created December 22, 2017 03:28
[WordPress] Redis Object Cache プラグインとか導入するとキャッシュがきつすぎてオプションが保存されない時あるよね ref: https://qiita.com/wokamoto/items/3498bb74d492258585f7
<?php
wp_cache_delete ( 'alloptions', 'options' );
?>
@wokamoto
wokamoto / chk-certificates.sh
Last active July 7, 2017 03:23
[Bash] シェルスクリプトで Nginx に設定されているサーバ証明書の情報を取得する ref: http://qiita.com/wokamoto/items/ca63374dd4b0266ec0a1
#!/bin/bash
LF=$(printf '\\\012_')
LF=${LF%_}
TAB=$'\t'
_ssl_keys=$(find /etc/nginx/conf.d/ -type f -name '*.conf' | xargs grep ssl_certificate | grep -v ssl_certificate_key | sed 's/[#:;]//g' | sort | uniq | awk '{print $1,$3}')
IFS=$LF
for _ssl_key in ${_ssl_keys}; do
_conf_file=$(echo ${_ssl_key} | awk '{print $1}')
_cert_key=$(echo ${_ssl_key} | awk '{print $2}')
@wokamoto
wokamoto / file2.txt
Last active June 13, 2017 08:39
[stripe][AWS] Stripe の Event を CloudWatch custom metrics に記録 ref: http://qiita.com/wokamoto/items/060b7cc4e458f4bba4d3
$ npm install stripe
@wokamoto
wokamoto / brew_update.sh
Created June 5, 2017 07:10
brew update
$ sudo chown -R $(whoami):admin /usr/local
$ brew update
$ sudo chown root:wheel /usr/local