Skip to content

Instantly share code, notes, and snippets.

@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(){
@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 / docomo_dialogue_api.php
Created Apr 3, 2015
docomo 雑談対話 API をさくっと php で使う
View docomo_dialogue_api.php
<?php
/*****
* https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=5
*****/
function webnist($text) {
$context_file = dirname(__FILE__).'/.docomoapi.context';
$api_key = 'your API key here';
$api_url = sprintf('https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=%s', $api_key);
$req_body = array('utt' => $text);
if ( file_exists($context_file) ) {