May 17, 2016

Console progress bar

It's very simple:

import sys
def update_progress(iteration, total):
    percent = int(iteration * 100.0 / total)
    sys.stdout.write(
        "\r[ {0:<51} ] {1}% ~{2}".format(
            '#' * (percent / 2), percent, iteration
        )
   )

The main trick is character "\r", which clear previous line.

May 5, 2016

Linux installation

2 years using OSX gave me more insight on how Unix system work more than before. This time for new home's desktop, I decided to use a Linux.

I chosen Debian testing with XFCE

Why testing? It has latest piece of software. Seems to unstable but it works. There is a good alternative are Mint, elementaryOS, good-looking but buggy, and security faults are largely ignored www.techrepublic.com/article/why-the-linux-mint-hack-is-an-indicator-of-a-larger-problem/

XFCE gives many customization chance and very, very fast! Resources usage is also optimized.



Default fonts is unpleasant, especially for Japanese text. To have above result, there is a fix for it by setting fallback chain in /etc/fonts/local.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>serif</family>
<prefer>
<family>Tahoma</family>
<family>TakaoPGothic</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Tahoma</family>
<family>TakaoPGothic</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Monaco</family>
<family>TakaoPGothic</family>
</prefer>
</alias>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="autohint">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
</match>
</fontconfig>
Here I used Tahoma from Windows and Monaco from OSX, but Open Sans and Ubuntu Mono are good alternatives. Takao font is an IPA font derivatives, installed by apt-get install fonts-takao*

Font Osaka causing ugly rendering on many latin characters, better to remove it
sudo rm /usr/share/fonts/truetype/Osaka* -f

It's easy to set system wide shortcuts. There are 2 places:
* Window manager: pre-defined functions
* Keyboard setting: a function is a command





About input methods, there is "uim", better than D-bus and Scim etc I have used.

For Japanese I use Mozc. It's important to set "Default input mode" to Hiragana to make it work as expected.

For Vietnamese I use m17nlib. Add "m17n-vi-telex" to Enabled input methods. It just works.

apt-get install  uim-mozc uim-m17nlib uim-gtk2.0 uim-gtk3




Hope that using it daily can boost Linux skill :D

Additional programs:

apt-get install abiword gnumeric gnome-dictionary gnote systemd-ui keepass2 gufw caffeine ocrfeeder 

Terminal with copy on selection
http://www.linuxnov.com/the-complete-guide-to-configure-terminator-terminal-emulator-layouts/
* Valentina Studio - all in one MySQL, Postgres, MS SQL Server GUI
* komodo-edit - Generic editor
* pycharm - Python IDE
* meld - Diff / merge
* systemd-ui
* Pinta - Image editor
* Synapse - launcher
* keepassx
* gufw - Firewall GUI
* plank - a dock
* caffeine
* ocrfeeder - OCR
* gnome-dictionary
* Abiword
* Gnumeric
* gnote