BASH: pipe to functions


function ProcessOneEntry() {

while read entry # Use the “read” function to do the trick
# Code here to do the job


# Application 1:
cat AnListFile | ProcessOneEntry

# Or
# Application 2:

find InputDirectory -name “Pattern” | ProcessOneEntry

Build Matlab mex files with CMake

To use CMake to manage the build and install process of your mex files, you need to change the compilation rules of CMake. CMake does not support “mex” compiler naturally, so you need to insert the following commands in your CMakeLists.txt.


# Suffix and Prefix of the output target file
SET( CMAKE_SHARED_LIBRARY_SUFFIX .mexa64 )	# set suffix to .mexa64
SET( CMAKE_SHARED_LIBRARY_PREFIX )		# remove the "lib" prefix

# Variables controlling the build-phrase
SET( CMAKE_CXX_FLAGS "-cxx -largeArrayDims CXXFLAGS='$$CXXFLAGS -std=c++11'" )
SET( CMAKE_SHARED_LIBRARY_CXX_FLAGS )		# remove the -fPIC option. mex does not accept the "-fPIC" option

	"<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -outdir <OBJECT_DIR> -c <SOURCE>; mv <OBJECT_DIR>/$$(basename <SOURCE> .cxx ).o <OBJECT>"

# Variables controlling the linking-phase
SET( CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS )	# remove -shared options. mex does not accept the "-shared" option


# Variables controlling the installation RPATH
# CMake will reset RPATH at the installation phase, so we need to specify CMAKE_INSTALL_RPATH

MESSAGE( STATUS "mex.cmake is loaded.\n" )

## To add an mex file, you can:
#  ADD_LIBRARY( myprogram SHARED myprogram.cxx )
## Make sure you specify it as SHARED, and make sure you use the cxx extension.  

Backup and Play DVD with Linux

If your linux does not play DVD correctly, try this:
sudo apt-get install libdvdread4
sudo /usr/share/doc/libdvdread4/

Backup DVD as ISO file:
ddrescue -d /dev/dvd ~/dvd_backup.iso ~/dvd_backup.log
This is just an example. Please replace the arguments with those of your specific backup task.

According to the following post:
Pack­ages needed:
Gnu ddres­cue

The process:
ddres­cue –n –b 2048 /dev/dvd output.iso
dvd­backup –M –i output.iso –o dvd_structure
mkisofs –dvd-video –o clean_dvd.iso dvd_structure

Step 1 copys the DVD to disk block by block but any bad sec­tors found zero data is filled in. At this point you are left with a DVD iso that has the copy pro­tec­tion removed but the encryp­tion is still intact. Step 2 extract the con­tents to a direc­tory. This sec­ond step leaves you with the struc­ture of a dvd with­out the encryp­tion. I want to pre­serve every­thing about the orig­i­nal DVD (except the copy pro­tec­tion and encryp­tion) so I used the mir­ror option. This leaves me with all the fea­tures and orig­i­nal menus. Step 3 take the DVD struc­ture and pack it up into a nice ISO.

Enable/Disable Touch Screen with Ubuntu

1. Identity Touch Screen
xinput –list
It will output a list of your input devices. For example:
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=10 [slave pointer (2)]
⎜ ↳ ELAN Touchscreen id=12 [slave pointer (2)]
⎜ ↳ Microsoft Microsoft® 2.4GHz Transceiver v5.0 id=13 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=9 [slave keyboard (3)]
↳ Lenovo EasyCamera id=11 [slave keyboard (3)]
My touch screen is “ELAN Touchscreen”

2. Enable/Disable Touch Screen
xinput –enable “Name Of Your Touch Screen”
xinput –disable “Name Of Your Touch Screen”

For example:
xinput –disable “ELAN Touchscreen”

Set Default File Association in Ubuntu Unity for Applications Not Listed in “Open With”


One can use “mimeopen -d file” to invoke an application to open a file in the command line. Afterwards the used application will be the default application associated with the file type, even from the Nautilus.

Example: Set nano as the default program to open *.txt files:

$ mimeopen -d file.txt

Please choose a default application for files of type text/plain

1) notepad (wine-extension-txt)
2) gedit (gedit)
3) GNU Emacs 23 (emacs23)
4) Other…

use application # 4

use command: nano

Opening “useful.txt” with nano (text/plain)