Skip to content

Instantly share code, notes, and snippets.

View atsuya046's full-sized avatar

Nobuya Oshiro atsuya046

View GitHub Profile
@atsuya046
atsuya046 / visitor.py
Created March 13, 2014 14:07
GoF design pattern with Python - Visitor
"""http://peter-hoffmann.com/2010/extrinsic-visitor-pattern-python-inheritance.html"""
class Node(object):
pass
class A(Node):
pass
class B(Node):
pass
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
tap "thoughtbot/formulae"
brew "carthage"
brew "ffmpeg"
brew "gist"
brew "mas"
brew "pidcat"
@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 / composite.py
Created February 28, 2014 22:33
GoF design pattern with Python - Composite
# -*- coding: utf-8 -*-
"""
A class which defines a composit object which can store
hierarchical dictionaries with names.
This class is same as a hierarchical dictionary, but it
provides method to add/accesss/modify children by name,
like a Composit.
@atsuya046
atsuya046 / setup.md
Last active March 23, 2018 02:38
Setup Mac

Install Homebrew

$ sudo xcodebuild -license

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Java/Kotlin/Scala and more

$ curl -s "https://get.sdkman.io" | bash
@atsuya046
atsuya046 / StateMachine.java
Last active December 29, 2017 09:01
RxJava2 StateMachine
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.functions.Action1;
@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 / builder.py
Created January 19, 2014 05:07
GoF design pattern with Python
# -*- coding:utf-8 -*-
"""
@author: Diogenes Augusto Fernandes Herminio <diofeher@gmail.com>
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 / MyClass.scala
Last active January 28, 2016 02:48
ScalaCheckで独自のGeneratorを作る ref: http://qiita.com/atsuya046/items/2ab7505336a9f892bc47
case class MyClass(number: Int, multiplier: Multiplier) {
def calc: Int = {
number * multiplier.number
}
}
case class Multiplier(number: Int)