10 June 2007

ctags with PHP in vim

Another tip to code PHP effectively

#!/bin/bash
cd /path/to/framework/library
exec ctags-exuberant -f ~/.vim/mytags/framework \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'


to load it,
:set tags=~/.vim/mytags/framework

Ctrl-], and you'll jump to the file and line of its declaration; Ctrl-T then takes you back
Ctrl-W ], it will split the current window and open the declaration in the new pane

20 April 2007

VIM tips: blockwise selection mode and recording macros

Here a table schema from postgresql


col1 | integer | not null default nextval('sc.col1_seq'::regclass)
col2 | timestamp without time zone | not null
col3 | character varying(100) |
col4 | numeric |
col5 | numeric |
col6 | integer |
col7 | integer |
col8 | numeric |
col9 | numeric |
col10 | character varying(100) |
col11 | character varying |
col12 | character varying(100) | not null
col13 | character varying |
col14 | character varying |
col15 | numeric |
col16 | numeric |
col17 | numeric |
col18 | character varying |
col19 | numeric |


and I want using VIM to convert to

$ary = array('col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9',
'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17',
'col18', 'col19');


How I do it?
The idea is use blockwise selection mode to insert (') in beginning of each line, and use recording macro to append (',) for each line. Format it (not exceed 80 characters per line). More details step by step

  1. <Ctrl+V>GI'<Esc> -- blockwise selection mode and insert (')

  2. 0qaelC',<Ctrl+c>j0q -- record macro to regiser a

  3. 18@a -- replay macro in register a

  4. insert the $ary = array(

  5. VGgq -- to format it, i.e. each line max chars=80



I do a lot of migration work currently, and frequently use these tips. Not sure for other editor, but I believe Kate don't have these features. Sorry Kate, I just don't like U! Someone look impress when saw me using blockwise selection, and that motivate me to write this blog :-)

more tips, http://jmcpherson.org/editing.html

11 February 2007

Back References in trac 0.10.2

Back References lists all references to an ticket inside the details of it. I want this feature in my trac, but the patch is for version 0.11beta. So I spent half an hour to implement my patch. Not perfect, but just fit my need. (sorry, give up to create proper patch after 7 minute rtfm)
helmi@hix2:~> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=6.10
DISTRIB_CODENAME=edgy
DISTRIB_DESCRIPTION="Ubuntu 6.10"
helmi@hix2:~> trac-admin --version
Trac Admin Console 0.10.2

10 February 2007

Broadband Throttling

Broadband throttling is:
  • try to move backward
  • MISLEADING THE PUBLIC WITH CHEATING MARKETING STRATEGY DESERVES A GOOD LAWSUIT
  • Better call it Streamyx Narrowaband or Streamyx Limitband
  • 4 days finish bandwidth and sit down there wait for another f***ing month to get another bandwidth usage
  • wanna throw up whenever i see the advert "breaking the speedometre"
  • "jaguh kampung" mentality? or the "we are still better than ghana" thinking?
  • definately ridiculous
as A. Asohan says in Throttling broadband access for all

Maxis did it first when it rolled out its wireless broadband service last year. Under the “Terms and Conditions” of usage, it had this little gem: “Maxis may, at its sole discretion, automatically disconnect the customer’s Internet session after a period of inactivity, which may vary from 20 minutes to 30 minutes.”

And if that’s not all, here’s the clincher: “Each customer’s total usage per month shall NOT exceed 3GB of data volume transmitted ...”

and I want add more complaint, bandwith during weekend is reaaaally suck (dial-up standard)

Average bandwith during weekend, 1.5Kb/s

@see http://www.lowyat.net/v2/latest/broadband-throttling-the-star-takes-notice.html
p/s: I am one of the Maxis broadband subscriber

21 January 2007

How I setup my 64bit machine to play flash in firefox

Use swiftfox instead of standard firefox as browser and install the flash plugin. I use automatix to install that packages.

Screenshot: swiftfox browser+plugins installed using automatix2
helmi@hix2:~> uname -a
Linux hix2 2.6.15-26-amd64-k8 #1 SMP PREEMPT Thu Aug 3 03:11:38 UTC 2006 x86_64 GNU/Linux
helmi@hix2:~> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=6.10
DISTRIB_CODENAME=edgy
DISTRIB_DESCRIPTION="Ubuntu 6.10"
I tried gnash as flash player, but it eat a lot of CPU resource for some of the websites. Yeah I have dual core CPU, but still irritate me when gkrellm show CPU busy working. Another idea is setup 32bit OS in vmware and install the firefox. Swiftfox=32bit app, i.e. not fully utilize 64 bit machine.

