Tips & Tricks

Bash: Batch file renaming

$ for i in ./*.jpg ; do mv "$i" "${i/-[0-9.]*.jpg/.jpg}" ; done
# Quotes are needed for filenames with spaces.
# Will rename
- mypic-2.1.13.jpg -> mypic.jpg
- visay-1.900.1.jpg -> visay.jpg
- trip-kampot-1.2.3.jpg -> trip-kampot.jpg

Docker: Copy image from one host to another

$ docker save <image> | bzip2 | ssh user@host 'bunzip2 | docker load'

Git rebase last 2 commits

$ git rebase -i --root

Enable 4G LTE on LG G2

 # Dial this number without pressing call
# Go to "Phone Information"
# Set Preferred Network Type
# Select "LTE/GSM/WCDMA"

Comment / Uncomment in vim

 # Edit the file, example
$ sudo vi /etc/hosts
# Place insertion point on start line of the list wanted to comment or uncomment
$ Shift + v
# Press up or down arrow until the last line of the list wanted to comment or uncomment
# To comment
$ Shift + i -> Type "#" -> Esc
# To uncomment
$ Press "d" or "x"
# Save and close the file with :wq

VIM: Saving with sudo, without opening with sudo

:w !sudo tee %
# Then press "L" to take new changes

Upgrade ibus from 1.5.5 to 1.5.11 on Ubuntu 14.04

 # Install dependencies
$ sudo apt-get install libdconf-dev libnotify-dev intltool libgtk2.0-dev libgtk-3-dev libdbus-1-dev
# Download ibus 1.5.11 source
$ wget
# Extract the archive
$ tar -xvf ibus-1.5.11.tar.gz
# cd into the directory
$ cd ibus-1.5.11
# Compile
$ ./configure --prefix=/usr --sysconfdir=/etc && make
# Install
$ sudo make install
# Verify
$ ibus version
# You should get the output "IBus 1.5.11"

Clear DNS caches on Ubuntu 14.04 Desktop

$ sudo /etc/init.d/dnsmasq restart

Stop / remove all Docker containers

$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a -q)

Sort files in vim

# Edit the file, example
$ sudo vi /etc/hosts
# Place insertion point on start line of the list wanted to sort
$ Shift + v
# Press down arrow until the last line of the list wanted to sort
$ :sort
# Press enter
# Save and close the file with :wq

Search and replace in Vim (adding c to the end of command to enable confirmation)


Set tracking information for current git branch

$ git branch --set-upstream-to=origin/<branch> <current-local-branch>

Mounting Samba Share on Ubuntu

 #For Ubuntu 13.10
$ sudo mount.cifs //server-ip/path/their-project /home/visay/dev/my-project -o guest,rw,uid=1001,gid=1001
# For Ubuntu 13.04
$ sudo mount -t cifs -o guest,rw,uid=1001,gid=1001,sec=ntlm //server-ip/path/their-project /home/visay/dev/my-project

Create tap for Ubuntu VirtualBox to use wireless Internet from Host

 # Install parprouted
$ sudo apt-get install parprouted
# Enable IP forwarding
$ sudo vi /etc/sysctl.conf # Make sure you have net.ipv4.ip_forward = 1
# Restart the service
$ sudo sysctl -p
# Replace 'visay' with your ubuntu username
$ sudo VBoxTunctl -b -u visay
$ sudo ip link set tap0 up
# Replace '' with your IP, e.g: 192.168.0.x
# x is the your tap IP where you can choose whatever but make sure not to conflict with existing IP on your network
$ sudo ip addr add dev tap0
# Replace wlan0 if you have another wireless name; run ifconfig to check that out
$ sudo parprouted wlan0 tap0
# Adjust '10.10.10' with your IP range set above. Keep 0 at the last part
$ sudo route add -net netmask tap0
# Replace wlan0 if you use another wireless name
$ sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE


# To remove the tap, just execute the following commands:
$ ifconfig tap0 down
$ VBoxTunctl -d tap0
$ pkill parprouted

In your VirtualBox network setting, you should be able to choose tap0 in your network adapter.
Tested with VirtualBox v.4.3.2 for Ubuntu 12.10

Include Extension with Namespace support as TypoScript Object

lib.rightContent = USER
lib.rightContent {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
vendorName = VisayInfo
extensionName = DropboxCarousel
pluginName = Carousel
actionName = play

settings =< plugin.tx_dropboxcarousel.settings
persistence =< plugin.tx_dropboxcarousel.persistence
view =< plugin.tx_dropboxcarousel.view

Find files by its content (Only print filenames)

 # By default, grep command prints the matching lines
# You can pass -H option to print the filename for each match.
$ grep -H -r “my content” /home/visay

Recursively delete .svn directories

rm -rf `find . -type d -name .svn`

Compile less file to css file

 # Adding -x switch to have css compress
lessc -x path_to_less_file.less > path_to_css_file.css

Warning! Make sure you have less binary in your system path. You can install it as following:

 # Install npm if you don't have it yet in your system
sudo apt-get install npm
# Install nodejs
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
# Installing less on the server
sudo npm install -g less

Remove remote branch in git

 # Delete reference locally
git push origin :remote_branch_name
# Prune deleted branch that are still visible to other team
git remote prune origin

Disable/Enable foreign key constraints

 # In the mysql command-line client, execute
# Once the fields were consistent again

Register Metfone Data Service

  • Go to message and write MI5 send to 133. This is to register 5$ for about 2GB data a month.

Configure Git

 # Sets the default name for git to use when you commit
git config --global "Visay Keo"
# Sets the default email for git to use when you commit
git config --global ""

Warning! Best check if you have git 1.7.10 or newer to be able to support the following 2 commands.

 # Set git to use the credential memory cache
git config --global credential.helper cache
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'

Copy file content in command with xclip

 # Downloads and installs xclip
sudo apt-get install xclip

# Copies the contents of a file to your clipboard
xclip -sel clip < /home/visay/.ssh/

Configure SSH with public key

  • Create/Edit file ~/.ssh/config with the following content
User visay123
Port 22
IdentityFile /home/visay/.ssh/id_rsa
  • Copy the content of the local public key /home/visay/.ssh/ to the server at ~/.ssh/authorized_keys

Cloning a project from

 # Go to web root
cd /home/visay/public_html
# Clone the repository with submodules
git clone --recursive .

Forking a project from

  • Go to original repo and click Fork
  • Setup locally
 # Clones your fork of the repo into the current directory in terminal
git clone /var/www/bootstrap
# Changes the active directory in the prompt to the newly cloned "bootstrap" directory
cd /var/www/bootstrap
# Assigns the original repo to a remote called "upstream"
git remote add upstream git://
# Pulls in changes not present in your local repository, without modifying your files
git fetch upstream
# Pushes commits to your remote repo stored on GitHub
git push origin master
# Fetches any new changes from the original repo
git fetch upstream
# Merges any changes fetched into your working files
git merge upstream/master

Installing JSMIN for javascript minification

 # Clone the source code for building
git clone git://
# Compile the file
cd JSMin
cc jsmin.c -o jsmin
# Cleanup
cd ..
sudo mv JSMin /usr/local/lib
sudo ln -s /usr/local/lib/JSMin/jsmin /usr/local/bin/jsmin
# Usage
jsmin < uncompress.js > compress.js "(c) 2012 Keo Visay"

Warning! If compiling fails, make sure you have gcc compiler. You can install it as following:

sudo apt-get install gcc