Skip to content

Instantly share code, notes, and snippets.

View shield-9's full-sized avatar

Daisuke Takahashi shield-9

View GitHub Profile
@shield-9
shield-9 / detect-resize.js
Created February 27, 2014 14:53
あんまり使う場面はないだろうけれど、ドキュメントの横幅が変更されたら特定の挙動をするためのJS
$(window).resize(function() {
if(!isset() or $(document).width() != document_width) {
/* Actions.... */
var document_width = $(document).width();
}
});
function isset() {
if(typeof(document_width) == 'undefined')
return false;
@shield-9
shield-9 / protect-wp-config.conf
Created April 3, 2014 13:59
Protect DB information from human error in server configuration settings
<Files "wp-config.php">
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ - [R=404,L]
</IfModule>
<IfModule !mod_rewrite.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
@shield-9
shield-9 / dhclient-exit-hooks
Created April 21, 2014 04:07
ConoHaの /etc/dhcp/dhclient-exit-hooks が天然記念物のような環境では動かないことがあるので修正版を作ってみた
#!/bin/bash
FIRST=$(/sbin/ifconfig eth0|grep -i global|head -n 1|cut -d ":" -f2,3,4,5)
SECOND=$(/sbin/ifconfig eth0|grep -i global|head -n 1|cut -d ":" -f6,7,8,9|cut -d "/" -f1)
if [ -z "${FIRST}" -o -z "${SECOND}" ]; then
exit 0
fi
case "${SECOND}" in
@shield-9
shield-9 / clear-swap.sh
Created June 10, 2014 14:57
Spell to clear swap
service memcached stop; service mysqld stop; service httpd stop; swapoff -a; swapon -a; service httpd start; service mysqld start; service memcached start
#!/bin/bash
FIRST=$(ip a show dev eth0|grep -E 'inet6 (.+) scope global'|head -n 1|sed -e "s/^ *inet6 *//g"|cut -d ":" -f1,2,3,4)
SECOND=$(ip a show dev eth0|grep -E 'inet6 (.+) scope global'|head -n 1|cut -d ":" -f5,6,7,8|cut -d "/" -f1)
if [ -z "${FIRST}" -o -z "${SECOND}" ]; then
exit 0
fi
case "${SECOND}" in
@shield-9
shield-9 / ALTER.sql
Created November 8, 2014 08:51
Convert WordPress Database from MyISAM to InnoDB (This works for only me!)
ALTER TABLE ew_wp_commentmeta ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE ew_wp_2_commentmeta ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE ew_wp_3_commentmeta ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE ew_wp_5_commentmeta ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE ew_wp_commentmeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ew_wp_2_commentmeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ew_wp_3_commentmeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ew_wp_5_commentmeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
@shield-9
shield-9 / i18n_repo.sh
Last active August 29, 2015 14:18
WordPress 4.2 Releasing Notes
svn co https://i18n.svn.wordpress.org/ja/
svn copy trunk branches/4.2
cd branches/4.2
mkdir messages
cd messages
wget https://translate.wordpress.org/projects/wp/dev/ja/default/export-translations?format=po -O ja.po
wget https://translate.wordpress.org/projects/wp/dev/ja/default/export-translations?format=mo -O ja.mo
wget https://translate.wordpress.org/projects/wp/dev/admin/network/ja/default/export-translations?format=po -O admin-network-ja.po
@shield-9
shield-9 / le-renewal.sh
Created February 8, 2016 04:23
Let's Encrypt Auto-renew
./letsencrypt-auto certonly --apache --keep -d extendwings.com -d www.extendwings.com
./letsencrypt-auto certonly --apache --keep -d aigis.pw
./letsencrypt-auto certonly --apache --keep -d shield-9.org
sudo apachectl graceful
@shield-9
shield-9 / icat-v1.js
Last active February 22, 2016 19:17
IPA icat for JSON Refactor
if(!window.jQuery) {
var script = document.createElement('script');
script.src = "//code.jquery.com/jquery-1.11.3.min.js";
document.head.appendChild(script);
}
(function($){
$.support.cors = true;
var layout = "icat";
@shield-9
shield-9 / demo.sql
Last active March 18, 2016 06:32
MySQL Sequence Emulation (Licensed under CC0)
INSERT INTO sequence values('one', 100);
INSERT INTO sequence values('two', 1000);
SELECT sequence('one');
SELECT sequence('two');
SELECT sequence('one');
SELECT sequence('one');
SELECT sequence('two');