Skip to content

Instantly share code, notes, and snippets.

View ytkhs's full-sized avatar
On vacation

ytkhs ytkhs

On vacation
View GitHub Profile
@ytkhs
ytkhs / bitly.lib.php
Created January 15, 2011 15:07
Examples to get shorten or decode target url using bit.ly.
<?php
define('LOGIN', 'xxxxx');
define('API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('END_POINT', 'http://api.bit.ly/v3');
function getShortUrl($longUrl)
{
$query = http_build_query(
array(
'login' => LOGIN,
@ytkhs
ytkhs / file_post_contents.php
Last active October 14, 2022 09:19
a sample POST method with file_get_contents()
<?php
if (!function_exists('http_post_contents')) {
function http_post_contents($url, $params) {
$content = http_build_query($params, '', '&');
$header = array(
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($content)
);
$options = array(

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 / send_intent.sh
Created August 16, 2011 09:33
Send Intent to emulator or real device from adb shell
$ adb shell
#sample
am start -a android.intent.action.CALL -d tel://000-0000
am start -a android.intent.action.SEND -d "some message" -t text/plain
am start -a android.intent.action.VIEW -d geo:0,0?q=Tokyo
am start -n com.android.browser/.BrowserActivity
@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 / 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 / connect_internet.sh
Created July 22, 2011 10:08
connect android emulator to the internet
# start emulator shell
$ adb shell
# on emelator
setprop net.dns1 8.8.8.8
setprop net.dns2 8.8.4.4
@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