# Category Archives: Science & Technology

## Commonly used Vim commands

:sav (save as)
c (change)
d (delete)
{ } (page up, down)
/ (search)
:wq (save, quit)

:%s/findme/replaceto/gc (replace within file, multiple occurence per line, confirmation)

v: Visual Mode
Shift+v : Line Visual Mode
Ctrl+v , then Shift+i : Column-wise Insert

:set autoindent
:set cindent
:set scrolloff=1000

:bufdo %s/from/replace/ge | w (search and replace, to all buffers)

(From command line) ctags -R .
Ctrl + ] = go to definition
Ctrl + T = go back to caller
:set tags=(the topmost ctags file desired)

—-.vimrc—-

```syntax on
"set autoindent
"set cindent
set smartindent
filetype plugin on

let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

"Set color scheme
set t_Co=256
colorscheme desert256
"colorscheme gardener

"Enable indent folding
set foldenable
set fdm=indent
set tags=../tags```

## Heap Segmentation Fault – caused by declaration location/scope

Unexpected segmentation faults? Might be your variable declaration.

Here’s the point, declaring variables as global, is commonly known as “do you really need to?” .
Especially if it’s a dynamic sized data structure, like a C++ list.
Yeah  I realized the hard way, the size grew out of static memory bounds and got into the heap.

Good old GDB to the rescue, those error messages might be a mystery at first, it’s still potentially a beacon of hope.

## Dynamic Multidimensional Array in C and C++

Here’s how you would declare a one dimensional array in C:

``` long* array;
array = malloc(dimension*sizeof(long));```

Equivalent to:
long array[dimension];

For two dimensional array in C, where each element are located in contiguous memory space:

```long** array2;
long* tmp;```
```array2 = (long**)malloc(dimension1 * sizeof(long*));
tmp = (long*)malloc(dimension1 * dimension2 * sizeof(long));
for (i = 0;i<dimension1;i++){
array2[i] = tmp + (i*dimension2);
}```

One dimensional array in C++:

```int *array;
array = new int [dimension];```

For two dimensional array in C++:

```int **array2;
array2 = new int* [dimension1];
for (i=0; i<dimension1; ++i)
array2[i] = new int[dimension2];```

If you get segmentation faults, and you have arrays in your program, most likely it’s because of those pointers. And never try to access a pointer that leads to NULL. Fault!

## PureSync

My favorite file synchronizer for Windows. It’s free for personal use.
http://www.jumpingbytes.com/en/puresync.html

## Hard Disk Freeware Utilities

I tried to revive a USB flash drive, and found useful utilities here:
http://www.hddguru.com
Didn’t get mine to work though, the OS doesn’t even recognize it as a drive.

## Don’t NTFS Compress OS HD

Never compress your main hard drive (that has Windows installation in it, usually C:\).
It will modify the MBR and thus Windows will fail to boot. You will need to fix the MBR with the Recovery Console, accessed by booting from the Windows Setup CD.
You can copy your installation CD to a USB, using WinToFlash to make it bootable.
Once inside the recovery console, type “fixboot” and thus the MBR is fixed.
I read an alternative way to fix this by booting from a live CD/USB (Linux ok) and copying the three MBR files.

## Logic Gate Simulation

This would really help digital engineering/discrete maths students:

http://joshblog.net/projects/logic-gate-simulator/

## Error on Linking MSVC++ Projects

Upon successful compilation of builds, the linking process  might stumble upon a linking error. These may happen in the form of unresolved externals or redefinitions.

On unresolved externals: make sure all of the dll or lib exists. Also check the code generation property and select the appropriate options. Make sure all projects use the same code generation correspondingly.

On redefinitions, I had to ignore one of the libraries which caused the redefinition. For instance, in my project, I had to ignore these libraries for the release build :libcmtd.lib;libc.lib;nafxcw.lib;msvcrtd.lib;msvcrt.lib