One issue with swiftfox, my firebug don't work, i.e. hard for me to do web app development using swiftfox :-(

** not related to any geeky stuff ** Really bored recently. So, I decide to learn new skill that not related to computer - juggle 3 objects. I believe in repetition is mother of skill (liliadandelion say: mother of boredom), so after a lot of practising I can YIPPEE! now. Highscore=64

11 December 2006

Configure RADEON X550 on Kubuntu Edgy

Here I want to share how I configured my ATI RADEON X550 on Kubuntu Edgy.

I installed the driver in Kubuntu edgy manually. In short, download ati-driver-installer-8.31.5-x86.x86_64.run and follow the ATI linux driver guide.

Work in theory but give me pain before I get the 3D properly. Here the 'bad' messages:

helmi@hix2:~> vim /var/log/Xorg.0.log
...
[drm] failed to load kernel module "fglrx"
(II) fglrx(0): [drm] drmOpen failed
(EE) fglrx(0): DRIScreenInit failed!
(WW) fglrx(0): ***********************************************
(WW) fglrx(0): * DRI initialization failed! *
(WW) fglrx(0): * (maybe driver kernel module missing or bad) *
(WW) fglrx(0): * 2D acceleraton available (MMIO) *
(WW) fglrx(0): * no 3D acceleration available *
(WW) fglrx(0): ********************************************* *
...
helmi@hix2:~> glxinfo | grep 'direct rendering'
direct rendering: No
helmi@hix2:~> fglrxinfo
display: :0.0 screen: 0
OpenGL vendor string: Mesa project: www.mesa3d.org

After googling, I realize that the driver don't match to the kernel
helmi@hix2:~> uname -a
Linux hix2 2.6.15-26-amd64-k8 #1 SMP PREEMPT Thu Aug 3 03:11:38 UTC 2006 x86_64 GNU/Linux
helmi@hix2:~> gcc --version
gcc (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)

I compile the ATI driver using gcc-4.1.2 but my kernel compiled using gcc-4.0. So the workaround is (follow the guide, copied here as my future reference):

sudo apt-get install gcc-4.0
sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc

After doing the module-assistant steps, you may want to return gcc to 4.1 by default:

sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc


After reboot,
helmi@hix2:~> glxinfo | grep 'direct rendering'
direct rendering: Yes
helmi@hix2:~> fglrxinfo
display: :0.0 screen: 0
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: RADEON X550 Generic
OpenGL version string: 2.0.6174 (8.31.5)
Yey! Next is Xgl/Beryl ...

If you notice I use kernel 2.6.15-26, and Edgy use 2.6.17-10. That new kernel just refused to start properly and I too lazy to debug it - my current kubuntu just `work for me`

04 December 2006

Page load faster after first request

It hard for me to explain why web page load faster when you visit the same url for second time. Non-geek just don't know how to visualize it, or people don't know what I'm talking about :-)
Now I have pictures

First request:

Second request:

Now understand? ... What, still don't understand???

24 November 2006

Why vmware snapshot is good idea?

Because you will know what to do when get Blue Screen of Death.
Here mine:
I want to get rid of message 'VMware Tools out of date'. After install and reboot, vmware give me this nice screen, yey!

01 November 2006

/bin/sh: bad interpreter: Permission denied

Got permission problem when run firefox2.

# ./firefox
# ./firefox: Permission denied

Just realize that all executable script have permission problem although give all permission to the file, i.e. chmod 777 script.sh. Even root have this permission problem.

Don't know how I edit the /etc/fstab, but my /home directory mount as 'auto'.
# cat /etc/fstab
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda3 /home auto defaults,user 0 0

So, the solution is add option exec to the filesystem at /etc/fstab. My new /etc/fstab
# cat /etc/fstab
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda3 /home auto defaults,user,exec 0 0


ref: http://forums.fedoraforum.org/archive/index.php/t-19374.html

21 July 2006

putty on nokia3230

Access to my home server using PuTTY on my Nokia 3230. I can even edit text using vim.





Buzzword for today = cometd (hint: ajax)

