Skip to content

Instantly share code, notes, and snippets.

View MugeSo's full-sized avatar

TANAKA Koichi MugeSo

View GitHub Profile
@MugeSo
MugeSo / file0.txt
Last active March 25, 2016 14:27
WebStormでtypingsを使ってTypeScriptの定義ファイル管理 ref: http://qiita.com/MugeSo/items/c9a9c35a6d172d9a1c54
$ cd /path/to/project
$ rm -rf typings
$ typings init --upgrade
$ typings install
@MugeSo
MugeSo / file0.txt
Last active August 29, 2015 14:15
Chrome拡張のEventPageでchrome.contextMenusを正しく動かす ref: http://qiita.com/MugeSo/items/e5307bda346c0bb8e22e
{
...
"background": {
"scripts": ["background.js"],
"persistent": false
}
...
}
module LRUMemoryCache {
export class Cache {
private leastRecentlyUsed: Node;
private mostRecentlyUsed: Node;
private map: Map<string, Node>;
private usage: number = 0;
constructor(public size: number) {
if (size <= 0) {
throw new Error('Cache size should be larger than 0');
@MugeSo
MugeSo / AuraRouterMapProvider.php
Last active August 29, 2015 13:56
This class generates routing map for BEAR(http://bearsunday.github.io/) application.
<?php
namespace Webnium\BEAR\Extension\Router;
use Aura\Router\Map;
use Aura\Router\DefinitionFactory;
use Aura\Router\RouteFactory;
use Ray\Di\ProviderInterface;
use Ray\Di\Exception\NotInstantiable;
use BEAR\Sunday\Inject\ResourceInject;
@MugeSo
MugeSo / leak-test.php
Last active August 29, 2015 13:55
Memory leak test of BEAR.Package
<?php
$context = 'prod';
$app = require dirname(__DIR__) . '/bootstrap/instance.php';
$count = $argv[1];
echo "Request page://self/ {$count} times.", PHP_EOL;
for ($i = 0; $i < $count; $i++) {
<?php
$obj = new stdClass();
$obj->a = new stdClass();
$obj->a->child = new stdClass();
$obj->b = new stdClass();
$obj->b->child = $obj->a->child;
$serialized = serialize($obj);
<?php
if ($argc < 3 || $argc > 4) {
printf('Usage: %s [<変動率>] <個数> <目標値>' . PHP_EOL, $argv[0]);
exit;
}
$average = array_pop($argv);
$count = array_pop($argv);
$variability = $argc === 4 ? array_pop($argv) : 0.3;
@MugeSo
MugeSo / LocationHeaderFixer.php
Last active December 29, 2015 03:09
Locationヘッダを修正するインターセプター。 Resource\Page\から始まるクラスのonメソッドにインターセプト。 本当は、HTTPレスポンスを送信する直前でやりたいことだけど、その周辺がDIとかAOPとかできなさげだったのであきらめました。
<?php
/**
* Lisenced under MIT license
*
* Auther: MugeSo
*/
namespace Mugeso\BEAR\Sample\Interceptor;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
@MugeSo
MugeSo / gist:7552072
Last active December 28, 2015 19:39
今、BEAR.Sundayについて思ってることメモ

issueにするかどうか迷うレベルのことをとりあえずメモって置く場所

設計に関する疑問点

  • BEAR\Resource\ResourceInterfaceがヘッダとペイロードを持たないのはなぜだろう。 このためHTTPより語彙が少なくなり、HTTPスキームのリソースへのアクセスを$this->resourceから行おうとしたとき不都合になることも。pageスキームのリソースでもHTTPヘッダやペイロードにアクセスするのにWebContextProviderのお世話になったりしないといけない。
  • アプリケーションがルーティングを持っていて起動スクリプトで実行しているけど、なぜBEAR/Resource/Adapter/Pageに持たせていないのだろう。 page://self/hogehogeからクラス名に変換するところでもできるよね。 取りだしたクエリの処理ができないのか。でも、位置的にはこのあたりがいいと思うのだけれど。
  • 前項にも関わるけれど、uriのパス部分からクラス名に変換・逆変換を行う処理はクラスを独立させた方が良いと思う。セキュリティ設定やらなんやらでも使うと思うので。
@MugeSo
MugeSo / JSONPointer.js
Last active December 28, 2015 11:39
JSON Pointer [RFC6901](http://tools.ietf.org/html/rfc6901) sample implementation.
function parseJSONPointer(string) {
if (string.length < 1) {
return []; // root
}
if (string[0] !== '/') {
throw new Error('Invalid JSON Pointer syntax');
}
return string.split('/').map(function(referenceToken){