Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
@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 / 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 / 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 / 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
""" 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 / 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
_some_global_value = 'hoge'
class A(object):
def __del__(self):
global _some_global_value
_some_global_value = 'fuga'
class B(object):
def hoge(self):
return _some_global_value
@hirokiky
hirokiky / mkpass.py
Created June 25, 2014 01:45
Creating random 8 letter string constructed by alphanumeric.
#! /usr/bin/env python
import string
import random
alphanumeric = string.ascii_letters + string.digits
def main():
return ''.join([random.choice(alphanumeric) for _ in range(8)])
@hirokiky
hirokiky / accept_header_middleware.py
Created May 29, 2014 02:33
Django Middleware to add attribute for Accept header of HTTP
class AcceptMiddleware(object):
""" Middleware to add attribute for Accept header of HTTP
"""
def process_request(self, request):
acc = [a.split(';')[0] for a in request.META['HTTP_ACCEPT'].split(',')]
setattr(request, 'accepted_types', acc)
return None
@hirokiky
hirokiky / has_children_query.py
Last active August 29, 2015 14:01
trying to get pagent having children on django 1.6.
from django.db import models
class Parent(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name