Computing

Matlab

Could you say what is the result of the following operation:
1e15 * sum([-10, 1e-15, 10]) ?
If you gave answer = 1, put the above expression in MATLAB. You will get
approximately 1.78. So, it is almost an error of 80%. To avoid that possible
blunder for ill-conditioned vectors, always sort you data by absolute value
in a descending order before computing a sum. For example,
1e15 * sum([-10, 10, 1e-15]) gives you unity as expected.
Another instructiveexample is
if ( 12345678901234567^3 + 2^3 == 12345678901234568^3 ) disp('be careful with floating-point arithmetic')end

For MATLAB newer than 7.8.* (2009), the multithreading (using more than one
CPU core) is set up automatically. To check the number of processor cores
available in a PC/server, use
feature('NumCores')
Note, that this is an undocumented function (see more details).
And the command
memory
gives you the system memory volume/usage information (MS Windows only).

Use parfor from the Parallel Computing Toolbox to split the for-cycle between
several MATLAB 'workers'. For example, to start a parallel computing session with a
maximum of 2 'working' MATLAB instances (plus one coordinating MATLAB client), use
matlabpool open local 2...parfor i = (1 : N) B(i) = function(A(i))end...matlabpool close
(more info). This is a perfect technique for Monte-Carlo ensemble averages.
See this figure for the performance speed-up on a busy 12-core Intel Xeon cluster ('chiron').

To override the default maximum usable number of CPU cores on the cluster, use the NumWorkers property.
In the example below, we set the maximum to 12 cores (upper limit in MATLAB) and open a parallel session with 4 'workers'
NUM_CORES = 4;
myCluster = parcluster('local');
myCluster.NumWorkers = 12; saveProfile(myCluster);
matlabpool('open', 'local', NUM_CORES);

----------------------
GRAPHICS AND EXPORTING
----------------------

Note that the scaling of an .eps-figure depends on the screen resolution you set
before launching Matlab. A running Matlab session will not adjust automatically
when you alter the screen settings. For example, a reduced screen resolution will
give you a figure with a larger bounding box (effectively reducing the font size).

To save the current figure, as it appears on the screen, to the bitmap-format use
I = getframe(gcf);
imwrite(I.cdata, 'FileName.png');

To extract the data from the plot (e.g. if you forgot to save it with 'save()'
and the variable is no longer in the active workspace), use
hh = get(gca, 'Children');XX = get(hh,'XData'); % or get(hh(1),'XData') if moreYY = get(hh,'YData'); % than one line was plotted
N.B. the first plotted line goes last in hh.

