Wednesday 15 October 2014

pickle

After writing and loading JSON files several times to record and read a object of tree structure, I found it quite difficult to minimize the size of the JSON files because some floating point number in the object is printed to character and take up more memory space.  Google for few seconds, I found a solution to save files more efficiently. Surprisingly it is easy solution from socksolution.com. Pickle is going to save my file and my sleeping time as well. Here is the solution.

To record the object to file:

import pickle
pickleFile = open('root.pickle', 'wb')
pickle.dump(root, pickleFile, pickle.HIGHEST_PROTOCOL)
pickleFile.close()



To read the file to the object:

pickleFile = open('root.pickle', 'rb')
root = pickle.load(pickleFile)

pickleFile.close()


Tadaa!

Thursday 9 October 2014

Top programming languages

What is the best programming language? A IEEE spectrum article on top list programming gave a good conclusion. Java seems to be the top and widely used. C/C++ has long history and become standard for low level application for embedded systems. Python is at the 4th for the web application. I personally like Python because it easy to maintain and fast coding!

top 10 progamming langauage Top 10 Programming Languages to Learn

I also did a diagram according to technology of some popular websites by simply extract the words in columns and put them in D3 wordcloud



“Front-end”, “Back-end”, Database, JavaScript, C, C++, Go, Java, Python, BigTable, JavaScript, Hack, PHP, C++, Java, Python, Erlang,  D, Xhp, MySQL, HBase, Flash, JavaScript, C, C++, Python, Java, MySQL, BigTable, JavaScript, JavaScript,  PHP, MySQL, PostgreSQL, JavaScript, ASP.NET, “Microsoft_SQL_Server”, JavaScript, ASP.NET, “Microsoft_SQL_Server”, JavaScript, PHP, MySQL, MariaDB, JavaScript, Python, BigTable, JavaScript, ASP.NET, “Microsoft_SQL_Server”, JavaScript, C++, Java, Scala, Ruby, Rails, MySQL, JavaScript, PHP, MySQL, JavaScript, Java, C++, Perl, JavaScript, Java, JavaScript, “Oracle_Database”, JavaScript, Java, JavaScript, Scala, JavaScript, C# , ASP.NET, MVC, “Microsoft_SQL_Server” 

Friday 3 October 2014

test ipython.parallel

from IPython import parallel
c = parallel.Client(packer='pickle')
c.block = True
print(c.ids)

dview = c.direct_view()
dview.block = True
print(dview)

dview.execute('import numpy as np')

###using execute
dview.execute('a=np.random.randint(0,5,size=(1,2))')
print("a:\n{}".format(dview.gather('a')))

###using run
f=open('iptest.py','w')
f.write('import numpy as np\nb=np.zeros(shape=(1,4),dtype=np.int32)')
f.close()
dview.run('iptest.py')
print("b:\n{}".format(dview.gather('b')))
print type(dview.gather('b')[0,0])

###using dictionary
dview['c']=np.ones(shape=(2,3),dtype=np.int8)
print("a:\n{}".format(dview.gather('c')))
print type(dview.gather('c')[0,0])

---------------output------------------
[0, 1, 2]
<DirectView all>
a:
[[4 0]
 [4 1]
 [3 2]]
b:
[[0 0 0 0]
 [0 0 0 0]
 [0 0 0 0]]
<type 'numpy.int32'>
a:
[[1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]]
<type 'numpy.int8'>