Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Phanda;
use Phanda;
class Util {
public static function encrypt($source, $key, $iv, $toBase64Encode=true)
{
$mcrypt_resource = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
$mcrypt_key_size = mcrypt_enc_get_key_size($mcrypt_resource);
@k-holy
k-holy / .htaccess
Created July 14, 2011 09:44
Phanda_PathTranslator
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !__gateway\.php$
RewriteRule .* __gateway.php [L]
@k-holy
k-holy / open_id.php
Created July 28, 2011 09:44
PHP OpenIDの利用サンプル
<?php
define('Auth_Yadis_CURL_OVERRIDE', '1'); // Curlは使わない
define('Auth_OpenID_RAND_SOURCE' ,
(!file_exists('/dev/urandom') || !is_readable('/dev/urandom'))
? '/dev/urandom' : null);
if (!isset($_SESSION)) {
session_start();
}
class Util {
@k-holy
k-holy / range.php
Created August 2, 2011 06:07
数値選択用の配列を生成するサンプル
<?php
namespace Holy;
// キーにzero-paddingした半角数字、テキストに全角数字を持つ日付選択用の配列を生成する
class Util {
public static function H($data) {
if (isset($data) && strlen($data) >= 1) {
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
}
return $data;
@k-holy
k-holy / memcached.php
Created August 3, 2011 09:47
php-memcacheのてすと
<?php
$array = range(0, 10000);
$options = array_combine(
array_map(function($i) {
return sha1($i);
}, $array),
array_map(function($i) {
return crc32($i);
}, $array));
@k-holy
k-holy / LoaderTest.php
Created August 5, 2011 06:42
PSR-0対応クラスローダ試案
<?php
namespace Holy\Tests;
use Holy\Loader;
/**
* LoaderTest
*
* @author [email protected]
*/
@k-holy
k-holy / gist:1135990
Created August 10, 2011 03:04
ディレクトリ内のファイル一覧(PHP5.2)
<?php
error_reporting(E_ALL|E_STRICT);
if (defined('E_DEPRECATED')) {
error_reporting(error_reporting() & ~E_DEPRECATED);
}
mb_detect_order('ASCII,EUC-JP,SJIS,JIS,UTF-8');
class U
{
public static function NL($data) {
@k-holy
k-holy / FizzBuzz.php
Created August 17, 2011 07:38
FizzBuzzとProject Euler Problem 1
<pre>
<?php
// array_map()で解くFizzBuzz
echo implode("\n", array_map(function($var) {
return ($var % 3 * $var % 5) ? $var : ($var % 3 ? '' : 'Fizz') . ($var % 5 ? '' : 'Buzz');
}, range(1, 100)));
?>
</pre>
@k-holy
k-holy / gist:1156160
Created August 19, 2011 06:06
PHP5.3 コールバックでクロージャを使うサンプル with はてなハイクAPI
<?php
namespace Holy\Example;
class Util {
public static function H($data, $default=null) {
$var = $default;
if (isset($data) && is_scalar($data) && strlen($data) >= 1) {
$var = htmlspecialchars($data, \ENT_QUOTES, 'UTF-8');
}
return $var;
@k-holy
k-holy / gist:1156281
Created August 19, 2011 07:51
PEAR形式のみ対応のautoload実装
<?php
set_include_path(realpath(__DIR__ . '/../lib') . PATH_SEPARATOR .
get_include_path());
// spl_autoload_functions()の挙動:登録前
var_dump(spl_autoload_functions()); // bool(false)
// include_path 前提のPEAR形式クラスの場合、最低これだけでも動く
function autoload($className) {
return @include str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';