Monday, December 10, 2012

How to time windows services using "Scheduled Tasks"

In short, you need to use the program "sc" to communicate with the services. So in a "Scheduled Task" you would put the run command as:
C:\WINDOWS\system32\cmd.exe /c sc start tomcat7
To start tomcat and of course:
C:\WINDOWS\system32\cmd.exe /c sc stop tomcat7
To stop tomcat. Fin.

Tuesday, November 27, 2012

Consumer and producer

One of the great advantage of living in the digital age is that it is much more cheaper and easier to become a producer. And by producer I mean producing any kind of content at all. Not just films but also photos, writing and others.

Almost any tom, dick and harry can pick up a computer, register himself on the internet and now he's a published writer read by hundreds or even millions or maybe nobody. Point being is that it is that much easier to put your ideas out there and effectively become a producer.

But then there's another side of the coin. All these contents have to be viewed by someone, liked by someone,  shared by someone. So now it becomes a choice for every single person,  do I want to be a consumer or producer. And most of the time the easy choice is to just be a consumer. Just spend your eyeballs time. Just browsing around, reading around, sharing around. Sometimes even when you have this great idea you think would be good to publish and share with the world,  you tend to put it off. Until finally it doesn't matter anymore, and there's an opportunity lost.

Maybe it's time for me to change.

Wednesday, November 14, 2012

Writing down my thoughts in public

Haven't written anything for a long time already. So just punctuating the silence with a burst of wacha...

Saturday, November 3, 2012

Update to "Solat Malaysia"

Alhamdullillah finally I have done it. I have finally took enough time to upgrade the "Solat Malaysia" app to save the solat schedule for a whole month from e-solat.gov.my. So now it would update to the current day schedule even though the site is currently down (which it comes down a lot, and people start blaming the app for not updating). To be fair, it could be that the app was "part" of the reason the website kept on going down considering that there was thousands of "Solat Malaysia" users at least updating their app every single day (and every single solat schedule app that uses the same update model). It kept on going down so many times that I even though about proposing to JAKIM to let me have a go at properly setting up their server to cache, balance and handle such traffic for free. But never got round to that and finally just upgraded my own software to play nice instead.

Apart from the all important downloading the whole month schedule update, the azan works properly now too. At least properly on my experia active. Before this it relied on a running service to check when it was time to sound the azan, which usually the service gets killed and never start again, causing the azan to not happen. I've finally fixed it to properly set and use an alarm manager and thus there is no background service which might be killed to rely on. Truth be told I have no idea what I was thinking early on when I used the service approach. It is quite silly.

Other things which have improved a bit (but just a bit though) is I spent a little time on streamlining the process to change area and a bit of cosmetic touch up. Finally I've actually aligned the text in the widget.

And as always, the most important part for me from "Solat Malaysia" is learning how to program for the android and it's all still available for the public at https://github.com/abdza/solatmalaysia. Some of it like I said is a little bit embarrassing (like why on earth did I use a service for the azan) but it's also encouraging that I am actually improving my android coding and understanding. Finally I can put this to rest for a while and concentrate on my other projects. Thank you all for the support you gave even when the software really sucked and even I couldn't recommend it to my friends. But now I finally can recommend it to my friends, so Shazman, if you're reading this, install it NOW... :P

Saturday, September 1, 2012

Using CTreeView with NestedSetBehavior in Yii

Getting this whole thing to work took me a few days of experimenting. Finally I've got it working. Posting it here hoping that it would save others some time and if I need it back in the future.

The Yii nested set behavior extension can be found at http://www.yiiframework.com/extension/nestedsetbehavior/.

Download the zip file and then extract it into the "app root"/protected/extensions/NestedSetBehavior folder. Make sure that the NestedSetBehavior.php can be found at "app root"/protected/extensions/NestedSetBehavior/NestedSetBehavior.php.

Then modify the model file which you want to use the behavior with. For example, I have a model Areas and the file "app root"/protected/models/Areas.php. Add to the mentioned file the following lines:
 public function behaviors()
 {
  return array(
   'nestedSetBehavior'=>array(
    'class'=>'application.extensions.NestedSetBehavior.NestedSetBehavior',
    'leftAttribute'=>'lft',
    'rightAttribute'=>'rgt',
    'levelAttribute'=>'level',
    'hasManyRoots'=>true,
    'rootAttribute'=>'root_area',
   ),
  );
 }

The table for the model has to have the lft, rgt, level, and root_area field. All the field of type integer. The hasManyRoots determine whether the behavior should support more than 1 root per table, and so if it is true, the root_area will contain the root node id.

