Skip to content

Instantly share code, notes, and snippets.

@tomotaka
tomotaka / use_pyramid_i18n.py
Last active December 22, 2015 19:29
use pyramid i18n(localizer) out side of web framework(in my case, it's test)
from pyramid.i18n import make_localizer, TranslationString
dir = '/your/locale/dir'
directories = (dir,)
txt_want_to_translate = TranslationString('hoge_moge')
# txt_want_to_translate = TranslationString('hoge_moge', domain='some_domain')
locale = 'ja'
localizer = make_localizer(locale, directories)
transltaed_str = localizer.translate(txt_want_to_translate)
@tomotaka
tomotaka / multi_gthread.py
Created September 4, 2013 08:32
gevent greenlet thread pool
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gevent
from gevent.event import AsyncResult
from gevent.queue import Queue
__all__ = ('GExecutorNotRunningError', 'GExecutor')
class GExecutorNotRunningError(Exception):
@tomotaka
tomotaka / for_hana.py
Created August 21, 2013 07:35
appendと+の違い
import pprint
print '----try not append----'
a = []
print 'object id of variable \'a\' => %d' % id(a)
print 'content of variable \'a\': %s' % pprint.pformat(a)
a = a + [1]
print 'added value 1 with + operator'
print 'object id of variable \'a\' has changed: %d' % id(a)
print 'content of variable \'a\': %s' % pprint.pformat(a)
@tomotaka
tomotaka / Vagrantfile
Created August 1, 2013 08:37
vagrant digital ocean
# coding: utf-8
Vagrant.configure("2") do |config|
config.vm.hostname = "digital-ocean-test"
config.ssh.private_key_path = "~/.ssh/id_rsa"
config.vm.box = "digital_ocean"
config.vm.provider :digital_ocean do |provider|
provider.client_id = "YOUR CLIENT ID"
provider.api_key = "YOUR API KEY"
@tomotaka
tomotaka / fluent_log_s3.py
Created July 12, 2013 04:11
parser for fluentd-s3 log
#!/usr/bin/python
# -*- coding: utf-8 -*-
import simplejson
import re
import pprint
import iso8601
__all__ = ('FluentLogS3', 'parse_fluent_log_line')
_parse_pat = re.compile(r'\A(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[\-+]\d\d:\d\d)\s+([^\s]+)\s+(.*)\n\Z')
@tomotaka
tomotaka / click_handler.js
Created July 11, 2013 09:31
jQuery click handler
$("#tagid").click(function(){
var someAttr = $(this).attr("data-hoge-fuga");
// do something
});
@tomotaka
tomotaka / update_tag_text.js
Created July 11, 2013 09:30
jQuery update tag text
$("#tagid").text("here is new text for the tag");
@tomotaka
tomotaka / onready.js
Created July 11, 2013 09:29
jQuery onReady
$(function(){
// do something onready
]});
@tomotaka
tomotaka / .screenrc
Created February 14, 2013 06:27
my .screenrc
escape
startup_message off
#attrcolor b ".I"
defbce on
term xterm-256color
termcapinfo xterm* ti@:te@
termcapinfo xterm-256color 'is=J7h1;4;6l'
vbell off
hardstatus alwayslastline "%`%-w%{=b bw}%n %t%{-}%+w"
autodetach on
@tomotaka
tomotaka / .zshrc
Created February 14, 2013 06:25
my .zshrc
setopt prompt_subst
setopt print_eight_bit
setopt no_flow_control
setopt hist_ignore_dups
setopt hist_reduce_blanks
#setopt share_history
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000