Skip to content

Instantly share code, notes, and snippets.

@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 Nov 21, 2019
[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'] ) {
@wokamoto
wokamoto / gist:6ca10bced5ca18562273745b50a7a428
Created Jan 22, 2018
[WordPress][CloudFront] ログイン時にプレビューが即時反映されない問題に対する fix 案
View gist:6ca10bced5ca18562273745b50a7a428
<?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 Dec 22, 2017
[WordPress] Redis Object Cache プラグインとか導入するとキャッシュがきつすぎてオプションが保存されない時あるよね ref: https://qiita.com/wokamoto/items/3498bb74d492258585f7
View file0.txt
<?php
wp_cache_delete ( 'alloptions', 'options' );
?>
@wokamoto
wokamoto / chk-certificates.sh
Last active Jul 7, 2017
[Bash] シェルスクリプトで Nginx に設定されているサーバ証明書の情報を取得する ref: http://qiita.com/wokamoto/items/ca63374dd4b0266ec0a1
View chk-certificates.sh
#!/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 Jun 13, 2017
[stripe][AWS] Stripe の Event を CloudWatch custom metrics に記録 ref: http://qiita.com/wokamoto/items/060b7cc4e458f4bba4d3
View file2.txt
$ npm install stripe
View brew_update.sh
$ sudo chown -R $(whoami):admin /usr/local
$ brew update
$ sudo chown root:wheel /usr/local
View index.php
<?php
ob_start();
require_once(dirname(dirname(__FILE__)).'/twentytwelve/index.php');
header('Content-Length: '.ob_get_length());
ob_end_flush();
@wokamoto
wokamoto / handler.js
Last active May 24, 2017
[AWS][Lambda] Lambda で Typetalk に投稿するサンプル ref: http://qiita.com/wokamoto/items/44c0439c0e56fd6e0035
View handler.js
'use strict';
module.exports.hello = (event, context, callback) => {
const https = require('https');
const querystring = require('querystring');
const typetalk_talken = process.env.TYPETALK_TOKEN;
const typetalk_room = process.env.TYPETALK_ROOM;
const options = {
hostname: 'typetalk.in',