Skip to content

Instantly share code, notes, and snippets.

@k-holy
k-holy / gist:1261023
Created October 4, 2011 06:36
ディレクトリ内のファイルを再帰的に削除するサンプル
<?php
namespace Holy\Example;
class Util
{
public function removeFiles($dir, $removeDir = false)
{
if (!file_exists($dir)) {
return;
}
if (false !== ($handle = opendir($dir))) {
@k-holy
k-holy / gist:1269136
Created October 7, 2011 00:41
array_map() と ArrayIterator で FizzBuzz
<?php
namespace Holy\Example;
require_once realpath(__DIR__ . '/lime.php');
class Util
{
public static function H($data, $callback=null)
{
if (isset($data) && strcmp($data, '') != 0) {
@k-holy
k-holy / SmartyServiceProvider.php
Created October 7, 2011 03:40
Silex SmartyServiceProvider
<?php
/**
* PHP versions 5
*
* @copyright 2011 k-holy <[email protected]>
* @author [email protected]
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
*/
namespace Holy\Silex\Provider;
@k-holy
k-holy / autoload.php
Created October 27, 2011 02:36
PEAR形式のみ対応のautoload実装(PHP5.3.2以降)
<?php
set_include_path('/path/to/pear' . PATH_SEPARATOR . get_include_path());
spl_autoload_register(function($className) {
if (false !== ($path = stream_resolve_include_path(
str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'))
) {
return include $path;
}
return false;
@k-holy
k-holy / RedBeanServiceProvider.php
Created October 27, 2011 23:43
Silex RedBeanServiceProvider
<?php
/**
* PHP versions 5
*
* @copyright 2011 k-holy <[email protected]>
* @author [email protected]
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
*/
namespace Holy\Silex\Provider;
@k-holy
k-holy / PhpTalServiceProvider.php
Created October 28, 2011 04:26
Silex PhpTalServiceProvider + RedBean
<?php
/**
* PHP versions 5
*
* @copyright 2011 k-holy <[email protected]>
* @author [email protected]
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
*/
namespace Holy\Silex\Provider;
<?php
namespace Holy\Example;
require_once realpath(__DIR__ . '/lime.php');
$conv = function($string) {
$i = 0;
return array_sum(array_map(function($char) use (&$i) {
$num = strpos('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $char) + 1;
$num *= pow(26, $i);
$i++;
@k-holy
k-holy / sunrise_sunset.php
Created November 11, 2011 04:40
日出没時刻をGoogle Geocoding APIで検索
<?php
namespace Holy\Example;
const MAP_API_URL = 'http://maps.google.com/maps/api/geocode/json?sensor=false&region=jp';
use Holy\Example\Util as U;
class Util {
public static function H($data, $default=null)
@k-holy
k-holy / image_types.php
Created December 6, 2011 08:50
IMAGETYPE定数と拡張子とmimeTypeの一覧を取得
<?php
$constants = get_defined_constants(true);
$supportedImageType = function($type) {
$_type = 0;
switch ($type) {
case IMAGETYPE_GIF:
$_type = IMG_GIF;
break;
@k-holy
k-holy / Util.php
Created December 9, 2011 05:49
エラーハンドラ・例外ハンドラのサンプル
<?php
namespace Holy\Example;
use Holy\Example\Util as U;
// ユーティリティクラス
class Util {
public static function H($var, $default = '') {
if (isset($var) && strlen($var) >= 1) {