Skip to main content

Posts

prompt less installing mariadb-server-5.5 on ubuntu

You need to previously set the root password echo mariadb-server-5.5 mysql-server/root_password password xxxxx | sudo debconf-set-selections echo mariadb-server-5.5 mysql-server/root_password_again password xxxxx | sudo debconf-set-selections And then sudo apt-get -y install mariadb-server If you are going to uninstall mariadb totally, you may sudo apt-get purge mariadb* && sudo apt-get autoremove

Install mysql-python with mariadb

mysql-python requires libmysqlclient-dev in ubuntu, but the installation of mariadb will have the lib with unmet dependenccies, so the error of "mysql_config not found" may occurred if you install mysql-python via pip. The case is that mariadb has a compatible package, if you have the ppa setup as in  http://downloads.mariadb.org/ . Just "sudo apt-get install libmariadbclient-dev".

About install from Ubuntu PPA

The PPA is short for Personal Package Archives for Ubuntu , which is a place for publishing/installing personal organized packages from  launchpad.net . Usually, the url of a package archive is organized as https://launchpad.net/~PUBLISHER_NAME/+archive/PACKAGE_ARCHIVE_NAME. At the url, you may see a full list of packages included. You can also search PPA packages in  https://launchpad.net/ubuntu/+ppas  . To install some packages using a ppa, you may use sudo add-apt-repository ppa:PPA_PUBLISHER_NAME/PPA_ARCHIVE_NAME sudo apt-get update sudo apt-get install PACKAGE_NAME If you want to remove a ppa sudo add-apt-repository --remove ppa:PPA_PUBLISHER_NAME/PPA_ARCHIVE_NAME For the command add-apt-repository, if not found, you may need to install python-software-properties for Ubuntu version <= 12.04, or software-properties-common for Ubuntu version >= 12.10. For earlier versions of Ubuntu or just you want manually add the ppa into the source.list,...

A possible [Errno 32] Broken pipe when using socket._fileobject

In Python 2.x, socket object have an makefile() method to provide you a file like object. Please do use it carefully, if the socket itself closed unexpectedly, the fileobject may not know the connection is actually closed. So some buffered write is not going to be performed correctly. For example, considering the following code: import socket sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect(('google.com', 80)) wfile = sock.makefile('w') wfile.write('a') sock.shutdown(socket.SHUT_WR) wfile.close() It will cause exceptions as below: Traceback (most recent call last): File "socket_shut.py", line 9, in wfile.close() File "/usr/lib/python2.7/socket.py", line 279, in close self.flush() File "/usr/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) socket.error: [Errno 32] Broken pipe The reason is that wfile has some buffered write, ...

A workaround for UnicodeDecodeError for kid template

Like previous post , the UnicodeDecodeError may occur in the following code: import kid t_mod = kid.load_template(template_file t_class = t_mod.Template t_class.serializer = kid.HTMLSerializer() t = t_class(**data) return t.serialize(output='html') The problem is caused by data contains some non-ascii data, and the default encoding kid choose for decoding is ascii. Actually kid has an attributing assme_encoding, are used to converting data to unicode. import kid t_mod = kid.load_template(template_file t_class = t_mod.Template t_class.serializer = kid.HTMLSerializer() t = t_class(**data) t.assume_encoding = 'utf-8' return t.serialize(output='html')

A workaround for UnicodeDecodeError when using mako template

Consider following code to rendering data with mako: from mako.template import Template tmpl = Template(filename=some_template_flle, module_directory=some_template_module_path) print tmpl.render(**some_data) The code may have following error, if the some_data contains non-ascii characters, because the implementation use directly use unicode method to convert some_data: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) The error can be fixed by decode the some_data. Or there is another workaround, which is injecting a partial unicode function into the module generated: from mako.template import Template import functools tmpl = Template(filename=some_template_flle, module_directory=some_template_module_path) tmpl.module.unicode = functools.partial(unicode, encoding='utf-8') print tmpl.render(**some_data)

Several Cases of Bit Torrent Sync

Here we are going to test several cases when using BitTorrent Sync. Assuming we have two devices, A and B. Below are the cases: Case 1 1) Create and share folder test1 on Device A, and use the readonly key to create the same folder on Device B. 2) Create test.txt in folder test1 on Device A, the file is synced correctly on Device B. 3) Change test.txt in on Device A, the change is synced correctly on Device B. 4) Create other files in folder test1 on Device B, nothing synced back to Device A. 5) Change the test.txt in Device B, nothing synced back to Device A. 6) Change the test.txt in Device A, nothing synced to Device B. 7) Create test2.txt in folder test1 on Device A, the file is synced correctly on Device B, but test.txt remains modified version on Device B. 8) Remove test.txt in Device B, nothing happend. 9) Change the test.txt in Device A, nothing happened. 10) Remove the folder test1 on Device B from btsync, and readd it with the readonly key, all files in Device A synced t...