Skip to content

Instantly share code, notes, and snippets.

View tanakahisateru's full-sized avatar

Hisateru Tanaka tanakahisateru

View GitHub Profile
@tanakahisateru
tanakahisateru / export-diff.py
Created October 3, 2011 05:55
Exports added or modified files by SCM summary
#!/usr/bin/env python
#!coding: utf-8
import sys, os, re, shutil
from optparse import OptionParser
parser = OptionParser(usage=
'''%prog [options] <target-dir>
Example:
@tanakahisateru
tanakahisateru / scp-git-diff.sh
Created November 17, 2011 09:56
Send changed files under Git via SCP (if SSH password auth)
#!/bin/sh
if [ $# -ne 1 ]; then
echo "$0 <git-commit>" 1>&2
exit 1
fi
git diff --name-status $1
read -p "Press any key to execute..."
@tanakahisateru
tanakahisateru / clipboard.ts
Created July 12, 2022 09:48
クロスプラットフォームな ClipboardEvent 生成
/**
* コードによるクリップボードイベントの生成はブラウザ実装によってまったく違う。
*
* Gekko 系 (Firefox) はコンストラクタの clipboardData 初期値を無視するが、
* 生成されたイベントオブジェクトの clipboardData には空の DataTransfer が
* 入っている。データ入りの DataTransfer を事前準備できない。
*
* WebKit 系 (Chrome, Safari, Edge) は、clipboardData の初期値をコンストラクタに
* 与えないと clipboardData = null になっている異常なオブジェクトを作ってしまう。
* こちらはデータ入りの DataTransfer を最初から与えても OK。
@tanakahisateru
tanakahisateru / AssertHtmlTarit.php
Last active June 13, 2022 14:30
assertHtmlStringEqualsHtmlString
<?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),
@tanakahisateru
tanakahisateru / perfect-mail.php
Created January 9, 2014 16:57
How Japanese control Yii2's SwiftMailer
<?php
// Charset
$domesticCharset = 'iso-2022-jp';
$universalCharset = 'utf-8';
// Encoders
$headerEncoderBase64 = new \Swift_Mime_HeaderEncoder_Base64HeaderEncoder();
$contentEncoder7bit = new \Swift_Mime_ContentEncoder_PlainContentEncoder('7bit');
$contentEncoderBase64 = new \Swift_Mime_ContentEncoder_Base64ContentEncoder();
@tanakahisateru
tanakahisateru / DoctrineHelper.php
Last active March 21, 2021 06:38
Symfony book problem
<?php
namespace Symfony\Bundle\MakerBundle\Doctrine;
final class DoctrineHelper
{
/**
* @return MappingDriver|LegacyMappingDriver|null
*
* @throws \Exception
@tanakahisateru
tanakahisateru / fizzbuzz.py
Created August 7, 2012 10:09
FizzBuzzをかんがえる
#Pythonは手続きだと逆にこういうダサさがあるのよね
def _tmp(e):
if e % 15 == 0: return "fizzbuzz"
elif e % 3 == 0: return "fizz"
elif e % 5 == 0: return "buzz"
else: return e
print map(_tmp, range(1, 100+1))
#分解
def fizzbuzz(n): "fizzbuzz" if isinstance(n, int) and n % 15 == 0 else n
@tanakahisateru
tanakahisateru / genuuid4.php
Created November 21, 2019 19:05
NEVER USE this UUIDv4 generator
#!/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 April 22, 2019 08:29
The refactoring
<?php
foreach ($cells $ $cell) {
//
switch ($tdcnt++ % 3) {
case 0:
$cls = 'c_td1';
break;
case 1:
$cls = 'c_td2';
@tanakahisateru
tanakahisateru / main.py
Created February 28, 2019 07:26
牛乳パック1つと卵があれば6つ買うをやるシステム
from shop import Item, Shop
shop = Shop('イオン ドームシティ店')
cart = shop.cart()
cart.add(Item.MILK)
# TODO implement more
receipt = shop.paycheck(cart)