Skip to content

Instantly share code, notes, and snippets.

View atsuya046's full-sized avatar

Nobuya Oshiro atsuya046

View GitHub Profile
@atsuya046
atsuya046 / strategy.py
Created January 21, 2014 04:47
GoF design pattern with Python. - Strategy
# http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern
# -written-in-python-the-sample-in-wikipedia
"""
In most of other languages Strategy pattern is implemented via creating some
base strategy interface/abstract class and subclassing it with a number of
concrete strategies (as we can see at
http://en.wikipedia.org/wiki/Strategy_pattern), however Python supports
higher-order functions and allows us to have only one class and inject
functions into it's instances, as shown in this example.
"""
@atsuya046
atsuya046 / adapter.py
Created January 20, 2014 04:38
GoF design pattern with Python. - Adapter
# -*- coding: utf-8 -*-
""""http://ginstrom.com/scribbles/2008/11/06/generic-adapter-class-in-python/"""
import os
class Dog(object):
def __init__(self):
self.name = "Dog"
def bark(self):
@atsuya046
atsuya046 / builder.py
Created January 19, 2014 05:07
GoF design pattern with Python
# -*- coding:utf-8 -*-
"""
@author: Diogenes Augusto Fernandes Herminio <[email protected]>
https://gist.github.com/420905#file_builder_python.py
"""
class Director(object):
def __init__(self):
self.buider = None
@atsuya046
atsuya046 / template.py
Last active May 23, 2016 16:56
GoF design pattern with Python
"""http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
An example of the Template pattern in Python"""
ingredients = "spam eggs apple"
line = '-' * 10
# Skeletons
def iter_elements(getter, action):
"""Template skeletons that iterates items"""
@atsuya046
atsuya046 / Berkshelf
Created December 31, 2013 14:44
custom cookbook for install and setting nginx
#repo/Berkshelf
cookbook 'nginx', '~> 0.1.0', path: 'site-cookbooks/nginx'
@atsuya046
atsuya046 / Vagrantfile
Created December 31, 2013 05:23
Vagrantfile for EC2 Ubuntu instance.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Uncomment these lines (and the ones in the generated Gemfile) if you want
# to live on the Edge:
#
# Vagrant.require_plugin "vagrant-berkshelf"
# Vagrant.require_plugin "vagrant-omnibus"
Vagrant.configure("2") do |config|
@atsuya046
atsuya046 / query.py
Created December 20, 2013 11:17
sqliteのクエリを組み立てるとき、配列の長さの分だけ"?"を作る
for row in csv.reader(data):
params = ', '.join(map(lambda s: '?', row))
c.execute('''insert into %s values (%s) ''' % (table_name, params), row)
@atsuya046
atsuya046 / jsonToSqlite.py
Created December 14, 2013 09:09
create sqlite database file from json file
# -*- coding:utf-8 -*-
import json
import sqlite3
JSON_FILE = "some.json"
DB_FILE = "some.db"
traffic = json.load(open(JSON_FILE))
conn = sqlite3.connect(DB_FILE)
@atsuya046
atsuya046 / create_django_pj
Last active December 20, 2015 14:39
How to create Django project.
$ django-admin.py startproject django_test
$ cd django_test/
$ python manage.py runserver
@atsuya046
atsuya046 / Update Android4.3
Created July 28, 2013 09:04
Galaxy NexusをAndroid4.3手動アップデート
$ cd yakju-jwr66v
$ adb reboot bootloader
$ ./flash-all.sh