Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
@hirokiky
hirokiky / templateview.py
Created December 30, 2014 13:02
Django View decorator to convert returned dictionary into TemplateResponse.
from functools import wraps
from django.template.response import TemplateResponse
def template_view(template_name):
""" View decorator to convert returned dictionary into TemplateResponse
You can apply template name for this decorator like this
>>> @template_view
""" Cache <-> Object Mapper
I know there is `rom <https://pypi.python.org/pypi/rom>`_ or some.
"""
import json
from django.core.cache import cache
SEPARATOR = ':'
@hirokiky
hirokiky / update_ff_flash.sh
Created February 6, 2015 13:33
Updating script of Flash plugin for Firefox
cd /tmp
mkdir adobe_flash
cd adobe_flash
wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.442/install_flash_player_11_linux.x86_64.tar.gz
tar axvf install_flash_player_11_linux.x86_64.tar.gz
sudo mv ./libflashplayer.so /usr/lib/mizilla/plugins
@hirokiky
hirokiky / result.txt
Created February 27, 2015 00:55
BooleanField with Django 1.7
Testitg: <class '__main__.RequiredForm'>
======== Should be True: True ==========
is_valid: True
cleaned_data: {'is_test': True}
======== Should be True: true ==========
is_valid: True
cleaned_data: {'is_test': True}
======== Should be True: 1 ==========
is_valid: True
cleaned_data: {'is_test': True}
@hirokiky
hirokiky / resutl.txt
Created February 27, 2015 01:37
BooleanField djangorestframework 3.0.3
Testitg: <class '__main__.RequiredSerializer'>
======== Should be True: True ==========
is_valid: True
data: ReturnDict([('is_test', True)])
======== Should be True: true ==========
is_valid: True
data: ReturnDict([('is_test', True)])
======== Should be True: 1 ==========
is_valid: True
data: ReturnDict([('is_test', True)])
@hirokiky
hirokiky / profmiddleware.py
Created March 2, 2015 05:00
ProfileをするDjango middleware
from io import StringIO
import cProfile
import pstats
from django.conf import settings
class ProfilerMiddleware(object):
""" プロファイラーを実行するMiddleware
@hirokiky
hirokiky / forms.py
Created March 22, 2015 07:35
weiwei's widget
class WidgetForm(object):
def is_valid(self):
pass
def __str__(self):
widget_forms = {
widget_code: modelformset_factory(widget_class)
for widget_code, widget_class in widgets.widgets.items()
}
@hirokiky
hirokiky / kind_of_shit_fluent.conf
Created May 21, 2015 02:46
Fluentd: Enjoy forever. This config causes `stack level too deep (SystemStackError)`. Allof memory willbe eaten, No log will be executed and your server will fail...
<source>
type forward
</source>
<match **>
type record_reformer
renew_record false
enable_ruby true
tag ip_formatted.${tag}
@hirokiky
hirokiky / easyscript.py
Created June 10, 2015 00:55
Basic form of Python scripts.
"""
Usage
=====
::
$ python easyscript.py 1 2
3
"""
@hirokiky
hirokiky / error.txt
Created June 16, 2015 00:55
Error when updating contents which name is as Unicode.
2015-06-16 09:42:09,565 ERROR [waitress][Dummy-4] Exception when serving /manage/terms/ティ/@@properties
Traceback (most recent call last):
File "/home/hirokiky/dev/deepthought/env/lib/python3.4/site-packages/waitress/channel.py", line 337, in service
task.service()
File "/home/hirokiky/dev/deepthought/env/lib/python3.4/site-packages/waitress/task.py", line 173, in service
self.execute()
File "/home/hirokiky/dev/deepthought/env/lib/python3.4/site-packages/waitress/task.py", line 392, in execute
app_iter = self.channel.server.application(env, start_response)
File "/home/hirokiky/dev/deepthought/env/lib/python3.4/site-packages/pyramid-1.6a1-py3.4.egg/pyramid/router.py", line 223, in __call__
response = self.invoke_subrequest(request, use_tweens=True)