Posts

Showing posts with the label python

Python yield paradigm

Image
Python yield paradigm Table of Contents generator or iterator generator pipe coroutine concurrency The yield keyword in python language is its landmark and invention, it is not just a language syntactic and feature, it lets python programming rocks in the functional programming way. Here in this article, I try to collect all the yield magic here to surprise the python newbie. 1 generator & iterator "yield" is the keyword that to make a generator in python, so what the generator is? Before that, I just try to explain what the Iterator is first? An iterator is an easier and more common concept in objective oriented languages, take java, for example, basically, every container can be converted to an iterator. List < String> namesList = new ArrayList < String> (); // add 3 names namesList.add( "moses" ); namesList.add( "jacobs" ); namesList.add( "davide" ); // iterate via Iterator Iterator < Str...

Learning a new way to release and package python source code

Image
This article is one part of learning notebook after I read the youtube-dl 's source code, I learned a lot of knowledge from this software, I guess the most interesting part is found two porn website inside it, haha. The anther interesting thing, I learned from its source code, is a python packaging technology. It is a new way to release or publish python software. Before I learned this way, I always use the following two methods to publish python software. Just release the raw source code. Use the package management tools like setuptools or distutils But, youtube-dl release itself in a standalone executable single file. So I read its build script, it zipped all its source code into a package and it is its way to make an executable file. I guess python interpreter has the capacity of interpreting source code from the zip file. As usual, I wrote some sample code to illustrate how this way works, and you can browser sample code from the following site. https://githu...

A LAN server discovery web app

Image
A LAN server discovery web app Table of Contents Requirement Next movement how to deploy the service? 1 Requirement the purpose of this project: Many services were running in my desktop environment at the company LAN, but the IP address was always alternate after I reboot, so my initial intent to develop this app is to let my fellow colleagues detect my desktop's IP address much quickly. this solution is to run a HTTP server on my desktop, and the client must post request at least with a key/value pair: req=get_ip. Then a client scan all the LAN IP address with that request, my computer will response with {'status' : 0, 'ret':ip_address}. 2 Next movement Since I am studied a lot of certification and encryption knowledge recently, I guess the next target of this project is to add a certificate process to reject the fake one. The simple ways were to employ an asymmetry encryption algorithm like RSA, then client generate a random number...

Dropbox Hacking

Image
Dropbox hacking Table of Contents Background How Dropbox implement its command mode? Loading image from serialized data 1 Background Yesterday, I upgrade my ubuntu into Trusty Tahr, the development branch of the newest ubuntu. Dropbox is one of many problems after the upgrade, although I found the solution finally, I discovered that Dropbox's technology to release software is worth hacking. Another reason to hacking Dropbox is that I love it so much, my daily works in computers depended on it, it is the coolest cloud storage tool, absolutely the best one. The first time I run dropbox after I install it, it emits a dialog to indicate the progress of download a package from its website, which is the real program to does the sync job, and its default install location is ~/.dropbox-dist. I think that's so cool, and I wanna learn how to do it. This article is hacking Dropbox release package in a linux environment. I tried to hack its Mac OS X's package,...

Hash functions in web security

Image
Hash functions in web security Table of Contents What the hash function is? Http Cookies password 1 What the hash function is? A hash function is a one-directional one-to-one or multiply-to-one function, which can project data in one space to another, but not reverse. The key point here is one-directional projection, if you found a way to reverse this process, then this hash algorithm is corrupted, if the hash algorithm corrupted, the whole web security is down. You would not want that happen, right? So, which hash functions are the popular ones? the popular hash function includes md5, sha256. In python standard distribution, it provided an hashlib module which provided the usual hash functions. The following code snippet is an example to get digest from messages by python's hashlib module. The digest is the hash value of a message.  digest = hash(message). import hashlib hashlib.md5( 'hello world' ).hexdigest() hashlib.sha256( 'hello wor...

为python添加默认的模块搜寻位置

如何查看python默认的模块搜寻位置: >>import sys >>print sys.path 如果要添加自己的模块搜寻位置; >>sys.path.append('the/way/to/my/path') 当然也可以在dist-packages(即 /usr/local/lib/python2.6/dist-packages )添加一个路径文件,如mypkpath.pth,必须以.pth为后缀,写上你要加入的文件名称就是了.