Skip to content

Instantly share code, notes, and snippets.

View tanakahisateru's full-sized avatar

Hisateru Tanaka tanakahisateru

View GitHub Profile
@tanakahisateru
tanakahisateru / array-spped-test.php
Last active May 25, 2016 13:55
PHP array operation speed test
<?php
require __DIR__ . '/vendor/autoload.php';
$size = 1000000;
$repeat = max([1, intval(5000000 / $size)]);
$targetArray = range(1, $size);
function plus1($n) {
return $n + 1;
@tanakahisateru
tanakahisateru / AwsEsTestController.php
Created May 24, 2016 13:02
AWSのElasticsearchのIAM認証実験
<?php
namespace hoge\fuga;
use Aws\Credentials\Credentials;
use Aws\Signature\SignatureV4;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use yii\console\Controller;
class AwsEsTestController extends Controller
@tanakahisateru
tanakahisateru / Article.php
Created December 15, 2015 13:34
Eloquent bidirectional reference test
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Article
*
* @property integer $id
@tanakahisateru
tanakahisateru / ResponsiveLinkPager.php
Last active October 7, 2017 08:29
Bootstrap responsive pagination widget for Yii
<?php
namespace app\utils\widgets;
use yii\helpers\Html;
use yii\widgets\LinkPager;
/**
* ResponsiveLinkPager can reduce or style each buttons for responsive design.
*
* Define CSS classes as if maxButtonCount would be so. For example below applies hidden-xs class
@tanakahisateru
tanakahisateru / confirm-before-submit.js
Created June 17, 2015 06:23
YiiのActiveFormサブミットを確認ダイアログ付きにするjQueryプラグイン ref: http://qiita.com/tanakahisateru/items/277d684bb75119dfc68a
(function($) {
$.fn.confirmBeforeSubmit = function(options) {
options = $.extend({
message: "本当に実行しますか。"
}, options);
this.each(function() {
var $button = $(this);
var $form = $button.closest('form');
@tanakahisateru
tanakahisateru / EmojiTrait.php
Created March 6, 2015 18:40
My Emoji parser for cebe/markdown
<?php
/**
* Sample code
*/
trait EmojiTrait
{
/** @var array */
protected $emojiMap = null;
@tanakahisateru
tanakahisateru / Job.php
Created December 26, 2014 09:21
Yii2のARで求人情報には公開求人と非公開人材紹介があることを表す方法
<?php
namespace app\models;
use yii\db\ActiveRecord;
abstract class Job extends ActiveRecord
{
public static function tableName()
@tanakahisateru
tanakahisateru / 0-yii2-test-wo-acceptance
Last active August 29, 2015 14:11
Yii2のAcceptanceなしテストこんな構成にしてみた
.
├── codeception
│   ├── _output
│   ├── _support
│   │   └── FixtureLoader.php --- フィクスチャ全部ロードするやつ
│   ├── bin
│   │   ├── _bootstrap.php
│   │   ├── yii
│   │   └── yii.bat
│   ├── config
@tanakahisateru
tanakahisateru / gist:15488cfd13a4fc9bf9ee
Created December 10, 2014 08:56
日本のクリスマスは世界のクリスマスイブ
CREATE TABLE test (
day1 DATETIME,
day2 TIMESTAMP
);
SET SESSION time_zone = 'UTC';
INSERT INTO test VALUES ('2014-12-25 00:00:00', '2014-12-25 00:00:00');
SET SESSION time_zone = 'Asia/Tokyo';
INSERT INTO test VALUES ('2014-12-25 00:00:00', '2014-12-25 00:00:00');
SET SESSION time_zone = 'UTC';
SELECT * FROM test;
@tanakahisateru
tanakahisateru / gist:f0549e7ec3ae7c870912
Created December 9, 2014 11:59
Remove UTF-8 bad bytes
<?php
$text = "あいうえお";
$text1 = substr($text, 1);
$text2 = substr($text, 2);
echo mb_strimwidth($text1, 0, 10) . "\n";
echo mb_strimwidth($text2, 0, 10) . "\n";
function valid($text) {
return (ord($text[0]) & 0xa0) != 0x80;