Wednesday, October 23, 2013

Good techniques for understanding someone else's code

When working with production code the first thing that I always do is to get the current code built and working - and verify that it is as per the production system.
Always aim to understand the minimum possible, and assume that the rest of the code is working as it should (even if it isn't - it's the mental process that is important).
Try to understand the big stuff first - how each part of the code hangs together and what is being achieved at a high level, then work downwards.
A large sheet of paper and a pack of 10cm^2 post-it notes always help me along. Each post-it is a component of the system, and I can move them to aid understanding.

(http://stackoverflow.com/questions/246546/good-techniques-for-understanding-someone-elses-code)

KDE application window settings

Auto stretch ?
KDE Forums / Windows auto-resize width : http://forum.kde.org/viewtopic.php?f=66&t=97839
Window rules
  • Configure settings specifically for a window
System Settings > Window Behavior > Window Rules
Special Window/Application Settings
Right click the window border > Advanced > Special Window/Application Settings > Size & Position
Size - Remember



enter image description here

(http://askubuntu.com/questions/103358/how-can-i-get-kubuntu-to-respect-previous-window-sizes)




































Tuesday, October 15, 2013

Doxygen on Ubuntu 12.04

Doxygen [almost full functionality] install on Ubuntu/Kubuntu 12.04

(let's suppose build-essential, texlive packages are installed)

install dependencies (for some reason it didn't work on a single line):

  sudo apt-get install flex
  sudo apt-get install bison 

get libiconv at
http://www.gnu.org/software/libiconv

install it
  sudo ./configure --prefix=/usr/local
  sudo make
  sudo make install

The manually compiled libiconv must be visible at execution time,
so modify your console profile (ex: ~/.bashrc) to to see the lib:

  export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

install Qt4 (5 not yet supported by Doxygen as of now)

  sudo apt-get install qt4-dev-tools qt4-designer
 
Download doxygen sources to a temp directory. Configure the Doxygen installation from the temp directory


 sudo ./configure --with-doxywizard
 
Attempt to compile the sources:
 
sudo make

This will probably fail, but in the process, the file Makefile.doxygen will be created. Modify this makefile:


  sudo favorite_editor ~/temp/doxygen-1.8.5/src/Makefile.doxygen

at line

  LIBS    =    -L../lib -ldoxygen -ldoxycfg -lqtools -lmd5 -lpthread -liconv


that -liconv is there, if not, add it.

Finish with installation:

  sudo make
  sudo make install
 
Generate doc if desired

  make pdf


Wednesday, October 9, 2013

SVN basic merging

http://svnbook.red-bean.com/en/1.7/svn.branchmerge.basicmerging.html

Thursday, September 19, 2013

ImageJ downscale image or stack

Downscaling a stack, to exactly N/M (ex: 256/2) in each axis, in float precision,

to get the closest result to the average value of a group of voxels,

select BOTH bilinear interpolation AND average (tick on) !

Sunday, September 8, 2013

Switch between nvidia GPUs for display via X settings, if bios doesn't have switching options

You might want to reserve a specific GPU for computing. This might be your "default" display GPU :(

If the Bios options allow you to select a GPU for display, that's your preferred option. If the bios does not offer this option, here is a hack, for screens with multiple I/O ports, or if you have multiple screens at hand:

- with computer off, wire the less preferred cable to the default GPU.

- Boot and shutdown, to make sure this default display layout works and config file xorg.conf is updated.

- boot

- create a backup copy of /etc/X11/xorg.conf

- turn off computer

- plug the preferred cable into the preferred GPU (aka new wiring), while the original wiring for the original display layout is left unchanged


- boot up in graphics mode

- $ sudo nvidia-settings

- Go to X Server Display Configuration

- click icon of disabled monitor (its the one you newly wired). Tip: each connected I/O cable is seen as an original monitor, even wired to 1 physical monitor

- in "Configuration", select "Separate X screen"

- reboot; now the new wiring services a slave X screen

- $ sudo favorite_editor /etc/X11/xorg.conf

- and edit the "Server Layout" to mimic the layout you had before (refer to backup), with new device and screen pointers.

The catch: now all the booting info goes thru the old wiring until xorg.conf is retrieved and its settings enforced. The old wiring may be kept in place, so you switch inputs and peek at the boot info.

Saturday, September 7, 2013

KDE (kubuntu 12.04) some settings cannont be enabled

check if some files /home/username/.kde/share/config/ are owned by root instead of username, ex: systemsettingsrc, kxkbrc

Thursday, September 5, 2013

KDE desktop panel restart

killall plasma-desktop
plasma-desktop
 (http://ubuntuforums.org/showthread.php?t=1264937)

Wednesday, September 4, 2013

Touchpad control under KDE linux

  1. install kde-config-touchpad package.
  2. Run Utilities->Touchpad Management and the application will have the option in GUI. (http://askubuntu.com/questions/46299/how-to-disable-touchpad-tapping-when-typing-on-keyboard)
 NOTE:
might not run properly from GUI.

In my case: $ sudo synaptiks did the job.

How to Set Emacs's User Interface to Modern Conventions

http://ergoemacs.org/emacs/emacs_make_modern.html

Monday, September 2, 2013

Linux OS freezes


If it locks up completely, you can REISUB it, which is a safer alternative to just cold rebooting the computer.
REISUB by:
While holding Alt and the SysReq (Print Screen) keys, type REISUB.
R:  Switch to XLATE mode
E:  Send Terminate signal to all processes except for init
I:  Send Kill signal to all processes except for init
S:  Sync all mounted file-systems
U:  Remount file-systems as read-only
B:  Reboot
REISUB is BUSIER backwards, as in "The System is busier than it should be", if you need to remember it. Or mnemonically - R eboot; E ven; I f; S ystem; U tterly; B roken.

* In the event you're forced to do this, do it slowly. Let a few seconds pass in between each keypress so that the commands you're invoking have a chance to finish before you go to the next one.

http://askubuntu.com/questions/4408/what-should-i-do-when-ubuntu-freezes/36717#36717 

Saturday, August 31, 2013

graphical / visual disk map

https://apps.ubuntu.com/cat/applications/oneiric/gdmap/

Friday, August 30, 2013

CUDA 5.5 on optimus laptop with ubuntu 12.04 LTS

Install a pristine Ubunto distro (check tutorials)

Get make and gcc
4 sudo apt-get install build-essential

Check version
7 gcc –version

Check nvidia card present
8 lspci | grep -i nvidia

Stop X server
9 sudo service kdm stop
Remove current nvidia drivers
19 sudo apt-get --purge remove nvidia-current

Get xorg tools
20 sudo apt-add-repository ppa:xorg-edgers/ppa
21 sudo apt-get update

Get bumblebee
22 sudo apt-get install bumblebee-nvidia nvidia-319 nvidia-settings-319
23 sudo apt-add-repository ppa:bumblebee/stable
24 sudo apt-get update
25 sudo apt-get install bumblebee virtualgl linux-headers-generic

Remove nvidia-current which came with bumblebee
28 sudo apt-get --purge remove nvidia-current

Install nvidia-319 (automatically gave me 325 after all...)
29 sudo apt-get install nvidia-319 nividia-settings-319

Modify /etc/bumblebee/bumblebee.conf to replace “nvidia-current” with “nvidia-325”
sudo nano /etc/bumblebee/bumblebee.conf

Make changes valid
36 sudo reboot

Check success:
40 optirun nvidia-settings -c :8
41 locate xorg.conf

Install CUDA toolkit
43 sudo service kdm stop
44 cd Downloads/
45 l
Here, tell cuda NOT to install the driver
46 sudo sh cuda_5.5.22_linux_64.run

Add paths to .bashrc
48 nano .bashrc

Validate:
49 sudo reboot

Check how it works (did not install OpenGL et al., I dont use them)
50 cd NVIDIA_CUDA-5.5_Samples/
54 cd 1_Utilities/
56 cd deviceQuery
58 make
64 optirun ./deviceQuery

How to change the default GCC compiler in Ubuntu?

As @Tommy suggested, you should use update-alternatives.
It assigns values to every software of a family, so that it defines the order in which the applications will be called.
It is used to maintain different versions of the same software on a system. In your case, you will be able to use several declinations of gcc, and one will be favoured.
To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:
update-alternatives --query gcc
Now, note the priority attributed to gcc-4.4 because you'll need to give a higher one to gcc-3.3.
To set your alternatives, you should have something like this (assuming you gcc installation is located at /usr/bin/gcc-3.3, and gcc-4.4's priority is less than 50):
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 50
--edit--
Finally, you can also use the interactive interface of update-alternatives to easily switch between versions. Type update-alternatives --config gcc to be asked to choose the gcc version you want to use among those installed.
--edit 2 --
Now, to fix the CXX environment variable systemwide, you need to put the line indicated by @DipSwitch's in your .bashrc file (this will apply the change only for your user, which is safer in my opinion):
echo 'export CXX=/usr/bin/gcc-3.3' >> ~/.bashrc
 
http://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu 

Brother printer on Ubuntu Linux

Brother support page
http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/evaluation.html

for HL-2240D you need "Printer Driver (lpr driver and cupswrapper driver)"

Lpr driver instructions
http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/instruction_prn3.html

- complete prerequisites
- install
-configure

Thursday, August 29, 2013

Dual boot - Win 8 does not boot after unsuccessful EasyBCD run

If the Windows partition is still intact, but the bootloader is confused, do the following:

- acquire the CD or USB stick with Win 8 recovery tools, any Win 8 PC can create one, but the machine must be 32-bit or 64-bit like the "broken" one.

- boot from this media drive (maybe you need to modify bios boot priority first)

- reach the command prompt

- execute : bootrec /rebuildbcd


-The program will conclude if it finds an installed windows partition. Follow instructions in the prompt.

http://superuser.com/questions/451277/missing-boot-files-in-windows-8

Wednesday, August 14, 2013

Unix: move odd or even numbered files

$ mkdir odd; mv *[13579].fileextension odd
Source: http://superuser.com/questions/587495/osx-unix-move-odd-or-even-numbered-files 

Monday, July 15, 2013

KDE Keyboard Layout Switcher crashes

Try to restart the application  :

$ kxkb

Source: http://forum.kde.org/viewtopic.php?f=66&t=83882

Monday, July 8, 2013

ImageJ multiple images to stack

File -> Import -> Image Sequence ->

Friday, July 5, 2013

Using Bash To Output To Screen And File At The Same Time

use "tee"

ex:
$ ls -al | tee blah.txt
 
source: http://www.skorks.com/2009/09/using-bash-to-output-to-screen-and-file-at-the-same-time/ 

Monday, July 1, 2013

Java classpath under linux

You use the -classpath argument. You can use either a relative or absolute path. What that means is you can use a path relative to your current directory, OR you can use an absolute path that starts at the root /.
Example:
bash$ java -classpath path/to/jar/file MyMainClass
In this example the main function is located in MyMainClass and would be included somewhere in the jar file.
For compiling you need to use javac
Example:
bash$ javac -classpath path/to/jar/file MyMainClass.java
You can also specify the classpath via the environment variable, follow this example:
bash$ export CLASSPATH="path/to/jar/file:path/tojar/file2"
bash$ javac MyMainClass.java
THE FIRST LINE MAY APPEAR IN THE .bashrc TO AUTOMATE THINGS A BIT

For any normally complex java project you should look for the ant script named build.xml


source: http://stackoverflow.com/questions/11459664/how-to-add-multiple-jar-files-in-classpath-in-linux

Thursday, June 13, 2013

Emacs comment / uncomment region

Add to config file:

(defun uncomment-region (beg end)
  "Uncomment a region of text"
  (interactive "r")
  (comment-region beg end -1));

(global-set-key "\C-c;"      'comment-region)
(global-set-key "\C-c:"      'uncomment-region)

Emacs overwrite selection

add the line:
(delete-selection-mode 1)
to the file 
~/emacs.d/init.el

Thursday, June 6, 2013

Open Office protect cells

* Select all cells with Ctrl+A
* Format->Cell->Cell Protection, unprotect [all]
* Select the cells to protect
* Format->Cell->Cell Protection, protect
* Tools->Protect Document->Sheet

ImageJ out of memory fix

Solution 1:

run from console:

./jre/bin/java -Xmx512m -jar ij.jar 

for getting 512MB (for example). (Source: http://imagejdocu.tudor.lu/doku.php?id=faq:technical:how_do_i_increase_the_memory_in_imagej)

Solution 2:

 edit the

/usr/bin/imagej

run script OR find it with

$ whereis imagej

then modify the line

declare -i default_mem=768

with the desired memory in MB. Notice limitations depending on total RAM and 32/64 bit system. (Source: http://ubuntuforums.org/archive/index.php/t-1236001.html)

Wednesday, June 5, 2013

ImageJ save Raw

26.10.6Raw Data…

Saves the active image or stack as raw pixel data without a header. 8-bit images are saved as unsigned bytes, unsigned 16-bit images are saved as unsigned shorts and signed 16-bit images (e.g., FileOpen SamplesCT (420K, 16-bit DICOM)) are saved as signed shorts. 32-bit images are saved as floats and RGB images are saved in three bytes per pixel (24-bit interleaved) format. 16-bit and 32-bit (float) images are saved using big-endian byte order unless Export Raw in Intel Byte Order is checked in the EditOptionsInput/Output… dialog box. 
 
http://rsbweb.nih.gov/ij/docs/guide/146-26.html

Monday, June 3, 2013

CUDA nvcc

"A different solution to overcome startup delay by JIT while still allowing execution on newer GPUs is to specify multiple code instances, as in
nvcc x.cu -arch=compute_10 -code=compute_10,sm_10,sm_13
This command generates exact code for two Tesla variants, plus ptx code for use by JIT in case a next-generation GPU is encountered. nvcc organizes its device code in fatbinaries, which are able to hold multiple translations of the same GPU source code. At runtime, the CUDA driver will select the most appropriate translation when the device function is launched."

"...the virtual compute architecture should always be chosen as low as possible, thereby maximizing the actual GPUs to run on. The real sm architecture should be chosen as high as possible (assuming that this always generates better code), but this is only possible with knowledge of the actual GPUs on which the application is expected to run. As we will see later, in the situation of just in time compilation, where the driver has this exact knowledge: the runtime GPU is the one on which the program is about to be launched/executed."

http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc

Thursday, May 30, 2013

Linux - New Video card upgrade

Right after you installed the card. Boot into recovery mode and go to text mode. Remove (or just rename) it:
Code:
sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.old
Then restart your computer. While you are in the desktop, go to 'Additional Drivers' and install the Nvidia driver.

http://ubuntuforums.org/showthread.php?t=1939530