This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- sort.js 2011-06-29 23:34:27.000000000 +0900 | |
+++ sort2.js 2011-06-29 23:34:37.000000000 +0900 | |
@@ -1,10 +1,10 @@ | |
var sort = function(list, comparer) { | |
- if (!comparer) comparer = function(x, y) { return y - x; }; | |
+ if (!comparer) comparer = function(x, y) { return x - y; }; | |
return (function self(list) { | |
if (list.length < 2) return list; | |
var left = self(list.splice(0, list.length >>> 1)), right = self(list.splice(0)); | |
while (left.length && right.length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Zend/Rest/Client.php'; | |
//アプリケーションIDは各自で取得したものを使ってください。 | |
$appid = 'プレミアム検索対応のアプリケーションIDをここに記入'; | |
//APIのベースURLを指定する | |
$client = new Zend_Rest_Client('http://search.yahooapis.jp/PremiumWebSearchService/V1/webSearch'); | |
//パラメータを設定 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getToken() { | |
$s = file_get_contents('/dev/urandom', false, NULL, 0, 24); | |
return base64_encode($s); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//常にZend_Db_Tableを作成するところから開始します。 | |
$posts = AR('posts'); | |
//テーブルクラスにデータを検索してもらったり | |
$latestPost = $posts->find(1)->current(); | |
//テーブルクラスに新しいRowデータの雛形を作ってもらったり | |
$newpost = $posts->createRow(); | |
$newpost->title = '新しいポスト'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* treeコマンドのPHP5.3による実装例。 | |
*/ | |
namespace Tree; | |
//iterator類は名前が長いので短縮 | |
use RecursiveDirectoryIterator as RDI, | |
RecursiveFilterIterator as RFI, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//以下、コードの先頭に書いておけば以降require_onceを書かなくてよくなる | |
function simpleClassLoader($classname) { | |
return @include_once str_replace( | |
array('\\', '_'), | |
DIRECTORY_SEPARATOR, | |
$classname | |
) . '.php'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<entry xmlns="http://www.w3.org/2005/Atom"> | |
<id>tag:example.com,2012:1234</id> | |
<title>sample entry</title> | |
<updated>2012-01-01T00:00:00+09:00</updated> | |
<author><name>author name</name></author> | |
<content>コンテンツの中身そのもの</content> | |
</entry> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a->hoge = 'fuga'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (array_values($arr) === $arr) { | |
echo '$arrは配列'; | |
} else { | |
echo '$arrは連想配列'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = new PDO('...'); | |
$stmt = $pdo->query('SELECT txt FROM Hoge'); | |
var_dump($stmt->fetchAll(PDO::FETCH_NUM)); | |
//[ [txt1], [txt2], [txt3], ... ] |
OlderNewer