Then you need to modify the actionCreate and the actionUpdate method of the controller to use $model->saveNode(); rather than $model->save();

And that should be it to get nested behavior working. But.... how would you display it using the CTreeView widget? And how would you update it using that?

To display the tree, in the view, it is as simple as:
$this->widget('CTreeView', array(
 'id'=>'treelink',
 'data'=>$treedata,
)); 

But to get the $treedata? I've added the following 2 function into the model file.
 
public function treechild($id)
 {
  $curnode = Areas::model()->findByPk($id);
  if($curnode){
   $childrens = $curnode->children()->findAll();
   if(sizeOf($childrens)>0){
    $out = array();
    foreach($childrens as $children){
     $currow=['id'=>$children->id,'text'=>$children->name,'children'=>$this->treechild($children->id)];
     $out[]=$currow;
    }
    return $out;
   }
   else{
    return null;
   }
  }
  return null;
 }

 public function treedata()
 {
  $roots = Areas::model()->roots()->findAll();
  $out = array();
  foreach($roots as $root){
   $currow=['id'=>$root->id,'text'=>$root->name,'children'=>$this->treechild($root->id)];
   $out[]=$currow;
  }
  return $out;
 }


The treedata function would iterate over all the root nodes in the table and the treechild function would iterate over all the child nodes so that the data would be put into a properly formatted data structure. The CTreeView require an array with at least the id field for id, and text field to be displayed in the tree.

And so the controller is as simple as:
  $this->render('tree',array(
   'dataProvider'=>$dataProvider,
   'treedata'=>Areas::model()->treedata(),
  ));


But that's only good for displaying the tree, to fully modify the tree (add new nodes and updating existing nodes), I need to add the following javascript to the view:
Yii::app()->clientScript->registerScript('clickscript',"
$('#treelink li').on('click', function(event) {
 event.stopPropagation();
 $('#create').attr('href',$.param.querystring($('#create').attr('href'),'parent_id='+$(this).attr('id')));
 $('#edit').attr('href',$.param.querystring($('#edit').attr('href'),'id='+$(this).attr('id')));
});
",CClientScript::POS_READY);


And the following menu (do note that I'm currently using the default layout which displays the menu widget):
$this->menu=array(
 array('linkOptions'=>array('id'=>'create'),'label'=>'Create Areas', 'url'=>array('create')),
 array('linkOptions'=>array('id'=>'edit'),'label'=>'Edit Area', 'url'=>array('update')),
 array('label'=>'Manage Areas', 'url'=>array('admin')),
);


And in the create view:
if(isset($parent_id)){
echo $this->renderPartial('_form', array('model'=>$model,'parent_id'=>$parent_id)); 
}

And in the _form view:
if(isset($parent_id)){
 echo CHtml::hiddenField('parent_id',$parent_id);
}


And in the actionCreate method in the controller, added after the "$model->attributes=$_POST['Areas'];" line:
   if(isset($_POST['parent_id'])){
    $parent = Areas::model()->findByPk($_POST['parent_id']);
    if($parent){
     $model->appendTo($parent);
    }
   }


And the render line would be changed to:
  $this->render('create',array(
   'model'=>$model,
   'parent_id'=>$_GET['parent_id'],
  ));


So what the whole thing actually did, was to bind the li items in the node tree to change the create and edit link when clicked. The create link will be changed so that the currently selected node id set as parent_id and the edit link is changed so that id is the currently selected node id. Once the create method received the parent_id variable, it would be passed on all the way into the form. And once saved, if the parent_id actually exists and points to a real node, the new node would be set to append to the aforementioned node. There isn't much change for the update method.

And that folks, is how you would use the CTreeView with the NestedSetBehavior.

Sunday, July 29, 2012

Thoughts on Linus "F*ck you nvidia" video

I FINALLY took the time to actually see the whole video. And I find the whole video quite thought provoking. I would admit unabashedly that Linus is a hero for me. I look up to him and find the way he thinks to be interesting and worthwhile my time to actually get familiar with. That said, I'm going to talk about some of the highlights which I found interesting (apart from the f*ck nvidia part which I think is just Linus being Linus, not much to learn from there, except for maybe if I'm running Nvidia the company).

It is interesting for me that his level of programming is not just a passion and hobby thing, but all the way up to the level of a habit. He programmed a lot of his own tools. And Linux was originally written just because he couldn't afford Unix and he thought it wouldn't be very hard to write his own Unix. That is just awesome. And early on he would even program directly in machine code by doing the assembly by hand, and just output the machine code directly. Talk about bare metal.

He talks about how open sourced software is able to take advantage of the different kind of strength of people. People have their own interest and able to contribute what THEY are interested in. People did what they were good at doing. A funny part of this was that he said he have never done any web programming before. There are MIS people for that. He wasn't interested in that. He was interested in PROGRAMMING.... LOL.. I write web apps for a living, but I also agree with him. I don't feel what I'm doing is real programming. For me if you're not compiling your source code to machine code, and running it on bare metal, you're not really programming. You're just scripting. Fancy scripting certainly, but just scripting none the less. Of course that's just my view it.. :P

He also talks about why Linux has not taken over the desktop and basically it is down to getting it pre-installed for the users because normal users do not want to install their own OS. He feels that the biggest hope for Linux on the desktop might be on Google's Chrome Book. Sadly this is very true. Unless someone can produce extremely cool hardware that people just drool over it without even thinking it's running Linux, desktop Linux ain't gonna happen. At least not to most normal people. I've been using Linux as my main desktop for almost a decade already. I KNOW it's ready for the desktop. But then again, I'm a user that would install my own OS.

One of the things that I really like about Linus is how he seems to be able to say whatever he wants and never have to be sorry about it. It is so different from me. A lot of my regret comes from things and projects I didn't shut down very early on only because I am trying to be polite. But when the going gets tough, I couldn't deliver. People get dissapointed and I feel regret for not being fortright early on.

Linus is very proud of git. He doesn't feel Linux was his own design because Linux was just following Unix, but git was his own design. And he's very proud of it. For most of my own projects, I do use git. But at work, we started out using mercurial from early on, because we had to work on windows and at the time, mercurial would actually outperform git on windows. And if not anything else, tortoisehg is much more nicer than the tortoisegit. Not sure how things are now though because I haven't looked into this aspect for years already.

One last thing I'd like to point out, is that Linus is not really a big fan of vision statement kind of thing. I find this very interesting. Because another personal hero of mine, my own father, also does not believe in the whole vision statement thing. You should have a sort of general idea of where you're heading, but the most important thing is just to get down and work on it. You have to be responsible, and as Linus says, passionate about it enough that you just keep on working on it, regardless of whatever vision statement you have.

I like offending people because I think people who get offended should be offended - Linus Trovalds. :)

