Skip to content

Instantly share code, notes, and snippets.

View cognitom's full-sized avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@cognitom
cognitom / fb2ical.php
Created May 29, 2011 17:36
Export ical format for Facebook page's events
<?php
// https://github.com/facebook/php-sdk/
require_once 'path/to/facebook.php';
// http://www.kigkonsult.se/iCalcreator/
require_once 'path/to/iCalcreator.class.php';
$config = array(
'appId' => 'xxxx',//change to your fb app id
'secret' => 'yyyy',//change to your fb app secret
'pageId' => 'shimokitazawa.osscafe',//change to target fb page id
@cognitom
cognitom / gist:1011927
Created June 7, 2011 09:01
jQueryで、選択済みチェックボックスの値のリストを取得するワンライナー
//<input type="checkbox" name="sample[]" value="1" checked="checked" />
//<input type="checkbox" name="sample[]" value="2" />
//<input type="checkbox" name="sample[]" value="3" checked="checked" />
var str = $('input:checkbox[name="sample[]"]:checked').map(function(i){ return this.value }).get().join(', ');
alert(str);//1, 3
@cognitom
cognitom / gist:1011960
Created June 7, 2011 09:39
電話番号の正規化 (日本版)
String.prototype.cnvPhone = function(defaultPrefix){
var str0 = this, str1, str;
str1 = str0.replace(/[^\d]/g, '');
if (defaultPrefix && /^[^0]/.test(str1)) str1 = defaultPrefix+str1;//0以外で始まる場合、デフォルトの局番を追加
str = str1;
str = str.replace(/^0(9969|9913|9912|9802|9496|8636|8514|8512|8477|8396|8388|8387|7468|5979|5769|4998|4996|4994|4992|1658|1656|1655|1654|1648|1635|1634|1632|1587|1586|1564|1558|1547|1466|1457|1456|1398|1397|1392|1377|1374|1372|1267)(\d)(\d{4})$/, "0$1-$2-$3");//固定電話市外4桁
str = str.replace(/^0(997|996|995|994|993|987|986|985|984|983|982|980|979|978|977|974|973|972|969|968|967|966|965|964|959|957|956|955|954|952|950|949|948|947|946|944|943|942|940|930|920|898|897|896|895|894|893|892|889|887|885|884|883|880|879|877|875|869|868|867|866|865|863|859|858|857|856|855|854|853|852|848|847|846|845|838|837|836|835|834|833|829|827|826|824|823|820|799|798|797|796|795|794|791|790|779|778|776|774|773|772|771|770|768|767|766|765|763|761|749|748|747|746|745|744|743|742|740|739|738|737|736|735|725|721|599|59
@cognitom
cognitom / gist:1300717
Created October 20, 2011 08:52
誕生日から年齢を取得
SELECT
YEAR(NOW()) - YEAR(birthday) - IF(DATE_FORMAT(birthday, '%m%d') > DATE_FORMAT(NOW(), '%m%d'), 1, 0)
AS "age"
FROM a_table
@cognitom
cognitom / curl_get_contents.php
Created December 14, 2011 14:43
file_get_contentsで、リモートホストから取得出来ない場合の代替関数
<?php
/**
* curl_get_contents
*
* $url = 'http://somewhere.dom/'
* $response = curl_get_contents($url);
*/
function curl_get_contents($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@cognitom
cognitom / gist:1520905
Created December 26, 2011 10:26
Change the creation date recursively.
cd /path/to/somewhere
find . -exec touch -t 11012250000.00 {} \;
@cognitom
cognitom / gist:1557123
Created January 3, 2012 21:51
MediaWikiの管理者パスワードを再設定
UPDATE user SET user_password = MD5( CONCAT( user_id, '-', MD5( 'NEWPASS' ) ) ) WHERE user_id =1
#http://kb.siteground.com/article/How_to_reset_my_MediaWiki_admin_password.html
@cognitom
cognitom / function.byte2str.php
Created January 4, 2012 10:33
バイト数を分かり易い表記に
function byte2str($size){
$kb=1024;
$mb=1048576;
$gb=1073741824;
$tb=1099511627776;
if(!$size) return '0 B';
elseif($size<$kb) return $size.' B';
elseif($size<$mb) return round($size/$kb, 0).' KB';
elseif($size<$gb) return round($size/$mb, 2).' MB';
elseif($size<$tb) return round($size/$gb, 2).' GB';
@cognitom
cognitom / add_file_size_to_link.php
Created January 4, 2012 15:53
PDFファイルのリンクに容量を記載する
@cognitom
cognitom / gist:1625389
Created January 17, 2012 07:12
Create archive without .DS_Srore files
zip -r Archive.zip TargetDirectory -x "*.DS_Store"