tcl: replace a sub-string with another string








puts [string map {" " "" a 1 b 2 c 3} "a b c"]
# output is 123

See also




tcl: check if a string starts with a sub-string








if { [string first "abc" "abcd"] == 0 } {
    puts "yes"
} else {
    puts "no"
}



Linux: find files only








find ./ -type f



Install microsoft office 2007 on Ubuntu Linux 13.10








  1. Install playonlinux:
    sudo apt-get install playonlinux curl p7zip-full
  2. Run playonlinux:
    playonlinux
  3. Click Install then in the new dialog window, select Office then select Microsoft Office 2007 in the list.
  4. Follow the instructions to insert your office 2007 disc to install.



Linux: list files in zip archive








  • If you want to list the files in a zip archive without extracting:
    unzip -l your.zip



ANT: set target jvm in the build.xml file by adding source and target options to the javac task








According to https://ant.apache.org/manual/Tasks/javac.html
 <!-- -->
 <!--Target: compile-->
 <!-- -->
 <target name="compile" depends="init,clean" description="Compile the java source">
  <!-- Compile the java code from ${src} into ${build} -->
  <javac debug="on" debuglevel="lines,vars,source" srcdir="${src}" destdir="${build}" source="1.6" target="1.6">
   <classpath>
    <pathelement location="${commons-jar}" />
   </classpath>
  </javac>
 </target> 

see also




Fix lock screen shortcut key bind in Lubuntu 13.10








After upgrade to Lubuntu 13.10. The Ctrl-Alt-L key combo defined in ~/.config/openbox/lubuntu-rc.xml bind to xsreensaver-command -lock is no longer working because xsreensaver is not installed. Instead, we should replace it with lxlock. Edit ~/.config/openbox/lubuntu-rc.xml:
    <!-- Lock the screen on Ctrl + Alt + l-->
    <keybind key="C-A-l">
      <action name="Execute">
        <command>lxlock</command>
      </action>
    </keybind>



Install and configure fluxbox on Ubuntu 13.10








  1. Install fluxbox as root or sudoer:
    sudo aptitude install feh fluxbox libjpeg-progs libjpeg-turbo-progs menu xfonts-terminus
  2. Set background color or wallpaper: edit ~/.fluxbox/overlay:
    • add the following lines to set background color:
      background: solid
      background.color: #303030
    • or add the following lines to set background wallpaper image:
      background: fullscreen
      background.pixmap: ~/Pictures/MyWallpaper.png



Install fcitx on Ubuntu 13.10 to replace ibus








Upgraded Ubuntu 13.10. The ibus character select window is incomplete and it is unusable. And I could not find a solution for it so far. It forced me to look at fcitx.
  1. Uninstall ibus and all its input methods:
    sudo aptitude purge ibus ibus-gtk ibus-qt4 ibus-sunpinyin ibus-table ibus-table-wubi ibus-libpinyin ibus-sunpinyin libibus-1.0-5 python-ibus ibus-pinyin
  2. Install fcitx:
    sudo aptitude install fcitx fcitx-libpinyin
    fcitx-libpinyin is better then fcitx-sunpinyin or fcitx-pinyin IMO
  3. Start fcitx:
    fcitx -rd
  4. You may need to restart your desktop manager, e.g. lightdm, in a console login as root:
    sudo /etc/init.d/lightdm restart
    or simply restart your computer



cups: /usr/lib/cups/filter has insecure permissions








Installed to printers without error. But it failed to print with error in /var/log/cups/error_log:
E [11/Oct/2013:07:43:44 +1100] FujiXerox-DocuPrint-C3300DX: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:07:43:44 +1100] FujiXerox-DocuPrint-C3300DX: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:07:43:44 +1100] FujiXerox-DocuPrint-C3300DX: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:07:43:44 +1100] TOSHIBA-eStudio-4540C: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:07:43:44 +1100] TOSHIBA-eStudio-4540C: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:14:25:19 +1100] FujiXerox-DocuPrint-C3300DX: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:14:25:19 +1100] [Job 3] Unable to start filter "pdftopdffx" - Success.
E [11/Oct/2013:14:25:19 +1100] [Job 3] Stopping job because the scheduler could not execute a filter.
E [11/Oct/2013:14:28:28 +1100] TOSHIBA-eStudio-4540C: Directory "/usr/lib/cups/filter" has insecure permissions (042775/uid=0/gid=0).
E [11/Oct/2013:14:28:28 +1100] [Job 4] Unable to start filter "pdftopdf" - Success.
E [11/Oct/2013:14:28:28 +1100] [Job 4] Stopping job because the scheduler could not execute a filter.
E [11/Oct/2013:14:30:20 +1100] [Job 3] Stopping unresponsive job.
E [11/Oct/2013:14:33:29 +1100] [Job 4] Stopping unresponsive job.

The solution is simle, run the following command as root:
sudo chmod 2755 /usr/lib/cups/filter



sed: append string to the end of the matching line








  • The orginal file file.txt:
    abc
    cde
    efg
  • Apend 123 to the line: cde. The expected result text should be:
    abc
    cde 123
    efg
  • The sed command:
    sed '/^cde/ s/$/ 123/' file.txt



sed: insert or append line after matching line








  • Original text file: 1.txt:
    abc
    def
    ghi
  • To insert line before line "abc":
    sed -i '/^abc/ i 111' 1.txt
    the result will be:
    111
    abc
    def
    ghi
  • To append line after line "abc":
    sed -i '/^abc/ a 111' 1.txt
    the result will be:
    abc
    111
    def
    ghi



范天恩:干就得有牺牲,摊上谁是谁











Ubuntu 13.04: cups server not starting








The cups server is not started when the system starts. This causes the cups client fails to connect to cups server. You can manually start the server by
sudo /etc/init.d/cups start
but to solve the problem completely, you need to install avahi-daemon package:
sudo apt-get install avahi-daemon



Java: Map class keeps insertion order








LinkedHashMap class is what we want.


Lubuntu Linux: Command to start lxde in NX session








/usr/bin/startlubuntu



See also




Lubuntu (LXDE) Linux: Skype window off screen, how to move it back?








Hold Alt and mouse left click on any part of the window then hold the mouse and move.


Install lxde on Ubuntu Linux








  • To install vanilla LXDE:
    sudo apt-get install lxde
  • To install Lubuntu customized LXDE:
    sudo apt-get install lubuntu-desktop



Ubuntu Linux: disable apport








  • Method 1:
    sudo sed -i s/enabled=1/enabled=0/ /etc/default/apport
  • Method 2:
    gksudo xdiagnose

See also




ibus tray icon missing on LUBUNTU linux 13.04








Install the following packages libappindicator1 and python-appindicator:
sudo apt-get install libappindicator1 python-appindicator python-gconf python-glade2 python-pexpect
will fix the problem.

See also




Ubuntu Linux: BADSIG error for openprinting








  • Description:
    W: GPG error: http://www.openprinting.org lsb3.1 Release: The following signatures were invalid: BADSIG 7A4B44C2D2A2203E OpenPrinting (OpenPrinting Test Key) <webmaster@openprinting.org>
  • Solution:
    edit /etc/apt/sources.list, and replace
    deb http://www.openprinting.org/download/printdriver/debian/ lsb3.1 gutenprint
    with
    deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main
    then run
    sudo apt-get update



Ubuntu: NO PUBKEY for www.openprinting.org








  • Description:
    when running apt-get update, got the following error:
    W: GPG error: http://www.openprinting.org lsb3.2 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7A4B44C2D2A2203E
  • Solution:
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7A4B44C2D2A2203E
    sudo apt-get update