And these for debug build:
libcmt.lib;libc.lib;nafxcwd.lib;msvcrtd.lib

Would be grateful for enlightenments on further details of those libraries. I could’ve saved hours on solving the linking errors.

PS: Don’t forget to set EMBED MANIFEST to yes when using non DLL settings. Found this out the hard way.

## Macros for Build Commands in MS Visual Studio

Other than the ones stated here:
http://msdn.microsoft.com/en-us/library/c02as0cs.aspx

We can also use Windows System Environment Variables (under Control Panel->System Properties) to retrieve the path. For instance: (\$DXSDK_DIR)
will lead to the DirectX SDK directory, includes a trailing backslash.
I needed to use these macros since the software development are conducted on different machines with different SDK directories/drive letters. Absolute include directories should always be avoided. 🙂

## Internet Explorer Script Error MFC (Line 815 Char 3)

I am using Visual Studio 2005 SP1 (C++), and I wanted to add a class for a dialog when the IE error showed up. Needed to find a quick fix and here is what I found: (turns out it was because I installed IE8)

http://blogs.msdn.com/vcblog/archive/2009/03/28/some-vs2005-and-vs2008-wizards-pop-up-script-error.aspx

–          Open regedit (on a 64-bit OS, open the 32-bit regedit)

–          Under “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones”, create a new key called 1000 (if it isn’t already there)

–          Under 1000, create a DWORD entry with:

o   Name = 1207

o   Type = REG_DWORD

o   Data = 0x000000

## Let’s use LaTeX!

I’m now officially a $\LaTeX$ user (hehee, just because of one report), and big fan 😀 You can even enter LaTeX equations in WordPress posts/comments.

I will update this post with how I got through the steep learning curve of $\LaTeX$. It’s a bit frustrating in the beginning, especially with the programming-compile process (hey, I’ve been coding for the last month, gimme a break :P). Anyhow, I shouldn’t complain about this, any future scientist/engineer will (or should) face the beauty of $\LaTeX$.

Right now, I’m still on progress writing I have just finished a report.  I’ve been in front of $\LaTeX$ these recent days, and I don’t miss the Word processor 😀

This is how I learnt $\LaTeX$. When I had to add figures (pictures), or tables, I looked up on the internet on how and what tools can be used. Then I studied the formatting of the picture, and table.
Another example, when I had to put references, I learnt how to use an external file, then later on how to format it using IEEE Transaction Standard. So it really is a step by step learning process.

Most graduate schools require the students to write their paper/thesis using $\LaTeX$. But don’t worry, usually they have templates we can use straight away. But to learn for the first time, it’s best to write our own template, to get the best looking. It takes time, but it’s worth it.

http://www.tex.ac.uk/cgi-bin/texfaq2html

There’s an online course with nice slides (German university), but I lost the link.. sorry, have been looking for it too.

OK, saved the best for last: http://www.andy-roberts.net/misc/latex/index.html

## OpenOffice Review (OxygenOffice Professional 2.3.1)

Why did I suddenly try the open office suite?
I wanted to know what people should use (instead of pirating) if they didn’t have the money to buy the widely used MS Office or purchase the licensed software cheaply from academic institutions (like me). It is also widely used on Linux OS PCs.

I installed the OxygenOffice Professional 2.3.1 version because it had a clipart gallery I want to check out, and also their pre-installed plugin for opening Office 2007 files.

First, I tried opening the docx format from Word 07. It worked out fine except for the equations (didn’t show up) and images are resized to small, which is annoying.

Then, I tried opening the pptx format from Powerpoint 07. Slide background and text were fine, but animations, slide transitions, and charts didn’t get transferred. Didn’t bother to try the spreadsheet, most likely the charts were also unable to be imported.

In conclusion, the installed OpenOffice is not a full replacement of the Office 2007 suite. We have to look for other ways to convert the format, or wait for the new OpenOffice 3 which is rumored to come out in September 2008.
The clipart gallery is nice btw.