To put a quote character (') in the string (for titles, legends, etc.), use
the twice repeated symbol, e.g. 'Newton''s law'

To draw a point (x,y) in rgb(0,0,0) on an existing figure, use
line('XData',x, 'YData',y, 'LineStyle','none', ... 'Marker','o', 'MarkerSize',7, 'MarkerFaceColor',[0,0,0]);
N.B. x,y can be vectors to draw a set of points.

To draw on an earlier figure after some other have been created use
hFig = figure('Name','MyFigure');...set(0, 'CurrentFigure',hFig); hold on;

To plot with multiple axes in a single figure, e.g. with linear scale on
the first y-axis and logarithmic scale on the second y-axis, use
figure('Name','Double-Axes Example'); hold on; box on;XX = 1:0.1:10; YY1=sin(XX); YY2=exp(XX);plot(XX, YY1, '-k', 'LineWidth',2);hAx1 = gca;hAx2 = axes('Position',get(hAx1,'Position'),... 'XAxisLocation','top', 'XTick',[],... 'YAxisLocation','right',... 'Color','none','XColor','k','YColor','k',... 'YScale','log'); hold on;semilogy(XX, YY2,'--k', 'LineWidth',2, 'Parent',hAx2);xlabel(hAx1, 'X', 'FontSize',16);ylabel(hAx1, 'Y1', 'FontSize',16);ylabel(hAx2, 'Y2', 'FontSize',16);legend(hAx1, {'a'}, 'FontSize',12, 'Location','NorthWest');legend(hAx2, {'b'}, 'FontSize',12, 'Color','w');
If you want to be able to click-edit the line properties plotted in the first axes,
add 'HitTest','off' when creating hAx2.

To set parameters of the figure in legend() use {...} for captions,
e.g. legend({'caption1','caption2'}, 'FontSize',12);

To align the first entry in the figure legendlegend({'line^{index}_1', 'line_2'}),
which contains subscripts/superscripts, apply
[hL,hLL,auxL,auxT] = legend( ... );hText = findobj(hLL, 'type','text');set(hText(end), 'VerticalAlignment','Cap');
where 'Cap' aligns with the Capital letter (try also 'Top').

To save an .eps figure with a transparent background, use
set(gca, 'Color','none');set(gcf, 'Color','none');set(gcf,'InvertHardCopy','off');print -depsc2 Transparent.eps;

If you want to display greek letters in uicontrol, which does not support TeX, use
the ASCII lookup function chart.m:
chart('arial'); % prints out character tablepm_char = char(hex2dec('B1')); % \pm char based on its ascii valuemu_char = char(hex2dec('B5')); % \mu char uicontrol('Style','text', 'String',[pm_char, ' 10 ', mu_char,'m']);
More info.

Starting from MATLAB 2010a, a new option 'index0' will be available for most
of standard array-generating function (zeros(), ones(), diag(), sum(), etc.)
It forces a so-created array to be indexed from 0 instead of 1. This breaks a nearly
three-decades-long tradition of hard-coded indexing from 1, unlike in the
majority of programming languages. See more details first-handedly.
[Update]: this turned out to be a joke...

The second part of 'Callback'-option/value pair is either 'any Matlab code' or
@mySubFunction_Callback, the latter WITHOUT quotes (' '). The respective
GUI m-file subfunction is @mySubFunction_Callback(hObj, event, eventdata).

Be careful with clear Variable; inside the script if the variable under question is global.
It is generally safer to set it to zero. Alternatively, use: clear Variable; global Variable;

You can operate in bulk with a list of variables (e.g. to empty them), like
(LIST_OF_VARIABLES = {'AnArray', 'ACellArray', 'AScalar'};for i = [1 : length(LIST_OF_VARIABLES)] Info = whos(LIST_OF_VARIABLES{i}); if strcmp(Info.class, 'cell') evalc([LIST_OF_VARIABLES{i}, ' = {}']); else evalc([LIST_OF_VARIABLES{i}, ' = []']); endend
however, it is not a recommended practice.

To take the last element of an array that satisfies a logical condition, use
A( find(A == 3, 1,'last') ); % returns 'ans = 3' % for A = [1, 2, 3, 3, 3];

To convert a matrix to LaTeX with a specified number of significant digits, say 3, use
digits(3); A_sym = sym(A, 'd');
latex(A_sym);

Torun a Matlab script in the detached no-GUI mode on a remote server
(say, called 'chiron'), use the screen to emulate a terminal session and
matlab -nodisplay to suppress the graphical support by using the
following command sequence (in a console):
$ ssh username@chiron$ screen$ nice matlab -nodisplay -logfile ~/matlablog.txt -r myscript.m...press <Ctrl>+a, followed by d$ logout chiron
To reconnect to the detached screen session, use
$ ssh username@chiron$ screen -r
and use exit to close the session.

Finally, if you are up to a smile or two, try the following:
spy % plots a ... sparse matrix

why(0) % answers any question

sum * % gives the Answer to the Ultimate Question of Life

Comsol

Unless you have MATLAB installed and COMSOL properly configured to support
their communications, you shall save your model in .mph or .fl binary formats;
otherwise, you are at risk of not being able to open your own COMSOL .m-file.

To run COMSOL in MATLAB environment and 2 COMSOL GUI Desktops (in Linux), use
$ comsol mphserver matlab &$ comsol &$ comsol &
from the same terminal (to avoid checking out multiple licences for the same user).
You also need to ensure that the COMSOL configuration file points to the supported
version of the MATLAB (e.g. add a command-line option -mlroot /usr/local/matlab... or
amend the line in the configuration file: MLROOT=${MLROOT:=/usr/local/matlab...}).

A Java error or crash at an attempt to show a mesh or at a similar 2d/3d graphical
operation in Linux might indicate that you need an OpenGL driver installed. If you
cannot find hardware accelerated OpenGL drivers for your graphics card, you
should use software OpenGL rendering via 'mesa' libraries provided by COMSOL.
In COMSOL 3.5*, use the option -mesa to the start-up script (see also
graphics troubleshooting):
comsol35a -mesa &

To specify a point source use a weak boundary condition: q0 * u_test,
where u=u(x,t) is the name of dependent variable in the equation(s). This is
equivalent, in 1D-geometry, to setting the boundary coefficient g = q0.
In 2D and 3D cases, it is necessary to use Point Settings of a Point
object and the only weak formulation for the boundary condition is available.

A great care is required when drawing geometrical objects in COMSOL. Check
Draw -> Geometric Properties to make sure all points and lines are precisely at
the positions they should be. An error of order 1e-4 is easily introduced when
drawing manually. A good alternative is to define lines using, e.g.
line1 = solid1([0,1]);
pt1 = point1(0.25); pt2 = point1(0.5);
p.objs = {pt1, pt2}; s.objs = {line1};
fem.draw = struct('p',p,'s',s);
fem.geom = geomcsg(fem);
from MATLAB, or using COMSOL GUI menu option Draw -> Specify Objects.
And do not forget to regenerate/reload the mesh.

To set up periodic boundary conditions, go to Physics -> Periodic boundaries...
and select the border (edge) that will be a "source" of the boundary data. Note that the
corresponding vertices should also be carefully matched in the correct order.

For an unknown reason, the analysed geometry with only internal 2D circles/ellipses
(ellip2()) and the one with only internal polygons (line2()) has different indexing
order for the outer borders. For example, if you subtract a polygon and an ellipse
from a rectangular domain ('g_rect2 - g_line2 - g_ellip2') and apply type 1 b.c.
on the outer-rectangle, type 2 on the inner-polygon, and type 3 on the inner-ellipse,
the final indexing will be as follows: (1,1,1, 2,2,...,2, 1, 3,3,3,3).
Be careful and double-check boundary conditions before computing.

To automatically run a series of Studies, e.g. a flow solver, followed by a transport sweep,
use the Study Reference: just add the component to Study 2 (transport sweep) and make it
refer to Study 1 (flow). Now, running the second study, runs the entire simulation sequence.
The Matlab LiveLink scripting is also capable of this or more sophisticated automation.
Alternatively, a build-in scripting tool Model Methods from the Application Builder
could do the job, but it is only available (as of ver. 5.3a) in the Windows distribution.

R

Help search in R:
?plot # for a command?spatstat::Kest # for a package??command # generic search

Press <Ctrl> + L to clear the console screen.

To reset R session, i.e. to close all connections and clear all workspace variables, use
closeAllConnections()rm(list=ls())

Imaging & Graphics

XFig - flexible diagrams

Installation (Ubuntu)
sudo apt-get install xfig gsfonts-x11

You can only type in values in a property field when the mouse pointer is over it.

When exporting a diagram to .png or other bitmap image, do not forget to
select 'some smoothing' or 'more smoothing' option, otherwise you may
end up with a fuzzy picture. You could also set an optional width of blank border.

When unable to position the objects precisely by moving the points (with the default
step of 1/16th inch), switch the Position property (bottom toolbar) to "any"
or use the Edit tool to tweak its coordinates arbitrary.

A very easy way to write any LaTeX symbols and equations inside XFig and then
to get a nice .eps file is to use the fig2eps utility by Marc de Courville and others
(please note that this is a modified version with an extra option to handle
LaTeX fonts; here is the original fig2eps).
The usage is as follows:

Insert any text object into XFig and type any formula you like within $ $,
set the font size to affect scaling (8-12 would be fine for labeling diagrams).

Save the figure, e.g. diagram.fig, and run from the console:
fig2eps diagram.fig
That's it. The result is a neat figure in the file diagram.eps, ready to be
inserted to LaTeX.

If you wish to use a mixture of plain text and formulae in the XFig, the option -times
is recommended (run fig2eps -h for more details).

-------------
InkScape Tips
-------------

To crop an imported image
(i) insert a rectangle on top of the desired area
(ii) Object -> clip -> set
(source)

To change the default transparent to a white background of the document, go to
File -> Document Properties -> Background colour and set Alpha (opacity) to 255.

To crop an image (say, remove 50 px from the top), use
convert -crop +0+50 +repage figure.png figure_cropped.png
see more info and examples.

To convert an .eps-image to .pdf, fitting the output to the bounding box,
use GhostScript Distiller
ps2pdf -dEPSCrop input.eps output.pdf
another useful options to consider: -dPDFSETTINGS=/prepress (or =/print)
for a publishing quality optimised output. See GhostScript Documentation for more details.
Alternatively, you could use
epstopdf input.eps

To convert an .pdf-image to .eps, use GhostScript
pdf2ps -sDEVICE=epswrite input.pdf output.eps
or
pdftops -eps input.pdf output.eps
The latter is of higher quality but might leave extra white space around the image.

To convert an animated .gif to .avi, use ImageMagick and ffmpeg:
convert FILE.gif temp%05d.png
ffmpeg -i temp%05d.png -r 10 -qscale 0 FILE.avi
rm temp*.png
(here -r defines the frame rate in Hz, and -qscale preserves the quality).
To convert to other formats, simply change the extention, e.g. to FILE.mov.
If you do not have ffmpeg installed, you could do it on Ubuntu with
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg
source: ffmpeg usage tips, documentation and installation.

Writing & Presenting

JabRef - BibTeX manager

To import a bibliography file from Firefox directly to JabRef, create
the following executable bash-script (for Linux users), say JabRef:
#!/bin/sh
java -jar /PATH_TO_JabRef/JabRef-2.6.jar --import $(readlink -f $1)
then browse and select this script (or just JabRef.exe itself in MS Windows)
with Open with... in Firefox each time when you encounter a .ris-file or the like.
N.B. Do not forget to activate Preferences --> Advanced --> Remote Operation in JabRef.

You can use the following sources of bibliography entries for importing directly to JabRef:

Publishers (Elsevier, Springer, etc.)
by using the options: Export Citation, Export this article as RIS, and so on;

To change the case of any field to, e.g. First capital only; First Capital In Each Word;
all in lowercase or ALL IN UPPERCASE, right-click in the entry editor
and choose the desired format from the menu Change case.

To push references directly to Kile, using [LyX/Kile] button in JabRef:

Now launch Kile, place the cursor at a desired position in your document, select one or
several references in JabRef, press [LyX/Kile] button and enjoy imported BibTeX keys.

To automatically wrap all capital letters for certain fields in JabRef with { }
(to make sure they are preserved in the LaTeX output), go to menu Options -> Preferences ->
General -> File -> "Store the following fields with braces around capital letters"
and include the desired fields, e.g. title;journal;author.
This setting automatically adds braces when saving the .bib file, but you won't see the
braces within JabRef (from jabref-users mailing-list).

Formatting options for export filters are very flexible. For example, this
\begin{author}\format[Authors(LastFirst,NoPunc,InitialsNoSpace),HTMLChars,Replace(A Name,<strong>A Name</strong>)]{\author}\end{author}
would print an author list in a compact format with the author "A Name" shown in bold.
Source: JabRef mailing list; see more details.

To use the LibreOffice plug-in for literature export, install the java API package:
sudo apt-get install libreoffice-java-common
press Tools --> OpenOffice/LibreOffice Connection, click on [Manual Connect], and set 'path to executable' to
/usr/lib/libreoffice/program/soffice.bin and 'path to library dir' to /usr/lib/libreoffice.

Pdf manipulation with pdftk

If you prefer, you can use a GUI interface for pdftk command-line backend:
PDF Chain (Linux / MacOS), e.g., in Ubuntu
sudo apt-get install pdfchain
and original PDFtk Free/Pro (MS Windows)

To join together two or more pdf files, use
pdftk file1.pdf file2.pdf cat output final.pdf
and to glue many sequentially-numbered files, use
pdftk *.pdf cat output final.pdf
See more PDFtk examples.

To rotate the first page of the file.pdf clockwise to 90 degrees, run the following:
pdftk file.pdf cat 1east 2-end output fileRotated.pdf

To rotate all odd pages to 180 degrees, download pdfrotate script and run
./pdfrotate odd 180 input.pdf output.pdf
(it is based on this script)
Update: the same effect can be achieved by a standard command:
pdftk A=input.pdf shuffle A1-endoddsouth A1-endeven output final.pdf

To shuffle the pages from two pdfs, e.g. one with odd sides and one with reverse-order even sides
(as produced by an automatic scanner), use
pdftk A=odd_pages.pdf B=even_pages.pdf shuffle A1-end Bend-1 output final.pdf

To fix a minor structure corruption in given file.pdf, just execute
pdftk file.pdf output fileFixed.pdf

Lossless PDF compressorsmpdf is availabe from the CPDF toolkit:
smpdf input.pdf -o output.pdf
[Update]: for a newer version of cpdf, use the following syntax instead:
cpdf -squeeze input.pdf -o output.pdf

To batch-encrypt pdf files (128 bit), use
for f in *.pdf; do pdftk $f cat output ${f%.*}-e.pdf owner_pw MasterPass user_pw OpenPass; done
To decrypt and extract the first page, use
pdftk protected.pdf cat 1 output first_page.pdf do_ask
If no (i.e. empty) user pass is set, one can also use qpdf to decrypt the pdf file:
qpdf --decrypt protected.pdf --password="" out.pdf
Please make sure you have valid authority to process the pdf files.

To compare changes in two .tex-files use the following:
latexdiff old.tex new.tex > diff.tex
The perl-script latexdiff doing this is available at CTAN
(sometimes it is necessary to use the script named latexdiff-so instead).

One way to do word & character-count in a TeX file is to apply the ps2ascii
utility to a generated .ps or .pdf as follows:
ps2ascii file.pdf | wc
The output consists of three figures. The first one is the number of lines,
the second is the number of words and the last one is the number of
characters (bytes).

To deal with a hyperref package warning: Token not allowed in a PDFDocEncoded string...,
provide alternative plain text for maths by using \texorpdfstring{$Your Formula$}{Equivalent Text}
in \section{}, \subsection{}, etc. (see also other hyperref problems).

To prevent Adobe PDF reader from errors like "Cannot extract the embedded font...",
add the PDF-specific option -Ppdf to dvips command line (e.g. in Kile/WinEdt settings).
Also, avoid using \usepackage[T1]{fontenc} but use {\fontencoding{T1}...} locally instead.

To make a book/thesis-style PDF-document with discontinuous page-number navigation, like "page 10 (14 of 200)",
ensure the following options are used in\usepackage[...]{hyperref}, NOT in the\hypersetup{...} :
\usepackage[plainpages=false,pdfpagelabels]{hyperref}
More Pdf/LaTeX-related help (see also the UK TeX FAQ and TUG mailist).

To circumvent the LaTeX base warning: Float too big for page... for a Figure/Table that still fits the page, use
the minipage environment with plain-TeX \vss to make LaTeX ignorant of extra height:
\begin{figure}[p] \begin{minipage}[t][\textheight]{\textwidth} \centering \vspace{-1em} % some tweaking \includegraphics{...} \vspace{-0.5em} \caption{...} \label{fig:...} \vss % hides extra height \end{minipage}\end{figure}
and do not forget that \label always go inside or straight after the \caption.
See more on comp.text.tex.

To prevent floats (Figures and Tables) from "floating away" too far from the desired place, or to have
a footnote postponed until the next page, use the \usepackage{afterpage} package, providing a
command \afterpage{ \do_something_after_this_page_ends }. For example,
to force the queueing floats to be placed as soon as this page ends (without breaking it), put
\afterpage{\clearpage}
or, if you need to have a footnote to a Figure/Table that wrongly appears at the previous page, use
\begin{figure} ... \caption{Blah-blah-blah \protect\footnotemark .}\end{figure}\afterpage{ \footnotetext{Some clarification.} }
Note that this method is NOT very robust, particularly if you try to use the command inside the floats.
Here is the package documentation and some more info on managing the floats.

To avoid an extra space after a full stop, like in Latin 'etc.', 'e.g.', 'ca.', 'cf.', ...,
put a backslash just after the full stop:
... e.g.\ we can avoid here an extra space.
See more white space info.

\textstyle command in the display mode switches fonts and spacing
to be a more compact, e.g.
\textsyle\sum e^{\textstyle a/b}
The other LaTeX maths styles are \displaystyle, \scriptstyle and \scriptscriptstyle.

Note that PostScript follow the Reverse Polish Notation, so for some numerical constants a,b,c,d,
c/d + b*exp(-a*x) = x a neg mul EXP b mul c d div add
See The List of PostScript Maths commands, plus extra commands, like EXP, from the package pst-math.
Alternatively, use package pstricks-add, which provides an option
\psset{algebraic=true}
but the package is sensitive to the LaTeX distribution and prone to instabilities.

A curious application to the bar-code generation including 2D Quick-Response code
(see also the '\string~' tip to handle tildes in the url correctly).

To set default file-sorting by ASCII (MC-style), so that -Dir and _File are on top (like in Win & MacOS),
(a) in RedHat/CentOS, create a file $HOME/.i18n and put the following line in it:
LC_COLLATE=C
(b) in Debian/Ubuntu, add the following to $HOME/.profile file:
export LC_COLLATE=C
then relogin or reboot the PC. (source: CentOS, Arch, Ubuntu).

PC/server performance:
check CPU information by using cat /proc/cpuinfo or dmesg | grep CPU
(e.g. cat /proc/cpuinfo | grep processor tells the number of processors/cores);
check RAM-memory by using cat /proc/meminfo (in kB) or free -m (in MB);
check miscellaneous hardware components: cat /etc/sysconfig/hwconf;
check the disc-space usage & capacity of mounted file-systems: df -h (add -T for fs type);
check the number of users in the system finger ;
check the system load by uptime or top
(the load average numbers show how many of the processor cores are busy).

IP / MAC-address and other networking details: /sbin/ifconfig .

To check the error and temperature SMART data for a hard-drive, use
smartctl -a /dev/hda
in Linux (where the required HDD device name can be found via df -h ),
and use a free monitoring tool SpeedFan in MS Windows.

To change the modification date of a file/directory into the format YYYYMMDDhhmm
(e.g. to 2010-03-02, 0:00), use
touch -m -t 201003020000 FILENAME

To combine multiple *.csv files in one, use
cat *.csv > merged.csv

Bulk-renaming the files (reg-ex command requires rename.pl Perl script by Larry Wall):
remove/change a prefix in filename
rename 'old_prefix-' 'new_prefix-' ./*
reformat all the numbers in filenames as 001, 002, ...
./rename.pl 's/([0-9]+)/sprintf("%03d",$1)/e;' ./*
replace all spaces in filenames with '-' (remove 'g' after / to replace only the first occurrence)
./rename.pl 's/\s/-/g' ./*
find and replace ':' with '-' in all filenames for MS Windows compatibility
(a safer version: remove the trailing -n option after a test run)
find . -name '*:*' -exec rename 's/:/-/g' {} -v -n \;
N.B. It is a good practice to copy the files in a dedicated directory and testing it before running a command.
See also a regex reference and an online regex simulator.

To copy/move all files of particular type from multiple directories to a single one, use
find ROOT_DIR -iname "FILETYPE" -exec cp {} TARGET_DIR \; ,
e.g. the following moves recursively all mp3-files from current directory to './global_storage/'
find ./ -iname "*.mp3" -exec mv {} ./global_storage/ \;

To show all files in HOME directory (except the hidden '.files') that have been
modified in the last 24 hours, use
find $HOME \( ! -regex '.*/\..*' \) -type f -mtime 0
-mtime -n means during the last n days

To create a zip archive from a batch of files (or a directory, recursively) use
zip -rTog filename.zip /PATH/*
Note, that you can add -m to delete these files after archivation.

To create an encrypted 7z archive from a directory (preserving all attributes), use
tar cf - DIR | 7z a -si -p DIR.tar.7z
or, without preserving the ownership, and encrypring the file listing header:
7z a -mhe=on -p DIR.7z DIR
Alternatively, you could create a less well-compressed zip-file, using
7z a -p DIR.zip DIR
(Note that an appropriate way to exract files is "7z x FILE").

To install an application, e.g. Midnight Commander, from source (.tar, .tar.gz)
to your home directory (root-level-access to your PC is not needed), use the following:

configure:
./configure --silent --prefix=$HOME/.mc
(here --prefix says where to install, subject to your rights to do so,
and --silent suppresses the auxiliary output)

compile:
make

install:
make install

That is it. The binary file is usually found in bin/ directory (in this case you can
run it as $HOME/.mc/bin/mc). However obvious it may sound, it is better to have
all bits and bobs of a standard procedure ready at hand.

To synchronise the directory modification time to match the latest date of its
content, run the command ./synch_dir PATH_TO_DIR, where
PATH_TO_DIR is the root path to the directory tree to be synchronised
and synch_dir is the following shell script
#!/bin/sh # run for every child directory of $1find $1 -type d | while read path; do # get the latest modified file in the tree $path fname=$(find "$path" -type f -printf "%T+\t%p\n" | sort -n | tail -1 | cut -f2); # set the modif. date of $path to match the attribute of $fname touch -m -c -r "$fname" "$path";done
(based on tip 1, tip 2 and tip 3)

To change access rights to all files and directories recursively, e.g. to be readable and browsable to others, use
chmod -R u=rwX,g=rX,o=rX ./*

To prevent accidental deletion of content created by others in a shared directory, use a 'sticky bit':
chmod +t ./SHARED

To compare two text-files, use diff --side-by-side File1 File2
(a more advanced alternative is to use IDE like Eclipse).

To automatically restore applications running in Gnome 3 after logging out, run
gnome-session-properties (e.g. with Alt + F2) and select
Options --> Automatically remember running applications...
Note however that this could lead to some instability.

If there is some mix-up with default application associations, have a look in
~/.local/share/applications/mimeapps.list.

To add a shell script (or custom application) to the list of "Open with...",
create a new MyApp.desktop in ~/.local/share/applications/ with the following content:
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/PATH_TO_APP/MyApp.sh %f
Name=MyApp
Icon=/PATH_TO_APP/MyApp-icon.png
To permanently associate file-type with an App, right-click on it and then select
properties -> open with -> set as default. (see also .desktop format specification)

To sort folders before files in Gnome 3.12+, run the following in the terminal:
gsettings set org.gnome.nautilus.preferences sort-directories-first truegsettings set org.gtk.Settings.FileChooser sort-directories-first true
(similar effect can be done via GUI dconf editor; source).

==== Remote Access Tweaks and Settings ====
To open a remote Linux shell in a panel of Midnight Commander via ssh, use Shell link,
where you enter server hostname (e.g. 'granby'), or the full path to the remote machine.

To protect a remotely running SSH process from termination, use nohup:
$ ssh username@remote-server$ nohup my_command > my_command.log 2>&1 &$ exit
which outputs 'my_command' stdin and stderr to 'my_command.log'. An alternative is to use disown:
$ my_command > my_command.log 2>&1 & # script or GUI$ disown -a && exit
(see this reference more details).
However, a still better and more flexible way is to use a virtual terminal such as screen:
see an example of using screen to detach/re-attach a remotely running Malab script.

Firefox

To re-enable a stand-alone Preferences Dialogue in Firefox 38+, type in about:config in the address field and set
browser.preferences.inContent = falsebrowser.preferences.instantApply = false

To open pdf-documents with a stand-alone application instead of loading to the Firefox tab
about:config -> New -> String -> plugin.disable_full_page_plugin_for_types = application/pdf

To switch off the irritating "smart" search in the address bar of Firefox 3, use
about:config -> browser.urlbar.matchOnlyTyped = False

To turn off the compatibility check of add-ons, you can create a new property set
about:config -> New -> Boolean -> extensions.checkCompatibility.3.6 = False
(where 3.6 is the first two numbers of Firefox's version).
A better way, however, is to install a Compatibility Reporter that does this automatically for you.

If something is wrong with Firefox, you can create and launch a temporary blank new profile by typing (from the command line)
firefox -ProfileManager (or firefox -P) and then hitting the [Create Profile...] button

Use firefox -no-remote to run a new firefox instance rather than opening another window to existing process.

To get rid of the star next to the email address in Thunderbird 3.-, add .emailStar {display: none}
to the /chrome/userChrome.rss which has to be put in the user profile (e.g. ~/.thunderbird/***.default/ in Linux).

More tweaks and hacks for toolbar/menu items can be done with DOM Inspector add-on.

Either locate an element with 'find a node' button (top-left) or browse the layout
structure (e.g. #document/window/menuPopUp(mailContext) to configure right-click menu)

to hide the menu-item, add hidden="true" to the right-hand-side 'Attributes' panel

you can move a menu-item/button around by copy-cutting its node across the document tree.

To set a maximal number of recent folders in MoveTo->Recent menu, install the following add-on chrome.xpi
(first setting extensions.alwaysUnpack to true in the Settings->Advanced->Config Editor)
and then follow the instructions.

To clear the list of Recent folders in "Move to" and "Copy to", remove the file panacea.dat from the main Thunderbird profile directory (source).