Skip to content

Instantly share code, notes, and snippets.

View suin's full-sized avatar
😃

suin

😃
  • Craftsman Software, Inc.
  • Japan Tokyo
View GitHub Profile
@suin
suin / accept-language.php
Created December 26, 2012 07:21
AcceptLanguage negotiation algorithm
<?php
/**
* Return accept languages
* @return array
*
* HTTP content negotiation (section 12) uses short "floating point" numbers to indicate the
* relative importance ("weight") of various negotiable parameters. A weight is normalized to
* a real number in the range 0 through 1, where 0 is the minimum and 1 the maximum value.
* If a parameter has a quality value of 0, then content with this parameter is `not acceptable'
* for the client. HTTP/1.1 applications MUST NOT generate more than three digits after the
【K&R】
function(...)
{
}
if (...) {
.
├── src
│   └── MyCompany
│   └── AppBundle
│   ├── Command
│   └── Controller
└── vendor
└── MyCompany
├── DataSourceModule1
│   ├── ExternalService
<?php
class Foo
{
private $foo = 'bar';
public function generate()
{
return function() {
return $this->foo;
@suin
suin / test.php
Created December 2, 2012 07:43
parent::parent::parentコンストラクタパターン
<?php
class Foo
{
public function __construct()
{
$this->value = __CLASS__;
}
}
@suin
suin / Assertion.php
Created November 29, 2012 04:29
Assertionフレームワークのプロトタイプ(案)
<?php
class Assertion
{
private $assertion;
private $valiator;
public function __construct($assertion, callable $validator)
{
fields:
name:
type: string
label: "契約者名"
uname:
type: string
lablel: "ユーザ名"
email:
type: string
label: "メールアドレス"
@suin
suin / datetme.php
Created November 27, 2012 05:47
PHPのDateTimeクラスが作り方によって色々違う
<?php
$date1 = new DateTime('@999994149');
$date2 = (new DateTime)->setTimestamp(999994149);
var_dump($date1->getTimestamp());
var_dump($date2->getTimestamp());
$diff = $date1->diff($date2);
@suin
suin / Entity.php
Created November 16, 2012 06:15
PHP5.3のクラスエイリアシングを使った型下位互換技術
<?php
namespace XCore\Entity;
class User
{
// 元XoopsUserクラス
}
class Module
@suin
suin / Test.java
Created November 11, 2012 12:59
PHPは引数型のダウンキャストができないなと思ったら。
class Test {
public static void main(String[] args) {
UserRepository userRepository = new UserRepository();
userRepository.persist(new Object());
userRepository.persist(new User());
}
}
class Repository
{