How to maximize a window programmably in X Window?

You can do this using wmctrl.

Example

Get your window's ID.

$ wmctrl -l
0x02a00004  0 grinchy saml@grinchy:~
0x0620004f  0 grinchy [gnome] Bash command for Maximizing and Unmaximizing windows in gnome? - Google Chrome

Then toggle window ID 0x0620004f, like so.

$ wmctrl -i -r 0x0620004f -b toggle,maximized_vert,maximized_horz

here is a simpler way, just put this code in a script, and set executable with a keyboard shortcut. Works for me.

wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz