01 December 2007

Turn VIM omni completion ON

Turn omni completion feature by put this in vimrc.
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete


Default vim turn off this feature. And here to set ctags

ctags -R -f ~/.vim/qttags /usr/include/qt3

:set tags +=~/.vim/qttags

03 November 2007

Muslim prayer times by web scraping

Here I'll show how to get Muslim pray times by web scraping. Web scraping is one of the methods to implement mashup.


<?php

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.e-solat.gov.my/solat.php?kod=sgr03&lang=ENG');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer)) {
print '<a href="http://www.e-solat.gov.my/">Prayer Time</a>';
} else {
$waktu_s = array('imsak', 'subuh', 'syuruk', 'zohor', 'asar', 'maghrib', 'isyak');
$w = array();
foreach ($waktu_s as $waktu) {
$w[] = "<tr.*?>.*?<td.*?>.*?$waktu.*?<\/td>.*?<td.*?>.*?(?P<
$waktu>\d?\d:\d\d).*?<\/td>.*?<\/tr>";
}
$t = join(".*?", $w);
$regex = "/<table.*?>.*?$t.*?<\/table>/si";
$result = "";
if (preg_match($regex, $buffer, $matches)) {
$result = '<table border="1"><caption>Kuala Lumpur</caption>';
$result .= '<thead><tr>';
foreach ($waktu_s as $waktu) {
$result .= "<th>".ucfirst($waktu)."</th>";
}
$result .= '</tr></thead>';
$result .= '<tbody><tr>';
foreach ($waktu_s as $waktu) {
$result .= "<td>".$matches[$waktu]."</td>";
}
$result .= '</tr></tbody>';
$result .= '</table>';
}
print $result;
}

?>


Example of output as below:
Kuala Lumpur
ImsakSubuhSyurukZohorAsarMaghribIsyak
5:295:396:5813:0016:1918:5820:09


I'll leave to you as exercise to show the date of prayer times, GMT and qiblat direction.

31 August 2007

use onmousedown instead of onclick

Joseph Smarr give great talk about javascript performance, recommend to watch it. I'm not big fan of optimization, but in web application, load time (performance) matter. It interesting he claim that better performance when using onmousedown instead of onclick. And combine to setTimeout trick, setTimeout(func, 0), I can feel the difference in his demo. He also mention some other tips to improve javascript performance, so, watch it :-)

Hey, A Pattern Library for Interaction Design -- they update their website contents

03 August 2007

vim: Don't use escape key!

Esc is exactly equivalent to control-[ 
(that's the control key plus the left square bracket key)
For quite long time I hit Ctrl+c instead of Esc (mentioned in http://helmi-blebe.blogspot.com/2007/07/autodesk-mapguide-jakarta.html ), until vim7. Ctrl+c in vim7 don't behave Esc when indent lines of code using visual mode blockwise (:h blockwise). Also Ctrl+o in insert mode will switch to normal mode for one command only and automatically switch back.

Heh, learn 2 new tricks in vim today and still learning.

Somehow, the toolbar that supposed to assist compose this blog (in www.blogger.com) don't want to appear in my browser. Anyway, I compose in gmail instead.

http://vim.wikia.com/wiki/Don%27t_use_the_escape_key%21

22 July 2007

Autodesk Mapguide - Jakarta

Last week, went field trip to Jakarta for Mapguide training. The training quite boring for me since I familiar most of it, but at least, I learn properly.



You can use php to program the mapguide and can use ajax too. It quite easy for beginner, and have good API for advance user to extend it. In theory, you can implement your own ala google maps for Malaysia. My hands itchy now to programming, but where is public data for Malaysia???

Tip for vim user: You can also use 'Ctrl+C' to exit Insert Mode instead of 'Esc'. So keyboard layout user like below don't worry to mistakenly hit 'Power' key instead of 'Esc';

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