Skip to content

Instantly share code, notes, and snippets.

View tanakahisateru's full-sized avatar

Hisateru Tanaka tanakahisateru

View GitHub Profile
@tanakahisateru
tanakahisateru / gist:1012247
Created June 7, 2011 13:26
こんなバリデーションライブラリがあったらなぁ
こんなバリデーションライブラリがあったらなぁ
<?php
Validator::registerMessages(array(
'not-empty'=>'入力してください',
'max-length'=>'{1}文字以上',
'min-length'=>'{1}文字以内',
));
$v = new Validator($post);
$v->check('title')
@tanakahisateru
tanakahisateru / gist:1016531
Created June 9, 2011 11:04
PHPTAL's attribute extension test
<?php
/*
* This is PHPTAL's attribute extension test.
* pal:content-nl2br : replaces newline to <br/>
* pal:replace-nl2br : replaces newline to <br/>
* pal:attr : shorter version of tal:attributes
* and adds context variable includes original attributes
* named as "attr" inside the tag.
*/
require_once 'PHPTAL.php';
@tanakahisateru
tanakahisateru / relations.php
Created August 4, 2011 06:24
Model assosiation support for CodeIgniter
<?php if ( ! defined('BASEPATH')) exit('Direct script access not allowed');
/**
* This library bakes related object(s) into object field (or array key) using CI's ActiveRecord.
*
* @author Hisateru Tanaka
*
* Annual issue:
* Explicit sql programing is too redundant and too difficult to describe about relations.
*
@tanakahisateru
tanakahisateru / php540a3demo.php
Created August 5, 2011 12:56
PHP 5.4.0 Alpha3 でこういうコードが書けるようになる
<?php
// かならずコンテキスト付きで初期化する trait
trait InitWithContext {
function __construct($context)
{
$this->context = $context;
}
}
// オブジェクトのフィールドを直接呼べるようになる trait
@tanakahisateru
tanakahisateru / express-test.coffee
Created September 9, 2011 12:08
Express framework example by CoffeeScript
app = (require 'express').createServer()
#app.get /.*/, (req,res) -> res.render 'maintenance' #メンテナンスモード
#app.all /.*/, (req,rep) -> res.send 503 #メンテナンスモード
app.get '/', (req,resp)->
resp.send 'Hello World'
app.get '/goodbye', (req,resp)->
resp.send 'Goodbye World'
@tanakahisateru
tanakahisateru / gist:1228315
Created September 20, 2011 04:16
Pinoco_Varsを用いて徳丸本の「様々な列でのソート」のサンプルを改善してみた。
<?php
$sortables = Pinoco::newVars(array(
'sort_id' =>'id',
'sort_author' =>'author',
'sort_title' =>'title',
'sort_price' =>'price',
));
$sql .= ' ORDER BY ' . $sortables->get($_GET['sort'], 'id');
@tanakahisateru
tanakahisateru / gist:1228317
Created September 20, 2011 04:18
Pinoco_Varsを用いて徳丸本の「様々な列でのソート」のサンプルを改善してみた。2
<?php
$sql .= ' ORDER BY ' . Pinoco::newVars(array(
'sort_id' =>'id',
'sort_author' =>'author',
'sort_title' =>'title',
'sort_price' =>'price',
))->get($_GET['sort'], 'id');
@tanakahisateru
tanakahisateru / gist:1228346
Created September 20, 2011 04:38
Pinoco_Varsを用いて徳丸本の「様々な列でのソート」のサンプルを改善してみた。3
<?php
$sql = Pinoco::newList();
$sql->push('SELECT ...'); // ここでメインのクエリを書く
$sql->push(Pinoco::newVars(array(
'sort_id' =>'ORDER BY id',
'sort_author' =>'ORDER BY author',
'sort_title' =>'ORDER BY title',
'sort_price' =>'ORDER BY price',
@tanakahisateru
tanakahisateru / export-diff.py
Created October 3, 2011 05:55
Exports added or modified files by SCM summary
#!/usr/bin/env python
#!coding: utf-8
import sys, os, re, shutil
from optparse import OptionParser
parser = OptionParser(usage=
'''%prog [options] <target-dir>
Example:
@tanakahisateru
tanakahisateru / builtin-server.php
Created October 5, 2011 19:01
CakePHP2 by PHP5.4 builtin server
<?php
/**
* Place this file in CakePHP's root dir and do:
* $ php -S localhost:8080 builtin-server.php
* with PHP5.4
*/
list($path, $param) = preg_split('/\?/', $_SERVER['REQUEST_URI'], 2);
if($path != '/' && (file_exists('app/webroot' . $path)))
{
header(sprintf('Location: http://%s/app/webroot%s',