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 / php_closure_sample.php
Created January 16, 2011 14:29
Closure Sample PHP >= 5.3
<?php
# Closure Sample PHP >= 5.3
$var = 'FRESH_';
$func = function($str) use ($var)
{
return $var.strtoupper($str);
};
@ytkhs
ytkhs / apk_install.sh
Created March 19, 2011 04:10
uninstall and install command for android adb
$ adb devices #check connected device
$ adb uninstall <package name>
$ adb install <apk filename>
@ytkhs
ytkhs / SampleTask.java
Created March 21, 2011 13:01
a sample AsyncTask for Android
SampleTask task = new SampleTask(this);
task.execute(stringValues);
//check task status
if(task.getStatus() != AsyncTask.Status.FINISHED) {
if(!task.isCancelled) {
//call SampleTask.onCancelled()
task.cancel();
}
}
@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(
@ytkhs
ytkhs / imkayac_open_twitter.php
Created June 4, 2011 17:18
push notification to iPhone via im.kayac.com with password, and open Twitter.
<?php
define('USERNAME', 'xxxxxxxx');
define('PASSWORD', 'xxxxxxxxxxxxxx');
define('END_POINT', 'http://im.kayac.com/api/post/'.USERNAME);
$postMessage = urlencode('東京スカイツリーにきたよ!');
$data = array(
'message' => 'Push from im.kayac.com',
@ytkhs
ytkhs / convert_utf8_lf.sh
Created June 16, 2011 09:56
One-Liner for converting text files under current directory to UTF-8 encoding and LF line break.
$ find . -type f | xargs -n 10 nkf -w -Lu --overwrite
@ytkhs
ytkhs / shell_exec.java
Created June 29, 2011 02:42
a java tips like "shell_exec()" on PHP.
try {
Process ps = Runtime.getRuntime().exec("ps");
BufferedReader reader = new BufferedReader(new InputStreamReader(ps.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
@ytkhs
ytkhs / remove_dsstore_from_git.sh
Created July 13, 2011 15:50
remove all .DS_Store files from git
$ find . -depth -name '.DS_Store' -exec git rm --cached '{}' \; -print
@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