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 / periodic.py
Last active January 24, 2022 05:08
Periodic calling with asyncio
import asyncio
import logging
import time
import psutil
logger = logging.getLogger(__name__)
@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 / callpraphmiddleware.py
Created March 2, 2015 06:36
Django Middleware to show call graph.
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput
class ProfilerMiddleware(object):
includes = []
def can(self, request):
@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 / README.md
Created May 19, 2015 08:46
Proxy server by using aiohttp.

Async Proxy Server

Installation

pip install -r requirements.txt

Run

Run the backend server