Friday, June 8, 2012

Haven't blogged anything for a long time

I haven't blogged anything for a long time. Have so many things to say. Learned so many things to share. But in the end didn't allocate any time for it. Oh well...


Monday, February 13, 2012

Where has the love gone?

I am a bit late about this as I have only read it on twitter a few minutes ago, but the case of Hamza Kashgari really makes me sad. My heart aches every time something like this happens and I feel so sorry for the state of the ummah currently. The man said a few things on twitter regarding the prophet, and now it seems that his life might be on the line.

It makes me sad whenever people make fun of the prophet, the muslims rather than teach how the prophet was really like and his contribution to their lives and in doing so makes them understand why it is so disrespectful to make fun of such a person, choose to collectively call for murder of these people. Early in the days of his da'wah, people made fun of the prophet in even worse way, they called him even worse things, they put trash in his path, they even flung camels dung and intestines on him while he prayed. But when he finally won the conquest of Mecca, did he do the same to the people who hurt him so? No, he forgave them. When the people of Ta'if sent out their urchins and stoned him till he fled from them bleeding, and the angles were willing and ready to crush the town with mountains, did he approve of it. No, he just prayed that maybe their next generation would be muslims. A man who his companions say was never angry on his own account. Such a man, do you think if he was still amongs us today, would want us to react this way to such small and trivial things? I believe that he would rather not.

You can go here and here to see exactly what did he tweet. In his tweet he did not call the prophet any names, or associate with him any bad behaviour or anything. At most you can say was that he called the prophet a man, a normal man. And that was all that the prophet claimed he was. He was a normal man. With a message from Allah. And maybe that's the part where the contention is. With words like 'do not like the halos of divinity' and 'I shall speak to you as a friend, no more', people jump to the conclusion that he has renounced his religion. He even apologized and made shahadah and still people howl for his blood. Personally, I think these are extremely bad examples the muslims are making. You are not making the case of proving a 'most merciful and most forgiving' God by killing people. You are not making the case that if the muslims ruled the land, all the people will be treated fairly and justly with due respect and dignity no matter what they believe in. You are not making the case that Islam is the highest and none is higher because you are acting like you need to "protect" Islam and that it's followers are just dumb sheep that would be easily confused because their faith is so complicated.

