Skip to content

Instantly share code, notes, and snippets.

View tanakahisateru's full-sized avatar

Hisateru Tanaka tanakahisateru

View GitHub Profile
<?php $layout = $view->layout('layout.php'); ?>
<?php $block = $layout->block('main'); ?>
<p>hello world</p>
<?php $block->end(); ?>
<?php $block = $layout->block('sub'); ?>
<p>bye bye world</p>
<?php $block->end(); ?>
<?php $layout->end(); ?>
$ cd Sites
$ composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic yii2-basic-app
$ cd yii2-basic-app
$ pstorm .

ストームで ⌥ + F12

@tanakahisateru
tanakahisateru / shell-command-escape.coffee
Created August 26, 2014 11:15
Shell command escape by CoffeeScript
# replacement of node-shell-quote
# quote ['echo', '"Oh"', '>_<;'] # ==> echo '"Oh"' \>_\<\;
quote = (xs)->
(for s in xs
if /["\s]/.test(s) and !/'/.test(s)
"'" + s.replace(/(['\\])/g, '\\$1') + "'"
else if /["'\s]/.test(s)
'"' + s.replace(/(["\\$`(){}!#&*|])/g, '\\$1') + '"'
else
String(s).replace(/([\\$`(){}!#&*|<>;])/g, '\\$1')
@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;
@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 / 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 / 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 / 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 / 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 / fizzbuzz.py
Created October 20, 2010 06:36
Fizz Buzz expression
map(lambda n:'fizzbuzz' if n%15==0 else 'fizz' if n%3==0 else 'buzz' if n%5==0 else str(n), range(1, 101))