Skip to content

Instantly share code, notes, and snippets.

View ytkhs's full-sized avatar
On vacation

ytkhs ytkhs

On vacation
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ytkhs on github.
  • I am ytkhs (https://keybase.io/ytkhs) on keybase.
  • I have a public key whose fingerprint is 9BAF 6EEF DBD6 6336 47EC ACC1 6416 6A09 1572 E0EC

To claim this, I am signing this object:

@ytkhs
ytkhs / gist:1ec29784f2ad4203bdb4e43c1ce13a74
Last active January 28, 2020 10:30
Google Driveのファイルを再帰的に探す
var resultFiles = [];
// 再帰的にファイルを探す
function getAllFiles(folder, path) {
// まずこの階層のファイル
var files = folder.getFiles();
while(files.hasNext()){
var file = files.next();
@ytkhs
ytkhs / file2.php
Last active December 13, 2018 02:37
配列の最初or最後のキーを取り出す(PHP7.3) ref: https://qiita.com/ytkhs/items/6b97d0f46d3a04ef5183
$arr = ['a' => 'Alice', 'b' => 'Bob'];
# 今まで(ポインタが移動しちゃう)
end($arr);
# => "Bob"
# 存在チェックが必要なのでこれはこれで長い。いい方法あるかな?
$lastkey = array_key_last($arr);
array_key_exists($lastkey, $arr) ? $arr[$lastkey] : null
# => "Bob"
@ytkhs
ytkhs / file0.go
Created March 6, 2017 12:29
Golangでプレミアムフライデーかどうか判定する ref: http://qiita.com/qube81/items/1e93c837c0a7e3d99a10
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(IsPremiumFriday("2017-02-24")) // true
fmt.Println(IsPremiumFriday("2017-02-25")) // false
@ytkhs
ytkhs / file0.php
Created March 6, 2017 11:29
phpでプレミアムフライデーかどうか判定する ref: http://qiita.com/qube81/items/9d17ddc4aa8ffb276bc9
<?php
function is_premium_friday(Datetime $date) {
return $date->diff(new DateTime(sprintf('last Fri of %s', $date->format('Y-m'))))->format('%d') == 0;
}
var_dump(is_premium_friday(new Datetime('2017-02-23'))); // false
var_dump(is_premium_friday(new Datetime('2017-02-24'))); // true
var_dump(is_premium_friday(new Datetime('2017-02-25'))); // false
var_dump(is_premium_friday(new Datetime('2017-03-31'))); // true
@ytkhs
ytkhs / mod_remoteip.conf
Created January 31, 2017 01:17
ipによるアクセス制限 w/ apache24
RemoteIPHeader X-Forwarded-For
#RemoteIPTrustedProxy 172.16.0.0/16
RemoteIPInternalProxy 172.16.0.0/16
<Directory "/var/www/html">
AllowOverride All
Options ExecCGI FollowSymlinks MultiViews
<RequireAny>
Require ip xx.xx.xx.xx
@ytkhs
ytkhs / mysql_data_size.sql
Created January 23, 2017 09:02
mysqlのテーブルごとのデータサイズを調べるときに使う
select
table_name,
engine,
table_rows,
avg_row_length,
floor((data_length+index_length)/1024/1024) AS MB
from
information_schema.tables
where
table_schema = 'DATABASE_NAME'
@ytkhs
ytkhs / mysql_read_only.sql
Created September 20, 2016 02:20
MySQLを読み取り専用にする(バックアップ時など)
-- 読み取り専用にする
FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
-- バックアップとかDBサーバの移設作業とか --
-- 元に戻す
SET GLOBAL read_only = OFF;
UNLOCK TABLES;
@ytkhs
ytkhs / file0.txt
Created July 3, 2016 03:00
Go製のフレームワークechoをHerokuで動かす ref: http://qiita.com/qube81/items/b89ec5e663be934dccf5
go get github.com/labstack/echo/...
@ytkhs
ytkhs / general_log.sql
Created February 26, 2016 03:35
MySQLのgeneral_logをON/OFFする
// root user
show variables like '%general_log%';
set global general_log='ON'
set global general_log='OFF'