Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / oktest1.pl
Created September 28, 2012 04:33
define spec() simply
# -*- coding: utf-8 -*-
##
## denfine spec() simply
##
use strict;
use warnings;
sub spec {
@kwatch
kwatch / oktest2.pl
Created September 28, 2012 04:37
change block arg of spec() to be optional
# -*- coding: utf-8 -*-
##
## change block arg of spec() to be optional
##
use strict;
use warnings;
use Test::More;
@kwatch
kwatch / oktest3.pl
Created September 28, 2012 04:43
define OK() assertion function
# -*- coding: utf-8 -*-
##
## define OK() assertion function
##
use strict;
use warnings;
@kwatch
kwatch / oktest4.pl
Created September 28, 2012 04:49
define topic() and case_when() functions
# -*- coding: utf-8 -*-
##
## define topic() and case_when() functions
##
use strict;
use warnings;
@kwatch
kwatch / oktest5.pl
Created September 28, 2012 04:58
enhance to build intermediate data structure
# -*- coding: utf-8 -*-
##
## enhance to build intermediate data structure
##
use strict;
use warnings;
@kwatch
kwatch / oktest6.pl
Created September 28, 2012 05:16
add at_end() which registers blocks called end of test.
# -*- coding: utf-8 -*-
##
## add at_end() which registers blocks called end of test.
##
use strict;
use warnings;
@kwatch
kwatch / oktest7.pl
Created September 28, 2012 05:22
define AssertionObject class
# -*- coding: utf-8 -*-
##
## define AssertionObject class
##
use strict;
use warnings;
@kwatch
kwatch / gist:4200068
Created December 4, 2012 02:45
Function Decorator v.s. Method Decorator in Pyramid Framework
###
### Decorator for view function works very well.
###
def GET(route_name, template):
def deco(func):
@view_config(route_name=route_name, request_method='GET',
renderer='templates/'+template)
def fn(request):
# ... do something here ...
@kwatch
kwatch / gist:4204380
Last active November 17, 2015 16:17
Custom Decorator for View Method in Pyramid 1.3
import sys
from pyramid.view import view_config
from venusian import ATTACH_ATTR # view_config() uses 'venusian' module internally
##
## utility
##
def view_method(fn, **kwargs):
# get frame of class definition
@kwatch
kwatch / gist:4586127
Created January 21, 2013 13:40
モデルクラスから Query クラス (or Collection クラス) を分離すれば、黒魔術を一切使わなくても named_scope が実現できることを示すサンプル
## モデルクラスから Query クラス (or Collection クラス) を分離すれば、
## 黒魔術を一切使わなくても named_scope が実現できることを示すサンプル
class ORM::Entity
end
class ORM::Query # or ORM::Collection
def where(*args) ... end
def order_by(*args) ... end
def limit(n) ... end