Skip to content

Instantly share code, notes, and snippets.

@wokamoto
wokamoto / gist:5771b3b0b9b83d2e1642
Last active Jul 20, 2022
[PHP] Google Calendar API v3 から祝日取得
View gist:5771b3b0b9b83d2e1642
<?php
function get_holidays_this_month($year, $month){
// 月初日
$first_day = mktime(0, 0, 0, intval($month), 1, intval($year));
// 月末日
$last_day = strtotime('-1 day', mktime(0, 0, 0, intval($month) + 1, 1, intval($year)));
$api_key = 'YOUR API KEY HERE';
$holidays_id = 'outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com'; // mozilla.org版
@wokamoto
wokamoto / gist:b9eb0f22d9948a38544d
Last active Dec 15, 2021
[Nginx][WordPress] Nginx で WordPress の管理画面に BASIC 認証をかける ( ただし /wp-admin/admin-ajax.php, /wp-admin/css/*, /wp-admin/js/* にはかけない )
View gist:b9eb0f22d9948a38544d
location ~* /wp-login\.php|/wp-admin/((?!(admin-ajax\.php|css/|js/)).)*$ {
index index.php index.html index.htm;
# Basic認証のメッセージ
auth_basic "Please enter your ID and password";
# .htpasswd ファイルのパス
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
location ~ .*\.php$ {
try_files $uri =404;
@wokamoto
wokamoto / gist:9340462
Last active Apr 29, 2021
[Nginx] mobile-detect
View gist:9340462
set $mobile '';
set $mobile_off '';
if ($http_user_agent ~* '(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter|PSP)') {
set $mobile "@ktai";
}
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') {
set $mobile "@smartphone";
}
if ($http_cookie ~* "wptouch[^\=]+\=(normal|desktop)") {
set $mobile_off "${mobile}.off";
View Brewfile
cask_args appdir: "/Applications"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-versions"
tap "homebrew/cask-fonts"
tap "homebrew/core"
tap "argon/mas"
tap "rcmdnk/file"
View Feed2Typetalk.js
'use strict';
const lastUpdateFileName = './lastupdate.txt';
const feedUrl = 'https://example.com/rss';
const typetalkTopicNum = '__TYPETALK_TOPIC_NUMBER_HERE__';
const typetalkToken = '__TYPETALK_TOKEN_HERE__'
const fs = require('fs');
const FeedParser = require('feedparser');
const https = require('https');
View AllowWPAdminRequestFromLoggedInUser.json
{
"Name": "AdminRequestFromLoggedInUser",
"Priority": 8,
"Action": {
"Allow": {}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "AdminRequestFromLoggedInUser"
@wokamoto
wokamoto / gist:03fe3fc7534b78d25c30
Last active Dec 9, 2020
[Nginx][S3] Nginx で S3 をリバースプロキシするための設定
View gist:03fe3fc7534b78d25c30
location ~* ^/(get_s3)/(.*) {
set $s3_bucket 'your_s3_bucket_name.s3.amazonaws.com';
set $url_full "/$1/$2";
proxy_http_version 1.1;
proxy_set_header Host $s3_bucket;
proxy_set_header Authorization '';
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header Set-Cookie;
@wokamoto
wokamoto / replace-siteurl.php
Created Sep 4, 2012
WordPress のDB上のサイトURLを一気に変換
View replace-siteurl.php
#!/usr/bin/php
<?php
switch($argc) {
case 1:
case 2:
echo "please input new site url and wp directory name!\n";
exit();
default:
$old_site = isset($argv[3]) ? $argv[3] : '';
$path = $argv[2];
@wokamoto
wokamoto / user_meta_transient.php
Last active Dec 14, 2019
[WordPress] user_meta transient
View user_meta_transient.php
<?php
/**
* Delete a user meta transient.
*/
function delete_user_meta_transient( $user_id, $transient ) {
global $_wp_using_ext_object_cache;
$user_id = (int) $user_id;
do_action( 'delete_user_meta_transient_' . $transient, $user_id, $transient );
@wokamoto
wokamoto / cloudfront-preview-fix.php
Last active Dec 9, 2019
[WordPress] [CDN] CloudFront を前面に置いた時にプレビューが更新されないことってあるよね
View cloudfront-preview-fix.php
<?php
/*
Plugin Name: CloudFront Preview Fix
Plugin URI:
Description: WPログイン時にパーマリンクに記事変更日付を含み、プレビューが最新になるようにする
Version: 0.5
Author:
Author URI:
*/
add_action( 'init', function(){