Skip to content

Instantly share code, notes, and snippets.

wokamoto wokamoto

Block or report user

Report or block wokamoto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wokamoto
wokamoto / remote-site-parts.php
Last active Sep 7, 2018
[WordPress][Plugin] 外部サイトをクロールして、特定の要素を XPath で切り出して表示するウィジェット
View remote-site-parts.php
<?php
/**
* Adds Remote_Site_Parts widget.
*/
add_action( 'widgets_init', function(){
register_widget( 'Remote_Site_Parts' );
});
class Remote_Site_Parts extends WP_Widget {
private $options = [
'title' => 'Title:',
@wokamoto
wokamoto / doing-wp-cron.sh
Created Aug 22, 2018
WordPress の cron event を wp-cli で実行するやつ
View doing-wp-cron.sh
#!/bin/bash
wp_root=${1:-/var/www/html}
wp="/usr/local/bin/wp --path=${wp_root}"
if [ ! -e ${wp_root} ]; then
echo "Not exists ${wp_root}"
exit 1
fi
lock_file="/var/tmp/doing_wp-cron.$(basename $wp_root)"
@wokamoto
wokamoto / after_install.sh
Created Aug 16, 2018
amimoto での CodeDeply サンプル
View after_install.sh
#!/bin/bash
service nginx reload
service monit start
if [ -d /var/cache/myapp ]; then
rm -rf /var/cache/myapp
fi
@wokamoto
wokamoto / update-distribution.sh
Created May 1, 2018
[AWS][CloudFront] 既存の CloudFront をまとめて IPv6 Enabled に変更する ref: https://qiita.com/wokamoto/items/7eef100532fcced8d6d0
View update-distribution.sh
#!/bin/bash
DIST_IDS=$(aws cloudfront list-distributions | jq -r '.DistributionList.Items[] | select(.IsIPV6Enabled == false) | .Id')
for DIST_ID in ${DIST_IDS}; do
ETAG=$(aws cloudfront get-distribution --id ${DIST_ID} | jq -r '.ETag')
CONFIG_JSON=$(mktemp)
jq -s '.[0] * .[1]' <(aws cloudfront get-distribution --id "${DIST_ID}" | jq '.Distribution.DistributionConfig') <(echo '{"IsIPV6Enabled": true}') > ${CONFIG_JSON}
aws cloudfront update-distribution --id ${DIST_ID} --distribution-config file://${CONFIG_JSON} --if-match ${ETAG}
rm -f ${CONFIG_JSON}
done
@wokamoto
wokamoto / file0.txt
Created Mar 2, 2018
[AWS] CloudFront が使用する IP レンジを調べる ref: https://qiita.com/wokamoto/items/fd9c064c3608912085c1
View file0.txt
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="CLOUDFRONT")
@wokamoto
wokamoto / file0.txt
Last active Apr 8, 2019
[WordPress] 負荷がかかっている処理を見つけるのに wp profile がとても便利だった ref: https://qiita.com/wokamoto/items/3902278e658ba856f1a9
View file0.txt
$ 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 Feb 23, 2018
[WordPress][Nginx] Nginx 1.13.9 に実装された http2_push_preload を使って HTTP/2 push してみる ref: https://qiita.com/wokamoto/items/63b47c1b320807d6380b
View file0.txt
$ sudo /opt/local/provision
$ nginx -v
nginx version: nginx/1.13.9
@wokamoto
wokamoto / http2_push.php
Last active Jun 8, 2018
[WordPress]http2_push.php
View 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 Feb 5, 2018
[AWS][Terraform] Terraform で Amazon Inspector を導入する ref: https://qiita.com/wokamoto/items/3a331a7d30a26d6ce9f1
View cloudwatch-events-iam-role.tf
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 Jan 24, 2018
[WordPress] wp_is_mobile() を CloudFront に対応させる
View cf_wp_is_mobile-fx.php
<?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'] ) {
You can’t perform that action at this time.