Install both Python 2 and 3 on your mac

Step 1: Install Python3 Use brew install python to install python3 on the mac, current version is Python 3.6.5. If your mac has a python2 already, brew will ask for an upgrade, which is fine. # Going to install python3 brew install python # Going to upgrade brew upgrade python Step 2: Install Python2 Homebrew
Read More »

Introduction on Numpy

Install numpy pip3 install numpy Some basic examples: import numpy as np # Create rank 1 array #[1,2,3] a = np.array([1, 2, 3]) # Create rank 2 array #[[ 1, 2, 3], # [ 4, 5, 6]] b = np.array([(1,2,3), (4,5,6)]) # matrix with diff data types b = np.array([(1,2,3), (4,5,"a")]) a and b are
Read More »

Flask Command Line

Happy New Year! Hope everything becomes better in 2018! From the version 0.11.0, Flask began to support shell command. Something you probably you already saw when you are using other web project, such as Django: ./manage.py shell To achieve that, it is quite simple as it only needs two steps: 1. Set up the environment.
Read More »

Get Start with RabbitMQ

RabbitMQ is an open source & enterprise level messsage broker using AMQP protocal. The AMQP protocol is designed for asychronization and message dispatch. RabbitMQ can be used in time-consuming backend jobs such as sending emails to client, generating file for user to download, and so on. Install on Mac brew update brew install rabbitmq Then
Read More »

Using Jinja2 with Flask

Jinja2 is a flexible HTML Template along with with Flask, another commonly used Flask template is Mako. Install Jinja2 Install with PIP pip install jinja2 Basic Operation 1. Determine whether a variable is set or not {# user is a variable, and none is not None #} {% if user is not none %} in
Read More »

@property in Python

What is @property A normal class with class variable num: class Item(object): def __init__(self, value = 0): self._num = value Be aware: _num has no difference with num, the _ just let the variable num to be internal only. We can call this by: create new object item = Item() # set num item.num =
Read More »

Singleton in Python

There are a couple of ways of creating Singleton in Python: use module use __new__ use metaclass use decorator [gist https://gist.github.com/arkilis/67c72117ed76802bd5525e8ccb33c563/] Reference http://python.jobbole.com/87514/ http://www.needone.app

Python instance method vs. Static method vs. Class method

In Python, there are three methods: Instance method Static method Class method Look at the following code, have a test for yourself, what are the output: [gist https://gist.github.com/arkilis/341bf667a577b04b8b3a58bce78809a6 /] Results: 1: foo.method(“instance method”) — OK 2: Foo.method("instance method again") is wrong, as method is the instance method. To run an instance method, you have to
Read More »