On his death bed, the last words of the prophet was 'ummati, ummati, ummati' (My ummah, my ummah, my ummah). So concerned was he for his ummah, that even in the very last moment of his life, he was still thinking and worrying about them. He had such love for this ummah. He gave up everything and underwent countless challenges so that this beloved ummah would be properly guided and would find peace and safety in this world and in the next. Please do not bring shame to the prophet this way and make the world think that he was a lesser man than he actually was.


p/s: ummah means people. As the last messenger of Allah, Muhammad's ummah was the whole of mankind.

Wednesday, February 8, 2012

Running Android SDK on Arch Linux x86-64

A funny thing happens once you've downloaded it. Running ./adb in the platform-tools folder will yield a command not found error. But it's right there in clear view. Why wasn't it found. The answer seems to be because the android sdk itself is only 32bit thus you would be required to enable the multilib repos. Follow the instructions here on the things you need to do after you have enabled multilib support, namely you need to install the multilib-devel package which would replace the base-devel package.

Saturday, January 28, 2012

Ice Cream Sandwich on the cheap

My son keeps on playing with my htc phone until the batteries run dry. People can barely contact me because if my son answers the phone he doesn't want to pass it on to me. What's a techie to do? Why, get his son something else to play with of course.. :P So I scoured the low yatt plaza looking for something that would be cheap enough that if my son breaks it, I wouldn't mind, but fast enough that he can play his games on it. After searching high and low, the best I could find was the android pocket pc. It's basically just a very cheap android tablet that comes with a casing with a keyboard in it. Funny thing is, the keyboard is usb, the tablet only accepts mini usb (not even a micro usb) and so they also give an adapter from usb to mini usb. It costs rm 699 a pop. If it's still running by the year end, I'd consider that already as ROI. They claim the cpu is 1.5 Ghz and memory 1 GB. I haven't installed any diagnostics software to make sure, but the internal storage is 1 GB just by looking at the application management settings. It doesn't have a back facing camera to take any pictures, but it does have a 1.3MP webcam you can use to video chat or something. And it comes with a somewhat customized android 2.3 (customized as in it looks like a tablet interface, something like the original galaxy tab I think).

So I just had to do it. This morning I was already ready to try installing ICS on it. Mmmmm... manufacturer... none that I can find.. model.. oh err... damn these cheap things... How on earth am I going to find info on how to go about flashing it and all. Finally I just googled the build number, and I come to this gem of a post..

So basically the steps are, download the ics image either from:
MOMO9c ICS v1
build #1
Model 97FC
Kernel Version 3.0.8+ inet_dada@Inetsoftware #1 (without market, still has bug)
Build Number 97F1-D1-H2-H01-N412-20120105
- Momo9c ICS v1
Kevin Custom build 12
Model 97FC
Kernel Version 3.0.8+ inet_dada@Inetsoftware #12
Build Number 97F1-D1-H2-H01-N412-20120111
- Momo9c ICS v2
build #15
Model MOMO
Kernel Version 3.0.8+ inet_hxj@Inetsoftware #15
Build Number 97F2-D1-H1-H02-1553-20120113

I tried both the #12 and #15 build. Both seems to work fine.
After the image is downloaded, download the LiveSuitPack.
Run LiveSuitPack_v1.07.exe first,
then run LiveSuit.exe. (Yes, I did this in windows. Since it involves hardware, I would highly not recommend you try it in wine or something).
Running LiveSuit.exe will automatically run the wizard, if not click the third icon (the gears).
Click on "Yes",
then "Upgrade Mode",
then "Format",
then "Next",
then "Yes",
browse to the image you downloaded,
click "Finish".
Once that is done, there will be a progress bar but does not move. Now for the tablet.

First, switch off the tablet.
Then press the + volume button,
while keeping it (the volume button) pressed, connect the usb cable to the computer,
press the power button 6 times,
then let go of all the button. Fuh...
I had to go here to find out that.
Once that is done, the dialog box to confirm will pop up 2 times. Answer yes for both, and soon the progress bar will start moving.
Once it's finished, disconnect the table, turn it on, and there you have it, ice cream sandwich on the cheap.

Note about the build #15, it's in Japanese.
So you should first go to the settings page (flick the screen to the left to go to the pan on the right, it's the black box with control setting on it).
There choose the language options (it's the one with a capital A next to it),
click on the first option,
and select whichever english language you're comfortable in.
Then you can start playing around.
Both the build #12 and build #15 already has the market in it but I wasn't able to find the icon. What you should do is search for market, then you will find the market app. Install whatever you need.

Well, that's all for now. Time for me to keep on learning (playing) more about the ICS I've just downloaded.. :P

Haiya ala Solah