Wednesday, October 31, 2007

C/C++ Show macros

In gcc or g++, to show all of the macros that are defined for a given platform:
gcc -dM -E test.c
g++ -dM -E test.cpp

Sunday, October 28, 2007

Ubuntu - core dump

It appears that resource limits (which include the maximum size of a core dump file) are set by PAM on login. The settings for these limits are in /etc/security/limits.conf, which on my system (which is unmodified) is comments only. A quick look at the source code suggests that the default core dump limit is 0 (zero), which means no dump at all is created (even though the message suggests otherwise).

In summary: edit /etc/security/limits.conf, set the core limit to be non-zero (measured in kilobytes), and log in again.

I hope that works!

Thursday, October 11, 2007

VIM - omnicppcomplete

I had to put these in my ~/.vimrc to get omnicppcomplete to work
autocmd BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main

map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

imap <C-Space> <C-x><C-o>
let OmniCpp_MayCompleteDot = 0
let OmniCpp_MayCompleteArrow = 0

VIM - NERDTree plugin

Good file explorer.

plugin: link

Add this to ~/.vimrc
"NERDTree Toggle
noremap <Leader>][ :NERDTreeToggle

Tuesday, October 9, 2007

Ubuntu - Install dev man pages

sudo apt-get install manpages-dev manpages-posix-dev

Tuesday, October 2, 2007

Linux - xbindkeys for Logitech G5

This is my ~/.xbindkeysrc for my Logitech G5:
"/usr/bin/xvkbd -xsendevent -text "\[Return]""
m:0x0 + b:8
"/usr/bin/xvkbd -xsendevent -text "\[Alt]\[Left]""
m:0x0 + b:7
"/usr/bin/xvkbd -xsendevent -text "\[Alt]\[Right]""
m:0x0 + b:6

Additional help: link

Thursday, September 20, 2007

Eclipse - Last Edit Location

Keyboard shortcuts:
Last Edit Locationctrl+q
Next Edit Locationctrl+.

Monday, September 10, 2007

GVIM - Enable horizontal scroll bar

Add this to your .vimrc:
set guioptions+=b

Wednesday, September 5, 2007

UNIX/LINUX - Customized bash prompt

If you want your bash prompt to look like this:

[10:27:57 AM] hostname:~/some_dir

Put this in your .bashrc:
function proml
local BLACK="\[\033[0;30m\]"
local RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local YELLOW="\[\033[1;33m\]"
local BLUE="\[\033[0;34m\]"
local PURPLE="\[\033[0;35m\]"
local CYAN="\[\033[1;36m\]"
local WHITE="\[\033[1;37m\]"

case $TERM in
local TITLEBAR='\[\033]0;\h:\w\007\]'
local TITLEBAR='\[\033]0;\h:\w\007\]'
local TITLEBAR=''

${GREEN}[\$(date +%r)] ${RED}\h:${YELLOW}\w\
${WHITE}\n$ "
PS2='> '
PS4='+ '

You can change the colors and other properties as well.

Tuesday, September 4, 2007

X11 - Dell 2405fpw xorg.conf

Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
HorizSync 30.0 - 110.0
VertRefresh 50.0 - 150.0
Option "DPMS"
Modeline "1920x1200" 154.128 1920 1968 2000 2080 1200 1203 1209 1235 -hsync -vsync

Section "Device"
Identifier "Device0"
Driver "nv"
VendorName "NVIDIA Corporation"

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1200" "1280x1024" "1024x768" "800x600" "640x480"

Thursday, August 23, 2007

VIM - Search to end of word

This will leave your cursor at the end of the searched phrase:
/search phrase/e

Monday, August 13, 2007

VIM - format lines to certain width

:set textwidth=80 (or :set tw=80)
gqqFormat a single line
{Visual}gqFormat visual selection. (ctrl+v to get to visual mode then use hjkl to navigate)

For more help,
:help gq

Sunday, August 5, 2007

Compile Pidgin for Ubuntu 7.04

Download source:
Install dependencies:
sudo apt-get install gettext libglib2-dev libgtk2.0-dev libxml2-dev
For MSN and GoogleTalk:
sudo apt-get install libnss-dev libnspr-dev
sudo make install
make install clean

Sunday, July 8, 2007

Mouse gestures

What is a mouse gesture?

They can probably be explained better with an example:
Say you wanted to scroll down on a webpage using your mouse. Normally, you would point your mouse cursor to a scroll bar and clicking on it. Using mouse gestures, you would click and hold on to the right mouse button, move the mouse cursor down a little bit, and then let go of the button.

What are the advantages of mouse gestures?

First off, you don't need to point to any user interface element; thus, mouse gestures save time by minimizing mouse movement.
Most mouse gesture programs allow you to customize what your mouse gestures do. For example, if you did not want the down gestures to scroll down, you can change it to do something else such as changing tabs.

How do I add mouse gestures?

For Windows: StrokeIt
For Firefox: All-in-One Gestures
Other: wikipedia entry

Friday, June 22, 2007

Excel - Custom page numbering

  • View → Header and Footer...
  • "Custom Header..." button
  • Type these into any one of the sections:

    InputResult for page 1

Wednesday, June 20, 2007

VIM - minibufexpl

Script: minibufexpl.vim
"MINIBUFEXPLORER Stuff (Enter "\mbe" minus quotes quickly to bring it up)
" Ctrl-PgDown - goto next buffer
" Ctrl-PgUp - goto prev buffer
" \-Backspace-= - toggle minibufexplorer
"let g:miniBufExplMaxSize = 3 "allow up to 3 lines of buffers
let g:miniBufExplModSelTarget=1
"map mbo :MiniBufExplorer
noremap :bn
inoremap :bn
cnoremap :bn
noremap :bp
inoremap :bp
cnoremap :bp
noremap = :TMiniBufExplorer
noremap u :UMiniBufExplorer

set hid "Hide abandoned buffers in order to not loose undo history

Monday, June 18, 2007

KDE - Default browser

$ kcontrol
KDE Components → Default Applications → Web Browser
Under Default Component, choose "In the following browser"
Type in: firefox (or your browser of choice)

Then go to KDE Components → File Associations.
Go to Text → html.
Click Firefox and press the Move Up button.

Wednesday, June 13, 2007

LINUX/UNIX - inputrc options

Add this to your ~/.inputrc to
# get default system bindings
$include /etc/inputrc

# ignore case on tab complete
set completion-ignore-case On

# prefer visual bell
set prefer-visible-bell

Tuesday, June 12, 2007

Perl - Find and replace all

Find cpp and hpp recursively from the current directory then append those files onto the perl command, which substitutes "old" for "new" in those files while creating .bak backups.
find . -name "*.[ch]pp" -type f | xargs perl –i.bak –p –e 's/old/new/g;'

or non recursive:
perl -pi -w -e 's/search/replace/g;' *.php
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop

Thursday, June 7, 2007

VIM - Multiple highlighted searches

Script link
:Search <pattern1>
:Search <pattern2>

Friday, May 11, 2007

redhat - rpm

rpm -i softwarename(s)
rpm -e softwarename(s)
rpm -q softwarename
rpm documentation

KDE - Umbrello

I tried out Umbrello for KDE. Seems to work better than MagicDraw at reverse engineering C++ code. It's free. Crashed on a couple of the files I tried though.

Firefox - Reduce RAM when minimized

Move Firefox to your hard drive when you minimize it, taking up less memory. And there is no noticeable difference in speed when you restore Firefox.
  • Go to about:config
  • Right-click anywhere → New &rarr Boolean
  • config.trim_on_minimize
  • Set to TRUE
  • Restart Firefox for these settings to take effect
From: 15 Coolest Firefox Tricks Ever on

Wednesday, May 9, 2007

C - Static Keyword

inside a functionremains even after the function call is long gone
modify a global variableprivate to a certain file
modify a functionmaking those functions visible only to the file itself

KDE - Enable mouse gestures

Run kcontrol
Regional & Accessibility → Input Actions
Gestures tab
Unclick Disable mouse gestues global
Change Mouse button to secondary button (right mouse button)

Open up Konqueror
Hold on to right-mouse button, move left, release
It should have navigated back a page

VIM - Recursively set project path

Put this in your .vimrc
set path=$PWD/**

Visual Studio 2005 Express


Using Visual C++ 2005 Express Edition with the Microsoft Platform SDK

Cygwin/X - Install 100 dpi fonts

If your fonts look too small, try installing the 100dpi fonts in Cygwin's setup. Under X11, select
xorg-x11-f100: Cygwin/X 100 dpi fonts
In your C:\cygwin\usr\X11R6\bin\startxwin.bat, near the bottom of the file, append "-dpi 100" to this line:
%RUN% XWin -multiwindow -clipboard -silent-dup-error

UNIX/Linux - xhost access

To make your X server available to everyone:
xhost +
You can add this to your .bashrc

Cygwin/X - Startup with Windows

Place a shortcut to
in your startup folder (e.g. Start->All Programs->Startup)

To not have xterm pop up everytime you start up, open startxwin.bat and prepend REM in to this line:
%RUN% xterm -e /usr/bin/bash -l

Wednesday, May 2, 2007

UNIX/Linux - Recursive, forceful remove

For you n00bs, to recursively delete a directory with prompts for each file:
rm -rf dir_name

VIM - Using cscope

Install cscope.

At your project directory, to recursively build the database
cscope -Rb

Place cscope_maps.vim into ~/.vim/plugin.

CTRL+] to search for the word under the cursor.

See the cscope vim tutorial for more details.

VIM - Recursively set the path of the project

Put this in your .vimrc to
" Recursively set the path of the project
set path=$PWD/**

Monday, April 30, 2007

UNIX/Linux - Build essentials

In order to build stuff in Ubuntu, I needed to install the build-essentials:
sudo apt-get install build-essential

Who knew?

Wednesday, April 18, 2007

VIM - Shifting and code formatting

You can shift (indent) code right or left by typing >> or <<, respectively, with your cursor on the line you want to shift.

You can use VIM automatic formating by typing == on the line you want to format.

You can also set the amount of spaces to shift.

You can also shift and format in visual mode (To get into visual mode: SHIFT+V, then j and k to select rows) by selecting the lines you want, then typing >, <, or =.

VIM - Inserting spaces instead of tabs

Insert spaces instead of tabs

set expandtab or set et

Set the width of shifts to 4 for autoindenting and shifting: >> and <<

set shiftwidth=4 or set sw=4

Set where to stop tabs to 4

set tabstop=4 or set ts=4

This is what I have in my ~/.vimrc:

Set expanded tabs with shiftwidth=4 and tabstop=4 for Java, Perl, C, and C++ files

autocmd BufNewFile,BufRead *.java,*.pl,*.c,*.h,*.cc,*.cpp,*.hpp set sw=4 ts=4 et

Tuesday, April 17, 2007

UNIX/Linux - Find command

To look for files in the current directory tree then run a command on them:
find . -name <file-pattern> -exec <command> {} \;


To grep for "hello" inside all .txt files:
find . -name *.txt -exec grep -Hn hello {} \;

Put this in a shell script to recursively grep .cpp and .hpp files for the first argument:
find . -name *.[ch]pp -exec grep -Hn "$1" {} \;

Wednesday, April 11, 2007

RSS - Web comics

Subscribing to web comics is a great way to use RSS.

Here are some comics I subscribe to:

Wednesday, March 21, 2007

Cygwin tips

All tips assume you installed Cygwin at C:\cygwin

Use rxvt instead of dos command prompt

Change your cygwin.bat to
@echo off

chdir C:\cygwin\bin

rxvt -e bash --login -i

Customize rxvt

Create a file in your home directory named .Xdefaults
rxvt*font: Lucida Console-14
rxvt*scrollBar_right: true
Other rxvt options can be found here.

Fix Home, End, Delete, and Insert keys

Put this into ~/.inputrc
# Home Key

# End Key

# Delete Key

# Insert Key

Then add this to ~/.bashrc
export INPUTRC=$HOME/.inputrc

Friday, March 16, 2007

Web - Firefox Search Engines

You can add your own search engines to the Firefox search bar. Here are some I found:


Thursday, March 8, 2007

VIM - Doxygen Syntax Highlighting

To have vim highlight Doxygen comments, add this to your vimrc:
let g:load_doxygen_syntax=1

For more help, try
:help doxygen

Thursday, March 1, 2007

UNIX/Linux - Command Line Tips

du -hs dirDisplays disk usage of dir. -h gives human readable format (e.g. 12M) and -s suppresses every recursive directory's output
echo $?Displays the return code of the previously exited program
pgrep -lf process_nameDisplays pid of all running processes named process_name. -l lists the process name and -f matches in the full command line

Web - RSS

You've noticed websites with orange icons that say "RSS" on them, but you don't know what that means or what to do with those icons.

What is RSS?

Rich Site Summary, or Really Simple Syndication.

For real, what is RSS?

A website containing an RSS feed has the capability to send you a summary of updates whenever it has updates. In other words, you're able to subscribe to that website's updates.

Why should you care?

When you subscribe to an RSS feed, it sends notifications when updates are available on the site. Some feeds even give a brief description of the update. This way, you don't have to open the whole website to know that it's been updated; thus, saving you time.

What can you subscribe to?

Any site with orange icons labelled RSS or XML. This includes sites such as blogs, news sites, forums, and download lists.

Some browsers, such as Firefox, display buttons when you browse to a site with RSS feeds.

Ok, cool. So how do you use RSS?

Let's walk through an example:
  • At the bottom of CNN, you'll see a link for RSS.
  • Click on that RSS link. It should bring you to CNN's page of RSS feeds, which contains various RSS links to potential topics to subscribe to, such as CNN's Top Stories.
  • Click on any one of those RSS links. A page or dialog box should prompt you for which RSS aggregator (such as GreatNews) to use to subscribe to that feed.
  • Now you open your RSS aggregator, update your feed, and look at the page updates. Simple as that!

Subscribe to my blogs using RSS

Friday, February 23, 2007

C++ - Forward Declarations

If a class declaration (in a header file) does not need to know the size of any included classes/structs (i.e., the class declaration does not need to contain an actual instantiation of another class or access member data or functions of another class), forward declare the dependent classes/structs to minimize dependencies.

In other words, use pointers and references of classes/structs with respective forward declarations instead of member objects instantiations and #include's. Then, #include dependent files to access the other classes' members and functions in the source file (.c,.cpp). Remember to delete the pointers in the destructor if the class owns the pointer.

In myClass.h:
//Forward declarations
class OtherClass; // defined in otherClass.h
struct OtherStruct; // defined in otherStruct.h

class MyClass
OtherClass *mMyOtherClass; //pointer
OtherStruct &mMyOtherStruct; //reference
MyClass(OtherStruct &_struct);

In myClass.cpp
#include "myClass.h"
// include headers of forward declarations
#include "otherClass.h"
#include "otherStruct.h"

MyClass::MyClass(OtherStruct &_struct)
: mMyOtherClass(new MyOtherClass),
// references can only be initialized in
// constructor initialization list
// Empty constructor body

delete mMyOtherClass;

C++ - Minimize Dependencies

A change in a header file (.h, .hpp) causes every other header file that includes it to be recompiled. Thus, to decrease incremental build times, strive to minimize the number of #include's in header files.

Note this cannot be done with every header file, such as files containing dependencies on template classes or typedefs.

C++ - const Keyword

Use the keyword const to signify (to developers, not just the compiler) that a variable does not change).

* This method doesn't change its object
* @param[in] obj Reference to a constant MyObj
* @return A constant reference to obj
const MyObj& MyObj::myMethod(const MyObj &obj) const
return obj;

C++ - Parameter Passing

Avoid passing large objects by value. This causes unnecessary copying of those objects on to the stack, slowing down performance. Instead, pass by reference (or pointer).

When needed, use prefixes "in" and "out" to avoid confusion with outgoing parameters.

Pass by value (NG=No Good):
void func(BigObject obj) // Use copy of obj

Pass by reference (Good):
void func(BigObject &obj) // Uses reference of obj

Note that smaller primitives (e.g. int, short, char) do not benefit from passing by reference because most the time, they are either equal to or smaller than the word size of the machine.

C++ - Initialization Lists

Constructing an object consists of two parts:
  1. Creating the object
    • Without initialization list: Assign default values to the object's member variables
    • With initialization list: Assign specified values in initialization list to member variables
  2. Running the constructor's body
In object creation without an initialization list, default values are assigned to the object's member data. If assignments exist inside the body of the constructor, member data will be assigned again. However, with an initialization list, specified values can be assigned in step 1 to avoid assignments in the constructor's body.

Warning: there is no guarantee on the order of assignments (see example).

member1 = 1;
member2 = 2;
member3 = member2;

: member1(1),
//, member3(member2) // No guarantee member2
// was set before here
member3 = member2; // need to assign here

VIM - Advanced Tips

Here are some advanced tips I've learned from coworkers and working with VIM:

:%s *$==Delete end of line spaces
:'a,'bs/str1/str2/gReplace "str1" with "str2" from marker a to marker b
:%s/\(.*\):\(.*\)/\2:\1/gReplace the first field (\1) with the second field (\2) separated by the :
zfFold a selected block of code
zdUnfold a block of folded code
:makeRun Makefile
:w|makeWrite (save) current file and then run Makefile
:grep regexp filesFind regexp in files
:copenOpen quickfix list. Helpful after doing :make or :grep. Press Enter on entry in quickfix list to jump to that location
:ccloseClose quickfix list
:colderDisplay contents of previous quickfix list
:cnewerDisplay contents of next quickfix list
:!cmdRun cmd as if on command line. Example: :!ls
:bwClose current buffer
ctrl+oGo back once through visited lines
ctrl+iGo forward once through visited lines
:h topicGet help for topic

Wednesday, February 21, 2007


I've tried many RSS aggregators but the one I like most is GreatNews from Curio Studio.

Here are some tips I've learned from using it for a while:
  • Ctrl+R: Mark feed as read
  • Ctrl+T: Create new tab
  • Middle click
    • Feeds: Opens originating page
    • Posts: Opens post in current tab
    • Links in posts: Opens link in new background tab
    • Tabs: Closes the tab
  • Tools → Options → Reading
    • Check "Mark previous feed as read when switching feeds"
  • Do not sort by date (or anything for that matter). This really slows it down.
  • Tools → Cleanup... : Cleans up unread posts

Friday, February 16, 2007

Web - Firefox Extensions

I can't imagine using Firefox without these essential extensions. You can download Firefox on the side bar.

Thursday, February 15, 2007

Linux - Reinstalled Kubuntu

A few days ago, I wanted to install the new subversion client for Kubuntu because the old one didn't have the 'svn diff -c' option. I guess I shouldn't have because it depends on a newer cpp package, which the system depends on it. So after installing the new cpp package, my thesis wouldn't compile. I tried installing the old cpp but it kept using the new one. So last night I reinstalled Kubuntu. I updated all the packages and everything looks good. Hopefully, I will be able to work on my thesis tonight.