I'm in mode 'Korean movies'. My Little Bride, My Boss My Student, Please Teach Me English, My Tutor Friend

26 June 2006

An Optimization That’s Never Premature

I like this example about optimization:

Writing code that is difficult to read is like running up your credit card buying expensive toys; even though you don’t pay today, the bill is going to come due eventually — and the longer you wait the more it’ll cost.


I'm in Futurama fever. Now in Season 3, episode 9.

24 April 2006

vmware, apache, mplayer under kubuntu dapper [beta]

I follow this guide by Stoltenow, and it works for me.

apache2+kubuntu=SUCK!. I expect directory public_html in my home directory will be in apache DocumentRoot [like Suse and FreeBSD], but it not as expected. Have to edit the apache2.conf manually.

No mplayer in kubuntu dapper[beta]! Had uncomment /etc/apt/sources.list for universe and multiverse, but still no mplayer after `sudo apt-get update; sudo apt-get upgrade; apt-cache search --names-only mplayer`. Also had add `deb http://honk.sigxcpu.org/linux-ppc/debian/ mplayer/` in /etc/apt/sources, still no mplayer. I try the hard way, but the video don't want to come out.
VDec: vo config request - 208 x 170 (preferred csp: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.

FATAL: Could not initialize video filters (-vf) or video output (-vo).

Can't restore text mode: Invalid argument

Hey! the mplayer Makefile don't want me to uninstall mplayer.

make uninstall
...
...
/bin/sh: -c: line 6: syntax error: unexpected end of file
make: *** [uninstall] Error 2


Conclusion, my VMware Workstation 5.5.1 build-19175 works! (apache or mplayer)+kubuntu dapper[beta]=SUCK!

Kubuntu? What happen to FreeBSD?
FreeBSD is retired from my harddisk. Sayonara...

18 April 2006

Firefox problem in FreeBSD 6.0 after portupgrade

After portupgrade FreeBSD 6.0 then you got this error when run firefox:

(Gecko:7209): GLib-GObject-WARNING **: cannot register existing type `GConfClient'


Panic, panic. What to do? Google ... :)

I had try several methods, read /usr/port/UPDATING, `portupgrade -varR -PP`, etc. FreeBSD only like the hard way `portupgrade -vaR`. It means when you portupgrade the first time, firefox don't like one of it upgraded version dependency. Which package? argh... I don't know :/ . So, have to do the hard way, ask FreeBSD upgrade the ports by compile it from source, wait it finish compiling, cross your finger hopefully the blue screen that ask package option don't appear, bla bla ... 2 days fighting with this, then my firefox is alive back, YEY!

tips: GConf involved with GNOME. Give `portupgrade -vPP libgnome-2.10.1` a try before `portupgrade -vaR` is a GOOD idea.

While compiling port, the FreeBSD give me this error:
ad0: timeout waiting to issue command
ad0: error issueing READ_DMA command
g_vfs_done():ad0s1f[READ(offset=29776416768, length=12288)]error = 5
vnode_pager_getpages: I/O read error
vm_fault: pager read error, pid 71516 (rtorrent)
ad0: TIMEOUT - READ_DMA retrying (1 retry left) LBA=61351999
ad0: TIMEOUT - WRITE_DMA retrying (1 retry left) LBA=62304671
ad0: TIMEOUT - WRITE_DMA retrying (1 retry left) LBA=62311103


Please don't tell me that you FreeBSD sucker cause my 80G, WD harddisk failed.

OK, stop ranting about FreeBSD.

Hey! Tab Mix Plus is COOL, recommended.

13 April 2006

Why lah UNO hate me?

I HATE this line:
Error (<class conversion.com.sun.star.lang.IllegalArgumentException at 0xb7bc8d1c>) during conversion:URL seems to be an unsupported one.

Because of this line, I'm keep whining for whole day!

I want OpenOffice convert my document to PDF using UNO. Works perfectly in my development box, but when using different box it don't like me. Hate deployment, hate hate ...

I wish that I'm get paid by the line :D , so I can apply this cheat in my code:
If Request.QueryString("source_url") = "" Then
strRedirect = strRedirect & "&verify=1"
If Request.QueryString("process") = "1" Then
strRedirect = strRedirect & "&process=1"
End If
Response.Redirect(strRedirect)
Else
strRedirect = strRedirect & "&verify=1"
If Request.QueryString("process") = "1" Then
strRedirect = strRedirect & "&process=1"
End If
Response.Redirect(strRedirect)
End If

12 February 2006

Why REST?

This is about Representational State Transfer not rest, verb.

Quote from ajaxpatterns:

" Witness the the debacle caused by the Google Accelerator interacting with non-RESTful services in mid-2005. The accelerator jumps ahead of the user and prefetches each link in case they should click on it (a non-Ajaxian example of Predictive Fetch). The problem came when users logged into non-RESTful applications like Backpack. Because Backpack deletes items using GET calls, the accelerator - in its eagerness to activate each GET query - ended up deleting personal data. This could happen with regular search engine crawlers too ... "


REST compared to RPC

08 February 2006

Where should define database schema?

Where should define database schema? in python (hint: django) or DDL.

Jonathan Ellis explain why schema definition belongs in the database. Yes, why reinventing the wheel create another database schema in .py (hint: django). Runtime introspection is good idea (hint: sqlalchemy, pydo).

After read Adrian Holovaty (hint: django) comment "Cache that, man. Cache it." my eyes wink wink ...

p/s: Nesting UnitOfWork in a Database Transaction seems more interesting compared to adodb CompleTrans()

12 January 2006

Short memory problem

My pair programming partner always complaint that I have bad short memory.

Is it because of my foods? :D

After read article, 12 Steps to Better Code, point #8, I guess I found the right answer.

... Productivity depends on being able to juggle a lot of little details in short term memory all at once. Any kind of interruption can cause these details to come crashing down. When you resume work, you can't remember any of the details (like local variable names you were using, or where you were up to in implementing that search algorithm) and you have to keep looking these things up, which slows you down a lot until you get back up to speed.

28 December 2005

Java is portable?

Snippet for a java code:

public static MultipartRequest createMultipartRequest (HttpServletRequest req)
throws IOException
{
[SNIP]

// Create a temp directory for the attachments
Runtime.getRuntime().exec ("mkdir -p " + Constants.UPLOAD_PATH);

File check = new File (Constants.UPLOAD_PATH);

[SNIP]

}


What wrong with this code? The answer is, this code is not portable, i.e. doesn't work on Windows. Nothing wrong with the Java, the problem is the programmer itself. :D

I got this snippet from a discussion in The Daily WTF.

25 December 2005

Mailmerge in openoffice 2

In my head, to do mailmerge we need template and datasource. Place the mail merge field in the template and point the field to appropriate datasource field/column.

I spent this christmas evening with trying a script to mailmerge using pyuno, found in the openoffice forum. What I want to do is, produce a single openoffice file after mailmerge from a datasource(a csv file). I manage to do it after modify the code. Hooray!

I had refer to the api, and read a java code snippet.

What annoying me is when export the merged file to pdf, extra unwanted blank pages will be produced for odd-numbered page. Let say I have 1 page template then want to mailmerge with 3 set of data. The result is 5 pages of pdf. The second and fourth page is fill with unwanted blank page. I had tried using openoffice 2 in my Windowx XP box and FreeBSD 6.0 box, both produce same result. Is it a feature/a bug? What I know, this really annoy me :(

Some of openoffice users also complaints about memory usage for mailmerge.

Actually, I had implemented mailmerge using another approach. Modify the openoffice xml file (to be specific, modify content.xml) using ooopy. Although my script able to do the mailmerge, it really painful to get it work. Manipulate openoffice xml using dom really make me headache. No benchmark for these two approaches, what I want is just to mailmerge. Duhh.

13 December 2005

Merge arrays in php

The short answer is function array_merge from php manual.

Let say I have 2 arrays to merge:

$a1 = array('key1'=>'val1', '33'=>'dummy_value');
$a2 = array('choose_one'=>'');
$result = array_merge($a1, $a2);

What my expected result is:

array('key1'=>'val1', '33'=>'dummy_value', 'choose_one'=>'');

Right? Emm... my expectation is wrong, the actual result is, when print_r($result):

Array
(
[key1] => val1
[0] => dummy_value
[choose_one] =>
)

What's wrong? After re-read the fine manual, the following line interest me:

Don't forget that numeric keys will be renumbered!

What? I put the key as '33' (with quotes), that should be string. Emmmm... no idea. I am suck or php suck?