The following script allows for GUI popup display for Ubuntu and the likes:
#!/bin/bash
# basic script to display a GUI popup box
# requires libnotify-bin (for command notify-send)
notify-send -t 4000 "Take a look at the console !" $(eval pwd)"\n"`date +%Y/%m/%d-%H:%M:%S`
Thursday, December 24, 2015
Thursday, December 10, 2015
c++ change pointer passed as argument
To change the pointer passed in argument you need something like this:
void foo(int **ptr) //pointer to pointer
{
*ptr = new int[10]; //just for example, use RAII in a real world
}
orvoid bar(int *& ptr) //reference to pointer (a bit confusing look)
{
ptr = new int[10];
}
Original thread: http://stackoverflow.com/questions/11842416/function-does-not-change-passed-pointer-c
C++ headers and sources, templates
Original thread: http://stackoverflow.com/questions/23962044/multiple-definition-of-first-defined-here-in-the-same-line-in-a-data-struc
If I understand you correctly, you are doing things like this:
There is one special case where this is allowed, and that's when
Incidentally, the reason things work when you move the function bodies inside the class definition is because that has the effect of making them implicitly inline.
If I understand you correctly, you are doing things like this:
// C.h
class C
{
void f(); // declaration of f; ok to include in many modules
};
// definition of f; must not exist in more than one module
void C::f()
{
}
That doesn't work because the definition of f()
will
wind up in every module that includes C.h, leading to exactly the linker
error you describe. You can fix this by either marking f()
as inline
, or by moving the definition of f()
to a separate cpp file.There is one special case where this is allowed, and that's when
f()
is a template (either directly or because C
is a template). In that case, the definition must
be in the header so the compiler can know how to instantiate it for
whatever type(s) you specify. This does make life difficult for the
linker since you can and often do end up with the sorts of redundant
definitions that would normally be errors (e.g if you use f()
in more than one module). Special behavior is needed to handle this.Incidentally, the reason things work when you move the function bodies inside the class definition is because that has the effect of making them implicitly inline.
Friday, November 27, 2015
git graphical diff
One can use the "git difftool" command, which has direct knowledge of many diffing tools, including meld.
By default it always asks for which diffing tool to use (and defaults to 'meld' on my box), but you can automate the choice with configuration variables. See "git help difftool" for details.
Src: http://blog.deadlypenguin.com/blog/2011/05/03/using-meld-with-git-diff/
see "comments" sections
By default it always asks for which diffing tool to use (and defaults to 'meld' on my box), but you can automate the choice with configuration variables. See "git help difftool" for details.
Src: http://blog.deadlypenguin.com/blog/2011/05/03/using-meld-with-git-diff/
see "comments" sections
Wednesday, November 25, 2015
CUDA_VISIBLE_DEVICES – Masking GPUs
Src: http://acceleware.com/blog/cudavisibledevices-masking-gpus
Does your CUDA application need to target a specific GPU? If you are writing GPU enabled code, you would typically use a device query to select the desired GPUs. However, a quick and easy solution for testing is to use the environment variable CUDA_VISIBLE_DEVICES to restrict the devices that your CUDA application sees. This can be useful if you are attempting to share resources on a node or you want your GPU enabled executable to target a specific GPU.
CUDA will enumerate the visible devices starting
at zero. In the last case, devices 0, 2, 3 will appear as devices 0, 1,
2. If you change the order of the string to “2,3,0”, devices 2,3,0 will
be enumerated as 0,1,2 respectively. If
To determine the device ID for the available hardware in your system, you can run NVIDIA’s deviceQuery executable included in the CUDA SDK. Happy programming!
Does your CUDA application need to target a specific GPU? If you are writing GPU enabled code, you would typically use a device query to select the desired GPUs. However, a quick and easy solution for testing is to use the environment variable CUDA_VISIBLE_DEVICES to restrict the devices that your CUDA application sees. This can be useful if you are attempting to share resources on a node or you want your GPU enabled executable to target a specific GPU.
Environment Variable Syntax | Results |
---|---|
CUDA_VISIBLE_DEVICES=1 | Only device 1 will be seen |
CUDA_VISIBLE_DEVICES=0,1 | Devices 0 and 1 will be visible |
CUDA_VISIBLE_DEVICES=”0,1” | Same as above, quotation marks are optional |
CUDA_VISIBLE_DEVICES=0,2,3 | Devices 0, 2, 3 will be visible; device 1 is masked |
CUDA_VISIBLE_DEVICES
is set to a device that does not exist, all devices will be masked. You
can specify a mix of valid and invalid device numbers. All devices
before the invalid value will be enumerated, while all devices after the
invalid value will be masked.To determine the device ID for the available hardware in your system, you can run NVIDIA’s deviceQuery executable included in the CUDA SDK. Happy programming!
Monday, November 23, 2015
Nvidia Visual Profiler (NVVP) version 7.5 crashes on new session on Ubuntu
Original thread: http://stackoverflow.com/questions/26436009/eclipse-luna-crashes-on-new-project-in-ubuntu
Extracted Solution:
According to comment 20 in this bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=440660#c20
Extracted Solution:
According to comment 20 in this bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=440660#c20
This seems to be a bug in GTK according to https://bugs.launchpad.net/ubuntu/+source/gtk2-engines-oxygen/+bug/1242801 (there a similar problem for Meld was reported).
Another workaround mentioned there is for Oxygen, edit the normally already existing file/usr/share/themes/oxygen-gtk/gtk-2.0/gtkrc
and change
into`GtkComboBox::appears-as-list = 1`
This workaround is working for me.`GtkComboBox::appears-as-list = 0`
Tuesday, November 3, 2015
LD cannot find library because of version numbering
It is Debian convention to separate shared libraries into their runtime components (
Because the library's soname is
However, because the library is specified as
See Diego E. Pettenò: Linkers and names for details on how this all works on Linux.
In short, you should
This will not only give you
src: http://stackoverflow.com/questions/335928/ld-cannot-find-an-existing-library
libmagic1: /usr/lib/libmagic.so.1 → libmagic.so.1.0.0
) and their development components (libmagic-dev: /usr/lib/libmagic.so → …
).Because the library's soname is
libmagic.so.1
, that's the string that gets embedded into the executable so that's the file that is loaded when the executable is run.However, because the library is specified as
-lmagic
to the linker, it looks for libmagic.so
, which is why it is needed for development.See Diego E. Pettenò: Linkers and names for details on how this all works on Linux.
In short, you should
apt-get install libmagic-dev
.This will not only give you
libmagic.so
but also other files necessary for compiling like /usr/include/magic.h
.src: http://stackoverflow.com/questions/335928/ld-cannot-find-an-existing-library
Thursday, September 10, 2015
How to install Skype on Kubuntu 14.04
open muon
if you are in muon discover go to "sources">"configure sources"
check all on the Kubuntu software tab
then click the "other software"tab and make sure "canonical partners" is checked.
close muon
and back at the konsole:
if you are in muon discover go to "sources">"configure sources"
check all on the Kubuntu software tab
then click the "other software"tab and make sure "canonical partners" is checked.
close muon
and back at the konsole:
sudo apt-get update
sudo apt-get install skype
Src: http://community.skype.com/t5/Linux-archive/How-to-install-Skype-for-Kubuntu-14-04/td-p/3602591
Wednesday, August 19, 2015
Imagemagick in bash, resize images
The following command will resize an image to a height of 100:
convert example.png -resize x100 example.pngSrc: http://www.howtogeek.com/109369/how-to-quickly-resize-convert-modify-images-from-the-linux-terminal/
Tuesday, August 4, 2015
Latex Temporarily disable superscript in citation
The following example changes
\setcitestyle
locally and puts it in macro \citen
.
\setcitestyle
of package natbib
(2010/09/13
8.31b) contains a space right at the beginning of the macro definition
by an uncommented end of line, the trick with \romannumeral
removes this space.\documentclass{article}
\usepackage[square]{natbib}
\setcitestyle{super}
\newcommand*{\citen}[1]{%
\begingroup
\romannumeral-`\x % remove space at the beginning of \setcitestyle
\setcitestyle{numbers}%
\cite{#1}%
\endgroup
}
\begin{document}
Package \textsf{accsupp}\cite{oberdiek:accsupp}.
This figure is reproduce from reference~\citen{oberdiek:zref}.
\bibliographystyle{plainnat}
\raggedright
\bibliography{oberdiek-bundle}
\end{document}
Inside moving arguments (e.g.,
\caption
) macro \citen
can be protected using \protect
or by using \DeclareRobustCommand
for the definition:\newcommand*{\citen}{}% generate error, if `\citen` is already in use
\DeclareRobustCommand*{\citen}[1]{%
\begingroup
\romannumeral-`\x % remove space at the beginning of \setcitestyle
\setcitestyle{numbers}%
\cite{#1}%
\endgroup
}
Source: http://tex.stackexchange.com/questions/94178/temporarily-disable-superscript-in-citation
Friday, July 24, 2015
bash split pdf
$ sudo apt-get update$ sudo apt-get install pdftk
EDIT: since pdftk became deprecated, do:
sudo snap install pdftk
Then, to make a new pdf with just pages 1, 2, 4, and 5 from the old pdf, do this:
$ pdftk myoldfile.pdf cat 1 2 4 5 output mynewfile.pdfNote that cat and output are special pdftk keywords. cat specifies the operation to perform on the input file. output signals that what follows is the name of the output pdf file.
You can specify page ranges like this:
$ pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdf
http://linuxcommando.blogspot.ca/2013/02/splitting-up-is-easy-for-pdf-file.html
Find LaTeX multiply-defined labels
perl -nE 'say $1 if /(\\label[^}]*})/' *.tex | sort | uniq -c | sort -n
http://www.mawode.com/blog/blog/2012/03/21/finding-duplicate-latex-labels/
Thursday, July 9, 2015
MATLAB uniform ticks (uniformticks) and printing
The following script can make the axes nicer. Example:
%% render uniform ticks digits on Y axis
function uniformticks_y(deci) ; % input number of decimals as string
command = ['%0.' mat2str(deci) 'f|'] ;
ticks = get(gca, 'Ytick') ;
set(gca, 'YTickLabel', sprintf(command, ticks));
However, changing the graph manually in the GUI can upset the nice axes settings. Simply rerun the script from the console without closing the graphs.
%% render uniform ticks digits on Y axis
function uniformticks_y(deci) ; % input number of decimals as string
command = ['%0.' mat2str(deci) 'f|'] ;
ticks = get(gca, 'Ytick') ;
set(gca, 'YTickLabel', sprintf(command, ticks));
However, changing the graph manually in the GUI can upset the nice axes settings. Simply rerun the script from the console without closing the graphs.
Monday, June 22, 2015
convert graph image to text data
To convert a screenshot, photo or scan of a graph or plot to a text data table, use this software:
Engauge Digitizer
http://sourceforge.net/projects/digitizer/?source=navbar
bash copy a directory recursively, excluding some directory or file name
rsync -av --progress sourcefolder /destinationfolder --exclude thefilenametoexclude
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
NOTE: if the filename or directory appear multiple times, they will be excluded multiple times
Src:http://stackoverflow.com/questions/4585929/how-to-use-cp-command-to-exclude-a-specific-directory
Sunday, May 24, 2015
Latex / Bibtex rename Bibliography / references section when using babel
\addto\captionsenglish{\renewcommand{\refname}{Newname}} %% for babel
Monday, May 11, 2015
Kubuntu 12.04 wifi before logon
Check both boxes in network manger to get wifi running before login:
connect automatically & system connection
connect automatically & system connection
bash config files
For this task, you don't have to write fat parser routines (unless you
want it 100% secure or you want a special file syntax) - you can use
Bash's source command. The file to be sourced should be formated in
key="value" format, otherwise bash will try to interpret commands:
Src/more: http://wiki.bash-hackers.org/howto/conffile
#!/bin/bash echo "Reading config...." >&2 source /etc/cool.cfg echo "Config for the username: $cool_username" >&2 echo "Config for the target host: $cool_host" >&2So, where do these variables come from? If everything works fine, they are defined in /etc/cool.cfg which is a file that's sourced into the current script or shell. Note that this is not the same as executing this file as a script! The sourced file most likely contains something like:
cool_username="guest" cool_host="foo.example.com"These are normal statements understood by Bash, nothing special to do. Of course (and that is a big disadvantage under normal circumstances) the sourced file can contain everything that Bash understands, including evil code!
Src/more: http://wiki.bash-hackers.org/howto/conffile
Wednesday, May 6, 2015
Subversion 1.7 on Ubuntu 12.04
there’s an official Subversion PPA on Launchpad, so for Ubuntu 12.04 all you have to do is add the following couple lines to your
To configure APT to trust this repository's signing key, run script from the page
https://launchpad.net/~svn/+archive/ubuntu/ppa
And upgrade Subversion to its latest version with apt-get:
/etc/apt/sources.list
file:
deb http://ppa.launchpad.net/svn/ppa/ubuntu precise main deb-src http://ppa.launchpad.net/svn/ppa/ubuntu precise main
To configure APT to trust this repository's signing key, run script from the page
https://launchpad.net/~svn/+archive/ubuntu/ppa
And upgrade Subversion to its latest version with apt-get:
sudo apt-get update sudo apt-get install subversion
Source: https://kovshenin.com/2013/subversion-1-7-on-ubuntu-12-04/
Thursday, April 30, 2015
Obtain the number of CPUs / cores in Linux / bash
grep -c ^processor /proc/cpuinfo
Src:http://stackoverflow.com/questions/6481005/obtain-the-number-of-cpus-cores-in-linux
Monday, April 27, 2015
Inkscape - change the color of markers
How do I change the color of markers (e.g., arrow ends)?
By default, markers are black. You can change their color to match the color of the stroke of the object they are applied to by enabling an effect: Extensions > Modify Path > Color Markers to Match Stroke.http://wiki.inkscape.org/wiki/index.php/Frequently_asked_questions#How_do_I_change_the_color_of_markers_.28e.g..2C_arrow_ends.29.3F
Tuesday, March 31, 2015
Adding alpha (transparent) background to jpeg images, logos
- Some posters, powerpoints, have non-white backgrounds. Company logos with transparency look nicer on these. However, sometimes logos are only available in the jpeg format.
- Tools like GIMP/KolourPaint will easily flood-fill the white as alpha, except for the closed figures like "O,e" letters. This can be done by hand, than the result saved as png with alpha channel.
- However, jpeg images are full of shades of white, so the result can be very messy sometimes.
- Solution: use advanced software such as ImageJ, to change the contrast so any intensity value say, above 250/255, will be brought to 255. Then automatic flood-fill of the other software programs will be a lot more efficient.
Note: as of 03/2015, ImageJ does not natively support the alpha channel, so other paint software is still required to finish the job.
- Tools like GIMP/KolourPaint will easily flood-fill the white as alpha, except for the closed figures like "O,e" letters. This can be done by hand, than the result saved as png with alpha channel.
- However, jpeg images are full of shades of white, so the result can be very messy sometimes.
- Solution: use advanced software such as ImageJ, to change the contrast so any intensity value say, above 250/255, will be brought to 255. Then automatic flood-fill of the other software programs will be a lot more efficient.
Note: as of 03/2015, ImageJ does not natively support the alpha channel, so other paint software is still required to finish the job.
Friday, March 20, 2015
bash merge multiple pdf files
A) Using mutool
apt-get install mupdf-tools
mutool merge [options] file1 [pages] file2 [pages] ...
Options:
- -o output
- The output filename.
- -O options
- See mutool create for details on this option.
- Source: https://mupdf.com/docs/manual-mutool-merge.html
B) Using pdfunite. If needed, install poppler package
example uses:
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
pdfunite *.pdf out.pdf
Src:http://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Friday, March 13, 2015
bibtex medphys aapm enquote error
- when using the custom home-brew style medphys.bst
- after pasting the pre-compiled bibliography
- if the compilation crashes and says, \enqoute() already defined,
- you simply forgot to comment out \bibliographystyle(medphys)
- after pasting the pre-compiled bibliography
- if the compilation crashes and says, \enqoute() already defined,
- you simply forgot to comment out \bibliographystyle(medphys)
Saturday, March 7, 2015
convert bunch of images to video using ffmpeg
sample code:
avconv -framerate 7 -i img%03d.png -qscale 1 -c:v libx264 -pix_fmt yuv420p out.mp4
-use avconv, cause ffmpeg command is deprecated
-framerate is the desired visual result in fps units, can be a fraction like 1/5
-i is the regexp to retrieve pics
-qscale is quality: 1 for best, 31 for worst
-c:v is the video codec
-pix_fmt is the color space setting, yuv240p is the most portable
NOTE: the order of the arguments is important: some come before -i, some after -i
Src: https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
keywords: video, mpg, mpeg, mp4, movie, film
avconv -framerate 7 -i img%03d.png -qscale 1 -c:v libx264 -pix_fmt yuv420p out.mp4
-use avconv, cause ffmpeg command is deprecated
-framerate is the desired visual result in fps units, can be a fraction like 1/5
-i is the regexp to retrieve pics
-qscale is quality: 1 for best, 31 for worst
-c:v is the video codec
-pix_fmt is the color space setting, yuv240p is the most portable
NOTE: the order of the arguments is important: some come before -i, some after -i
Src: https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
keywords: video, mpg, mpeg, mp4, movie, film
install ffmpeg video tool
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-extra-53
sudo apt-get install libavcodec-extra57
Src: http://ubuntuforums.org/showthread.php?t=200562
keywords: video, mpg, mpeg, mp4, movie, film
sudo apt-get install libavcodec-extra57
Src: http://ubuntuforums.org/showthread.php?t=200562
keywords: video, mpg, mpeg, mp4, movie, film
Tuesday, February 24, 2015
makebst \enquote command error
The makebst program can crete custom commands within .bbl files.
If such a command, like \enquote{} is giving a compilation error,
try to delete the temporary (non-source) files and recompile the .tex
If such a command, like \enquote{} is giving a compilation error,
try to delete the temporary (non-source) files and recompile the .tex
Monday, February 23, 2015
SVN diff
The difference between working copy and
There are three versions being discussed:
HEAD
; the changes which would need to be made to what is now in the repository (HEAD
), to produce your working copy:svn diff -r HEAD --old=
Of possible interest, the difference between BASE
and HEAD
; changes that have been checked into the repository since you last updated working copy:svn diff -r BASE:HEAD
And of course the difference between BASE
and working copy; the changes you have made since you last updated working copy:svn diff
There are three versions being discussed:
BASE
, working copy, and HEAD
.BASE
:
as last checked out / updated. What working copy would revert to after usingsvn revert
- working copy: local modifications to
which has been checked out / updated as recently asBASE
HEAD
: latest modifications in repository. Equivalent toBASE
iff no changes have been committed since
was checked out / updated as working copy.
Wednesday, February 18, 2015
Tuesday, February 17, 2015
Bash set variable to command output
In addition to the backticks, you can use
Quoting (
Src: http://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output-from-a-command
$()
, which I find easier to read, and allows for nesting.
OUTPUT="$(ls -1)"
echo "${OUTPUT}"
Quoting (
"
) does matter to preserve multi-line values.Src: http://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output-from-a-command
Matlab new page size scraps plot axis markers
-Run a script to generate only one plot
-Change page size in print preview / export setup
-Run the uniformticks script (x-axis shown here):
%% render uniform ticks digits on X axis
% input: number of decimals after decimal point
function uniformticks_x(deci) ;
command = ['%0.' mat2str(deci) 'f|'] ;
ticks = get(gca, 'Xtick') ;
set(gca, 'XTickLabel', sprintf(command, ticks));
-Change page size in print preview / export setup
-Run the uniformticks script (x-axis shown here):
%% render uniform ticks digits on X axis
% input: number of decimals after decimal point
function uniformticks_x(deci) ;
command = ['%0.' mat2str(deci) 'f|'] ;
ticks = get(gca, 'Xtick') ;
set(gca, 'XTickLabel', sprintf(command, ticks));
Ubuntu Matlab Plot Fonts
That was the elusive information we needed: I looked at my 11.04 that
worked (I was the OP on the other thread) and compared font paths. What
you need to install is:
xfonts-100dpi and
xfonts-75dpi
logout and log back in again and you should be away laughing! (worked for me on a fresh install)
Src: http://ubuntuforums.org/showthread.php?t=1762805
xfonts-100dpi and
xfonts-75dpi
logout and log back in again and you should be away laughing! (worked for me on a fresh install)
Src: http://ubuntuforums.org/showthread.php?t=1762805
Wednesday, February 4, 2015
bash: Simple way to move files only from one location to another
In the case you have many files to move, and your folder tree has nothing special, use
mv ./*.* destination_path
This will also move directories containing a dot in the name and will ignore files without extensions...quick hack
mv ./*.* destination_path
This will also move directories containing a dot in the name and will ignore files without extensions...quick hack
Thursday, January 29, 2015
UNIX Local machine MAC address
$ ifconfig
look for the entry for HWaddr,
6 groups of 2 hex characters
look for the entry for HWaddr,
6 groups of 2 hex characters
Monday, January 26, 2015
ubuntu teamviewer black screen after unlock
In case after an unlock, the screen keeps dimming to black ...
Radical solution: System settings, Display, screensaver, disable sreensaver.
"May work" solution:
simply go to System settings, Display, screensaver, click anywhere in the application and exit. This will somehow update the config files and prevent further blinking during this session.
also, try to change the connection settings on the "controlling" machine:
tick "enable black screen if partner input is deactivated"
Radical solution: System settings, Display, screensaver, disable sreensaver.
"May work" solution:
simply go to System settings, Display, screensaver, click anywhere in the application and exit. This will somehow update the config files and prevent further blinking during this session.
also, try to change the connection settings on the "controlling" machine:
tick "enable black screen if partner input is deactivated"
Monday, January 12, 2015
LaTeX Labels for figures
When a label is declared within a float environment, the
\ref{...}
will return the respective fig/table number, but it must occur after
the caption. When declared outside, it will give the section number. To
be completely safe, the label for any picture or table can go within
the \caption{}
command, as in\caption{Close-up of a gull\label{fig:gull}}
Source: http://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing
Saturday, January 10, 2015
update Adobe Flash Player in Kubuntu
You should just install the latest version from the Ubuntu
repositories. It is a lot easier and normally they keep this one
up-to-date with new Linux Flash releases.
To install it run the command
To install it run the command
sudo apt-get install flashplugin-installer
Src: http://askubuntu.com/questions/463295/how-to-update-adobe-flash-player-in-kubuntu-latest-update
Subscribe to:
Posts (Atom)