Sunday, December 25, 2016

imagemagick - add date on image


  • Install
  • sudo apt install imagemagick

  • example for batch mark date on images
  • for img in *.jpg;
    do convert "$img" -gravity SouthEast -pointsize 64 -fill white -annotate +30+30 %[exif:DateTimeOriginal] "time_""$img";
    done

    Sunday, December 18, 2016

    Atom - source editor

    Atom - excellent source editor under Linux, the most import thing is it's "FREE"
  • Install
  • sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update sudo apt-get install atom

  • Ignored names (useful for search)
  • .git, .hg, .svn, .DS_Store, ._*, Thumbs.db, *.txt, *.tags, tags, *.stack, _out, *.htm, *.lst, .tags1


  • Best Packages for developers
  • Atom-ctags
    Atom Beautify
    File-icons
    Highlight-line
    Highlight-selected
    Project-Manager
    Symbol-tree-view
    Terminal-plus
    Vertical-tabs
    Merge-conflicts
    Todo-show
    git-blame

    SSD Optimization under Ubuntu

  • Reduce flush frequency
  • Add "noatime" on /etc/fstab UUID=f0ae2c59-83d2-42e7-81c4-2e870b6b255d / ext4 noatime,errors=remount-ro 0 1
  • Reserve some space for Over-provision
  • leave at least 7% capacity size for unformatted. (14 % is better)
  • Enable TRIM suuport
  • By default, Ubunut 16.04 will support trim operation automatically, but you could perform it manually
  • Reference
  • https://sites.google.com/site/easylinuxtipsproject/ssd

    PS. Trust me, I have over 6 years experience on SSD firmware development.

    Static code analysis - pylint

    popular static code analysis for python language
  • Install (via pip)
  • pip install pylint
  • Run pylint
  • pylint [SOURCE]
    Don't like command line tool? try pylint-gui pylint-gui

    Python package installer

    For all python developer, you will need it
  • for python 2.x
  • sudo apt install python-pip
  • for python 3.x
  • sudo apt install python3-pip

    Static code analysis - flawfinder

    Unlike cpecheck, flawfinder will looking for the security vulnerability of your source code
  • Install
  • sudo apt install flawfinder
  • Run flawfinder
  • flawfinder --html --quiet --dataonly . >> output.html
  • Reference
  • https://security.web.cern.ch/security/recommendations/en/codetools/flawfinder.shtml

    Static code analysis - cppcheck

    Great static code analysis tool for C/C++ programming language
  • Install
  • sudo apt install cppcheck
  • Run cppcheck and redirect result to output file
  • cppcheck --enable=all --force -j4 . 2> output
  • run cppcheck with html report
  • cppcheck --enable=all --inconclusive --xml-version=2 --force --library=windows,posix,gnu [PATH_TO_SOURCE] 2> result.xml && cppcheck-htmlreport --title="Your Project Name" --source-dir=[PATH_TO_SOURCE] --report-dir=[OUTPUT_DIR] --file=result.xml && rm result.xml Would like to try latest version of cppcheck? just clone the source from github https://github.com/danmar/cppcheck.git for more detailed information, please visit the home page https://github.com/danmar/cppcheck
  • Reference
  • https://sites.google.com/site/opensourceconstriubtions/ettl-martin-1/tutorials/how-to-generate-an-html-report-with-doxygen-using-the-linux-command-line-interface

    Run 32 Bits program on Ubuntu 64 Bits

    Sometimes, you might need to run 32 bits program under 64 bits environment. Here are the packages you need sudo apt install primus-libs-ia32 sudo apt install gcc-multilib sudo apt install lsb

    hdparm - Sorage Device Configuration Tool

    Official Website: hdparm

    hdparm is a powerful and open source storage device configuration tool under Unix/Linux system. Here are the parameters I frequently used.

    • Identify Devicehdparm -I /dev/sdb
    • SecureErase hdparm --user-master u --security-set-pass p /dev/sdb
      hdparm --user-master u --security-erase p /dev/sdb
      hdparm --user-master u --security-unlock p /dev/sdb
      hdparm --user-master u --security-disable p /dev/sdb
    • Set Maximum Sector (84GB / 128GB)hdparm -N p164115504 --yes-i-know-what-i-am-doing /dev/sdb

    To pursue higher performance, storage device might implement data caching (store in the internal DRAM). However, it might have the risk of data loss, especially when a power failure occurred. For data protection purpose, we could disable write cache to prevent data loss disaster. Here are the steps for disabling write cache.
    Disable Write Cache(Assume your device mounted on /dev/sdb) hdparm -W 0 /dev/sdb Enable Write Cache hdparm -W 1 /dev/sdb Once you disable the write cache, the performance will drop sharply!!!

    Linux S3/S4 testing tool - rtcwake

    Source: lpmt.c

    If you are looking for a S3/S4 testing program under Linux OS. Here is a simple example to demonstrate how to do it by rtc

    Compile:
    gcc -o lpmt lpmt.c

    Run:  (S3 for 100 cycles)
    sudo ./lpmt S3 100
    use it at your own risk :)

    Ubuntu menu editor - alacarte

    very useful tool sudo apt install alacarte

    Thursday, December 01, 2016

    Thursday, November 24, 2016

    Ubuntu module blacklist

    Edit blacklist.conf sudo gedit /etc/modprobe.d/blacklist.conf Add below statement at the end of the blacklist.conf blacklist [module name] Update ramfs and reboot sudo update-initramfs -u sudo reboot

    Tuesday, November 08, 2016

    Linux and Unix grep command

    memo for frequently used command grep -nr "pattern you looking for" . Linux and Unix grep command

    Wednesday, October 19, 2016

    Change fonts on Ubuntu

    Install unity-tweak-tool sudo apt install unity-tweak-tool

    Monday, October 17, 2016

    Install R on Ubuntu 16.04

  • Add R repository
  • sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list
  • Add R to Ubuntu Keyring
  • gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 | sudo apt-key add -
  • Install R-base
  • sudo apt-get update sudo apt-get install r-base r-base-dev
  • Install GUI tool - Rstudio
  • sudo apt-get install gdebi-core wget https://download1.rstudio.org/rstudio-0.99.896-amd64.deb sudo gdebi -n rstudio-0.99.896-amd64.deb rm rstudio-0.99.896-amd64.deb

    Saturday, July 09, 2016

    [Ubutnu] analyze system boot time

    Simply execute the following command to see the detailed boot up time systemd-analyze blame

    [Ubutnu] Create bridged network for qemu

    Simple way to create bridged network between Ubuntu host and qemu client Install bridge-utils package first. sudo apt-get install bridge-utils Edit /etc/network/interfaces, and append the following configurations. Add a bridged network (br0) to your host network adapter (eth0)
    ------------------------
    auto br0
    iface br0 inet dhcp
     bridge_ports eth0
     bridge_stp off
     bridge_fd 0
     bridge_maxwait 0
    ------------------------
    Restart your network. sudo /etc/init.d/networking restart Edit your script to boot qemu client, here is an example (-net nic, -net bridge,br=br0) qemu -net nic, -net bridge,br=br0 you are now ready to boot your qemu client with bridged network

    Friday, July 08, 2016

    [Ubutun] Repiar no sound problem on Ubuntu 16.04

      Uninstall pulseaudio package
    sudo apt-get purge pulseaudio
      Remove the following files/folders
    sudo rm -rf ~/.config/pulse /etc/pulse /usr/share/pulseaudio
      Reboot you system
      Reinstall pulseaudio package
    sudo apt-get install pulseaudio
      You might need to reinstall ubuntu-desktop if your 'Ubuntu System Settings' has disappeared
    sudo apt-get install ubuntu-desktop

    Saturday, June 25, 2016

    [gitlab] Backup & Restore





  • Backup Repository, Wiki, and etc.
  • sudo gitlab-rake gitlab:backup:create




  • Restore gitlab from a backup number 164486484 (move backup file under /var/opt/gitlab/backups/ folder)
  • sudo gitlab-rake gitlab:backup:restore BACKUP=164486484




  • Upload backup to local directory
  • Edit '/etc/gitlab/gitlab.rb', find 'backup_upload_connection', change 'local_root''s value with your backup path
    ----------------------------------------------------------------
    gitlab_rails['backup_upload_connection'] = {
      'provider' => 'Local',
      'local_root' => '/mnt/backups'
    }

    # The directory inside the mounted folder to copy backups to
    # Use '.' to store them in the root directory gitlab_rails['backup_upload_remote_directory'] = 'gitlab_backups' ----------------------------------------------------------------
    Don't forget to give access permission for git user
    You need to run gitlab reconfigure to apply new settings sudo gitlab-ctl reconfigure



  • Setup crontab for daily backup
  • sudo crontab -e Add the following two line command into your crontab (Ex. cron will execute gitlab backup every 2:00 A.M, and backup /etc/gitlab every 2:05 A.M) 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 5 2 * * * umask 0077; tar -cf /mnt/gitlab/backups/$(date "+etc-gitlab-%s.tar") -C / etc/gitlab *if you get some error message which are related to folder permission, please make sure your backup location are writeable for git user.




  • Restore Configuration File (Move backup file under /etc/gitlab/ folder)
  • sudo tar -xf etc-gitlab-XXXXXXXXXX.tar -C /
  • Reference
  • https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md http://docs.gitlab.com/omnibus/settings/backups.html

    Friday, May 27, 2016

    [Ubuntu] Change network name to eth0

    1. Modify GRUB_CMDLINE_LINUX="" with GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" sudo nano /etc/default/grub 2. update grub and reboot sudo update-grub

    Saturday, May 14, 2016

    Linux Subtitle Editor - (gaupol / gnome-subtitles)

    gaupol sudo apt-get install gaupol gnome-subtitles sudo apt-get install gnome-subtitles