Skip to content

Instantly share code, notes, and snippets.

View suin's full-sized avatar
😃

suin

😃
View GitHub Profile
@suin
suin / file0.php
Created December 16, 2011 01:03
Safe Modeなどの諸事情によりmkdir()できないときはFTPで ref: http://qiita.com/items/1384
<?php
mkdir('ftp://user:pass@localhost/path/to/dir');
@suin
suin / file0.php
Created December 16, 2011 04:22
glob()の結果からファイルだけを抽出する ref: http://qiita.com/items/1388
<?php
$files = glob('/path/to/dir');
$files = array_filter($files, 'is_file');
@suin
suin / file0.php
Last active February 19, 2016 11:07
改行テキストを配列に変換する ref: http://qiita.com/suin/items/835ac0f58e6d3bbb6280
$text = 'a
b
c
d
f
';
@suin
suin / file0.php
Created December 28, 2011 13:09
PHPUnitで定数のテストをするときは@runInSeparateProcessで別プロセスに ref: http://qiita.com/items/1476
<?php
class ConstantTest extends PHPUnit_Framework_TestCase
{
/**
* @runInSeparateProcess
*/
public function testConstant1()
{
define('THIS_IS_CONSTANT', 'foo');
$this->assertSame('foo', THIS_IS_CONSTANT);
@suin
suin / file0.txt
Created January 22, 2012 05:06
複数のCoffeeScriptファイルからひとつのJavaScriptファイルにコンパイルする ref: http://qiita.com/items/1831
$ coffee -cj path/to/compiled/file.js file1 file2 file3 file4
@suin
suin / callme.php
Created January 25, 2012 13:10
Node.jsからPHPのプロセスを呼び出す - JSONでやりとり編 ref: http://qiita.com/items/1879
<?php
$stdin = file_get_contents('php://stdin');
$data = json_decode($stdin, true);
// var_dump($data);
if ( is_array($data) === false )
{
@suin
suin / file0.txt
Created February 3, 2012 13:41
kmyaccとPHPでオレオレプログラミング言語を作る - 環境構築編 ref: http://qiita.com/items/2011
$ git clone https://github.com/moriyoshi/kmyacc-forked.git
Cloning into kmyacc-forked...
remote: Counting objects: 76, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 76 (delta 14), reused 76 (delta 14)
Unpacking objects: 100% (76/76), done.
@suin
suin / file0.php
Created February 3, 2012 13:41
閏年かどうかを判定する ref: http://qiita.com/items/2012
<?php
// まじめに計算する方法
function isLeapYear($year)
{
return ( ( $year % 4 === 0 and $year % 100 !== 0 ) or $year % 400 === 0 );
}
$years = range(2000, 2012);
@suin
suin / file0.php
Created February 3, 2012 14:34
あるファイルに使われている関数を数えて返す ref: http://qiita.com/items/2013
<?php
$filename = '/path/to/file.php';
$contents = file_get_contents($filename);
$tokens = token_get_all($contents);
$functions = array();
while ( count($tokens) > 0 )
{
$token = array_shift($tokens);
@suin
suin / file0.php
Created February 11, 2012 12:35
モデルのインターフェースを定義してみる。 ref: http://qiita.com/items/2389
<?php
interface ModelInterface
{
/**
* Sets the value of a property.
* @param string $name
* @param mixed $value
* @return void
*/