Skip to content

Instantly share code, notes, and snippets.

<?php
trait EnumTrait
{
/** @var static[] */
private static $instance;
/** @var mixed value of constant */
private $value;
/**
@do-aki
do-aki / EnumTrait_Sample.php
Last active February 28, 2018 15:03
EnumTrait usage
<?php
final class GameDifficulty
{
const HARD = 'hard';
const NORMAL = 'normal';
const EASY = 'easy';
use EnumTrait {
constant as public HARD;
constant as public NORMAL;
@do-aki
do-aki / ParameterTypeWidening.php
Created February 13, 2018 10:47
Parameter Type Widening に関して
<?php
class ParentClassA { function f(stdClass $a) {} }
class ChildClassA extends ParentClassA { function f($a) {} }
/*
7.2 の Parameter Type Widening (https://wiki.php.net/rfc/parameter-no-type-variance) によって、
上記 ParentClassA/ChildClassA は ok になった。
(new ParentClassA())->f(new stdClass()) に対して
# スレッドA,B 生成前に実行
> create table t1( id int not null auto_increment, hoge varchar(255) not null, primary key(id) )engine=innodb;
> insert into t1 values (1, "hoge");
スレッドA
> drop table t1;
> create table t1( id int not null auto_increment, primary key(id) )engine=innodb;
> insert into t1 values (1);
<?php
require 'vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
$html = <<<'HTML'
<!doctype html>
<form>
<input type="image" name="date[2016-03-16]" />
</form>
@do-aki
do-aki / gist:7771047
Created December 3, 2013 15:23
AngularJS の練習。 タグ的なものを入力する感じのモノ。
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.3/angular-animate.min.js"></script>
<script>
function ctrl($scope) {
$scope.words = [];
$scope.input = function() {
@do-aki
do-aki / generator.php
Created September 3, 2013 11:38
trait と generator の練習。
<?php
trait GeneratorAction {
private $_g;
public function initializeGenerator($g) {
$this->_g = $g;
}
public function getGenerator() {
@do-aki
do-aki / mylogin_dumper.pl
Created April 17, 2013 08:54
MySQL Casual Talks Vol.4 LT 「セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor」 http://www.slideshare.net/do_aki/mysql-config-editor を参照。 Crypt::ECB と Crypt::OpenSSL::AES が必要です。
######################################
# usage
# mylogin_dumper.pl ~/.mylogin.conf
######################################
use strict;
use warnings;
use Crypt::ECB;
#use Crypt::OpenSSL::AES;
my $my_login_file = shift;
@do-aki
do-aki / html_purifier.php
Last active December 16, 2015 02:09
HTML Purifier を使って html を消毒する ref: http://qiita.com/items/b7767b63d6c3d65cd3da
<?php
require_once('$PATH_TO_LIBRARY/HTMLPurifier.includes.php');
use HTMLPurifier;
use HTMLPurifier_Config;
function sanitize($tainted_html) {
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', $PATH_TO_TEMPORARY_DIR);
$purifier = new HTMLPurifier($config);
return $purifier->purify($tainted_html);
@do-aki
do-aki / download.html
Created February 25, 2013 08:07
Excel 向け日本語 CSV ファイル
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>日本語csv sample</title>
</head>
<body>
<a id="js-download" href="dummy">download</a>
<script>
// (1) BOM の用意