May 28, 2014

Interesting points of Python

After 4 months learning and its ecosystem I felt the following amazing things in Python:
(created or borrowed from other language)

1. List comprehension
Quick and beauty way to work with array of elements:
>>> vec = [2, 4, 6]
>>> [3*x for x in vec]
[6, 12, 18]
More: https://docs.python.org/3.4/tutorial/datastructures.html#list-comprehensions

2. Decorator
A function, which wraps another function, is called "decorator", enable us to write:
@app.route('/')
def hello_world():
    return 'Hello World!'

More: http://www.jeffknupp.com/blog/2013/11/29/improve-your-python-decorators-explained

3. Iterator & generator
Good for memory allocation and nice syntax.
https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1

4. List unpacking and indexing

5. Named-arguments in functions
It's make the code more readable, without length like Objective-C

6. Collections
defaultdict, namedtuple, ... are our friends!

7. Context manager
It's "with" structure.

More reference:
http://stackoverflow.com/questions/101268/hidden-features-of-python
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://www.cs.cmu.edu/~nschneid/pythonathan/

May 16, 2014

Push an existing git repos to a SVN repos

The old thing (SVN) and new thing (Git) sometimes are forced to co-exist.

Assume we are at local repos work folder, here are the trick (rebase git-svn):

$ git svn init http://svn/path
$ git svn fetch
$ git rebase git-svn
$ git svn dcommit
From now on, to push to SVN, issue:
git svn dcommit 
to pull from SVN:
git svn rebase

May 13, 2014

SQLite

I got "unable to open database file" when trying to make changes in an SQLite database using PHP PDO.

Finally the real problem is:

If we have /path/name.db writable, it's NOT enough!
We have to make the container dir of database file (this case, /path/ ) be writable AS WELL.

Tricky! I guess SQLite need temporary space in this dir.