Skip to content

Instantly share code, notes, and snippets.

@wokamoto
wokamoto / gist:8838684
Last active Aug 29, 2015
[WordPress][Backlog API] WordPress から xmlrpc クライアントをしようして、backlog API を叩く
View gist:8838684
<?php
include_once( ABSPATH . WPINC . '/class-IXR.php' );
include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php');
add_filter( 'http_request_args', function( $args, $url ) {
if ( false !== strpos($url, 'example.backlog.jp') ) {
$args['headers']['Authorization'] = 'Basic '. base64_encode('backlog_user' . ':' . 'backlog_passwd');
}
return $args;
}, 10, 2 );
View gist:9066757
<?php
$mime_type = 'application/pdf';
$file_path = '/path/to/pdf';
header('Content-Disposition: inline; filename="'.basename($file_path).'"');
header('Content-Length: '.filesize($file_path));
header('Content-Type: '.$mime_type);
readfile($file_path);
View gist:9066721
<?php
$mime_type = 'application/pdf';
$file_path = '/path/to/pdf';
// for IE 8 ( see http://support.microsoft.com/kb/323308/ja )
$expires = 30;
header("Last-Modified: ". gmdate("D, d M Y H:i:s", filemtime($file_path)). " GMT");
header("Expires: " . date(DATE_RFC1123, time() + $expires));
header("Pragma: cache");
header("Cache-Control: max-age={$expires}");
@wokamoto
wokamoto / gist:9225119
Created Feb 26, 2014
[WordPress] Nginx Cache Controller でデバイスごとにキャッシュキーを変更しているときにそれらのキャッシュを全部消す方法
View gist:9225119
<?php
function nginx_flush_cache( $url ) {
if ( !$url )
return;
$params = array(
'@ktai',
'@smartphone',
'@smartphone.off',
);
foreach ( $params as $param ) {
@wokamoto
wokamoto / gist:9342751
Last active Aug 29, 2015
[Nginx] オレオレ CDN
View gist:9342751
server {
listen 80;
location /example.com {
resolver 127.0.0.1;
rewrite ^/example.com/(.+) $1 break;
proxy_cache czone;
proxy_cache_key "$scheme://$host$uri$args";
View gitlab_init.sh
#!/bin/sh
PUBLIC_HOST_NAME=`/usr/bin/curl http://169.254.169.254/latest/meta-data/public-hostname`
yes | crontab -r
su - git
PUBLIC_HOST_NAME=`/usr/bin/curl http://169.254.169.254/latest/meta-data/public-hostname`
INSTANCE_ID=`/usr/bin/curl http://169.254.169.254/latest/meta-data/instance-id`
echo "GRANT ALL PRIVILEGES ON *.* TO gitlab@localhost IDENTIFIED BY '$INSTANCE_ID';" | mysql -u root
@wokamoto
wokamoto / gist:9500102
Last active Aug 29, 2015
Amazon Linux に gitlab 入れるメモ
View gist:9500102
# t1.micro の場合 unicorn 起動時にメモリ足りなくなるので swap 作っておく
dd if=/dev/zero of=/swapfile bs=1024 count=2097152
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
echo '
vm.swappiness=0' >> /etc/sysctl.conf
# PublicDNS の取得
@wokamoto
wokamoto / apache.conf
Last active Aug 29, 2015
[WordPress][Apache][Nginx] xmlrpc.php を Web サーバレベルで無効にする
View apache.conf
<Files ~ "xmlrpc.php$">
deny from all
</Files>
View nginx.conf
http {
# : (略)
upstream backend {
server localhost:8080;
}
upstream backend_admin {
server master.server:8080;
}
@wokamoto
wokamoto / gist:9659672
Created Mar 20, 2014
[WordPress] wp-cli でユーザのパスワードを変更
View gist:9659672
$ cd /path/to/wordpress
$ wp user list
+-----+-----------------+--------------------------+---------------------------------+---------------------+---------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+-----+-----------------+--------------------------+---------------------------------+---------------------+---------------+
| 1 | hogehoge | hogehoge | hogehoge@example.com | 2014-03-20 00:00:00 | administrator |
+-----+-----------------+--------------------------+---------------------------------+---------------------+---------------+
$ wp user update 1 -user_pass=fugafuga
Success: Updated user 1.