Skip to content

Instantly share code, notes, and snippets.

Avatar

Hisateru Tanaka tanakahisateru

View GitHub Profile
@tanakahisateru
tanakahisateru / clipboard.ts
Created Jul 12, 2022
クロスプラットフォームな ClipboardEvent 生成
View clipboard.ts
/**
* コードによるクリップボードイベントの生成はブラウザ実装によってまったく違う。
*
* Gekko (Firefox) はコンストラクタの clipboardData 初期値を無視するが、
* 生成されたイベントオブジェクトの clipboardData には空の DataTransfer
* 入っている。データ入りの DataTransfer を事前準備できない。
*
* WebKit (Chrome, Safari, Edge) は、clipboardData の初期値をコンストラクタに
* 与えないと clipboardData = null になっている異常なオブジェクトを作ってしまう。
* こちらはデータ入りの DataTransfer を最初から与えても OK。
@tanakahisateru
tanakahisateru / AssertHtmlTarit.php
Last active Jun 13, 2022
assertHtmlStringEqualsHtmlString
View AssertHtmlTarit.php
<?php
/**
* @method assertEquals(mixed $expected, mixed $actual, string $message)
*/
trait AssetHtmlTrait
{
public function assertHtmlStringEqualsHtmlString(string $expectedHtml, string $actualHtml, string $message = ''): void
{
$expected = (new \PHPUnit\Util\Xml\Loader)->load(
$this->cleanHtml($expectedHtml),
View DoctrineHelper.php
<?php
namespace Symfony\Bundle\MakerBundle\Doctrine;
final class DoctrineHelper
{
/**
* @return MappingDriver|LegacyMappingDriver|null
*
* @throws \Exception
@tanakahisateru
tanakahisateru / genuuid4.php
Created Nov 21, 2019
NEVER USE this UUIDv4 generator
View genuuid4.php
#!/usr/bin/env php
<?php
/**
* Try: bin/genuuid4.php 65536 | sort | uniq -d
*/
class UuidV4
{
const VERSION = 4;
const VARIANT = 2;
@tanakahisateru
tanakahisateru / nazo.php
Last active Apr 22, 2019
The refactoring
View nazo.php
<?php
foreach ($cells $ $cell) {
//
switch ($tdcnt++ % 3) {
case 0:
$cls = 'c_td1';
break;
case 1:
$cls = 'c_td2';
@tanakahisateru
tanakahisateru / main.py
Created Feb 28, 2019
牛乳パック1つと卵があれば6つ買うをやるシステム
View main.py
from shop import Item, Shop
shop = Shop('イオン ドームシティ店')
cart = shop.cart()
cart.add(Item.MILK)
# TODO implement more
receipt = shop.paycheck(cart)
@tanakahisateru
tanakahisateru / wave-or-tilde.php
Last active Jun 19, 2018
入力した波ダッシュが全角チルダに化けるまたはその逆について
View wave-or-tilde.php
<?php
$wave = "\u{301C}";
$tilde = "\u{FF5E}";
// EUC-JP has no different character for wavy dash and full width tilde
$eucWave = mb_convert_encoding($wave, 'euc-jp', 'utf-8');
$eucTilde = mb_convert_encoding($tilde, 'euc-jp', 'utf-8');
assert($eucWave == $eucTilde);
// euc-jp to utf-8: always wavey dash
@tanakahisateru
tanakahisateru / emoji-gh2cp.rb
Last active Jan 29, 2018
Generates emoji data mapped from GitHub emoji name to fully-qualified codepoints
View emoji-gh2cp.rb
#!/usr/bin/env ruby
require 'set'
require 'net/http'
require 'json'
gh_emoji_json = Net::HTTP.get URI('https://api.github.com/emojis')
gh_emoji = JSON.load gh_emoji_json
exit 1 unless gh_emoji.kind_of? Hash
@tanakahisateru
tanakahisateru / AncestorPrivateAccessTrait.php
Created Dec 13, 2017
継承で子が親の private にアクセスするできるようにするやつ
View AncestorPrivateAccessTrait.php
<?php
trait AncestorPrivateAccessTrait
{
protected function invokePrivateMethod($name, $arguments = [])
{
$reflectionClass = new \ReflectionClass(get_class($this));
while (!$reflectionClass->hasMethod($name)) {
$reflectionClass = $reflectionClass->getParentClass();
if (!$reflectionClass) {
throw new \InvalidArgumentException('Property not found:' . $name);
View gist:61e64fe41a9e6aa48ee62c0330fd57f2

OREORE

    "require": {
        "aura/di": "^3.2",
        "aura/dispatcher": "^2.0",
        "aura/includer": "^2.0",
        "aura/router": "^3.1",
        "http-interop/http-factory": "^0.3.0",
        "http-interop/http-factory-diactoros": "^0.3.0",