Thursday, October 7, 2010

Zend Debugger > XDebug makes PDT > Netbeans

Displaying variable values - including breakdown values of their attributes - of current scope has been the most important thing to my debugging practice.

AFAIK, Netbeans PHP IDE only supports XDebug. XDebug is known to be unstable with watches and balloons (and I have had too many crashes experience) and having this defect yields Netbeans useless IMO.

I use PDT together with XDebug over the past 3 years of active PHP development and for the past few days (finally) I started using Zend Debugger. Then I realized that it has the "problem" of only displaying variables in scope (e.g. function scope), meaning, global variables and $this will not be shown, due to usability and performance concern.

The fix is pretty simple (after reading this forum response), just place watches if you want to monitor out-of-scope variables.

Saturday, September 11, 2010

回张木钦道德论

"你有没有感受到,当前我们的社会流行的“比道德更高价值”的东西,就是“反国阵”?道德虽然好,但是还有更好的,就是打倒国阵。打倒国阵是政治目的,不是道德,却是比道德更高的价值。"

"我们是不是即将进入一个只有政治目标,没有道德价值的世界?"


在一个道德已被滥用的社会,已被国阵扭曲和掩盖的社会,你可否有反问道德是否还存有其被等量齐观的价值?

革命,看重的是议程,被应许的是人权与未来。若像你那一般高谈道德,美女间谍就永远派不上用场了。

这个星期我看了《V煞》整一百遍,在一个人民被贬低,媒体,司法与立法被控制的国家,政权的倒台与改变需要人民的策划与响应(当权者和汉奸最怕)。

  艾维: You really think blowing up Parliament's
going to make this country a better place?

  V: There's no certainty, only opportunity.

暗杀与爆炸听来血腥,毫无道德,但爆响声中却带来了希望与未来。

Monday, May 17, 2010

Wee, Prove It

“I didn't jump ship. I am on my own and now I have more time to concentrate on my constituents.

“My constituents will see whether what I did was right. I am certain I will be forgiven by history and the next generation,” he added.

It's too early still for me to say that you had done practically nothing for my district, yes, my freaking district.

I still remember on a Wednesday rainy night, me, a very a young guy at that time attended your cerama in celebration of your move to PKR. Then, a meet-up once speaking about a portal for Wangsa Maju.

I remember you claimed that in 30 days Wangsa Maju/Setapak will see a change. I saw a small protest on removal of protected trees due to road expansion. I saw you hitting on Yew for the Platinum condominium and land matters. Other than that, I am still awaiting the change.

Prove it.

Monday, February 22, 2010

Some Groovy Class-Loading Notes

Was trying to load a resource (*.properties) from the class-path and as you know, class loading can be a PITA at different enviroments (IDEs, build tools, tests, containers).

Here's the snippet I used, ran with Maven and Eclipse IDE, target/test-classes is in the class-path.
String name = "aflexi.itest.properties"

// System CL
println ClassLoader.getSystemClassLoader()
// Uses system or bootstrap CL
println ClassLoader.getSystemResource(name)

// Caller CL
println ClassLoader.getCallerClassLoader()
println ClassLoader.getCallerClassLoader().getResource(name)

// Class's class loader. Perfectly fine in both places
println getClass().getClassLoader()
println getClass().getClassLoader().getResource("aflexi.itest.properties")

// Doesn't work anywhere, the CL is the one of previous, but the name will be resolved as "net/aflexi/cdn/test/itest/aflexi.itest.properties"
println getClass().getClassLoader0()
println getClass().getResource("aflexi.itest.properties")

// Doesn't work either. Using Groovy's calling class.
println ReflectionUtils.getCallingClass()
println ReflectionUtils.getCallingClass().getResource("aflexi.itest.properties")

And here's the result:

Expression / Class LoaderTest 1: InstanceTest 2: InstanceTest 1: Found Resource?Test 2: Found Resource?
ClassLoader.getSystemClassLoader().getResource()sun.misc.Launcher$AppClassLoader@19134f4sun.misc.Launcher$AppClassLoader@19134f410
ClassLoader.getCallerClassLoader().getResource()sun.misc.Launcher$AppClassLoader@19134f4org.codehaus.groovy.tools.RootLoader@8965fb11
getClass().getClassLoader().getResource()groovy.lang.GroovyClassLoader$InnerLoader@14177f3groovy.lang.GroovyClassLoader$InnerLoader@dc043511
getClass().getResource()groovy.lang.GroovyClassLoader$InnerLoader@14177f3groovy.lang.GroovyClassLoader$InnerLoader@dc043500
ReflectionUtils.getCallingClass().getResource()class cuke4duke.internal.groovy.GroovyLanguageclass groovy.ui.GroovyMain00

Take note that, getClass().getResource() uses the same CL instance (otherwise system CL) with getClass().getClassLoader().getResource(). The reason why it failed is that, it resolves the name of the properties file with package name, i.e. aflexi.itest.properties to net/aflexi/cdn/test/itest/aflexi.itest.properties.

Saturday, February 20, 2010

POGO + Singleton + Mixin

Something worth sharing (or probably you may suggest me with a better solution) about injection/Mixin on Groovy's object that is being a singleton.

Let's start off with an example. I have a Users class with a private singleton, e.g.
@Mixin(Whatever)
class Users{

  private static Users instance = new Users()

  def doGetUserByEmail(){}

  static def getUserByEmail(){
    instance.doGetUserByEmail()
  }
}

Unfortunately, this is not working as Users.instance is constructed within the class before Groovy does more thing with its interpreter (at this point, I still have limited knowledge about Groovy, but that's the basic idea).

So I let Groovy to handle the construction of the singleton for me, with @Singleton - resulted with the same effect.

However, @Singleton(lazy = true) solves the problem, as the late/lazy instantiation happens on a "ready" POGO class.

Thursday, December 17, 2009

3 Spring Stuff Worth Sharing

Firstly, Spring 3.0.0 is released not more than 2 days ago. Juergen (if you have the habit of reading source code, you shall know him) blogged about the features at Spring Framework 3.0 goes GA. I am particularly interested to explore more (possibly make changes to my existing project) in the area of @Configuration, SpEL, REST, OXM and validation.

I also upgraded my project this morning, with less than 10 lines of code changes to switch the plug from 2.5.6 to 3.0.0 - the compilation errors were some casting issues of generics type - yes, Spring 3 is now compile-time type safe. If you use Maven, you may want to read about the pom and repository configurations here.

Second-and-thirdly, below are some notes I wrote down in company's intranet. :)

Spring Resolves Dependencies and Initializes Accordingly, Not You

Before that, I thought implementing the Ordered interface could impact the order of which beans shall first be loaded. Then I realized, it doesn't work. Ordered is used.. as far as I can tell right now, two on top of my head: during invocation of Bean and BeanFactory post processing and the order of Advices - just not Bean initialization!

So how does it really work (for which bean to be loaded before any other)? One thing that I found (or maybe really just one): dependencies - bean references and @DependsOn/depends-on. When the BeanFactory preinstantiates the beans, it resolves its dependencies (via BeanDefinitionValueResolver) and eventually the beans who are referenced/dependent by others will be initialized first.

Do take note that, you rarely use @DependsOn unless you have static (*ugh!!*) references. For my case, HibernateSessionFactoryBean depends on SubEntityManager and those enums in it are accessed via the static (*ugh!!*) method SubEntityManager.getInstance() by the SubEntityUserType.

Spring Shutdown Hook and Unit Testing

A Spring ApplicationContext has a close() method, things like HibernateSessionFactoryBean will only be destroyed when the context is destroyed via the close() method - which is triggered by shutdown hook. See AbstractApplicationContext.registerShutdownHook(). So what is important here to know is, if you are running unit tests, a series of them, destroy can only happen when the shutdown hook is called.

Here's an example, I was running two test fixtures but the first one didn't shutdown until the whole test execution exited.
[12-16 16:26:45] INFO  GenericApplicationContext [Thread-4]: Closing org.springframework.context.support.GenericApplicationContext@1923ca5: ...startup date [Wed Dec 16 16:26:42 MYT 2009]; root of context hierarchy
[12-16 16:26:45] INFO  GenericApplicationContext [Thread-3]: Closing org.springframework.context.support.GenericApplicationContext@19b5217: ...startup date [Wed Dec 16 16:26:34 MYT 2009]; root of context hierarchy
[12-16 16:26:45] INFO  HibernateSessionFactoryBean [Thread-4]: Closing Hibernate SessionFactory
[12-16 16:26:45] INFO  HibernateSessionFactoryBean [Thread-3]: Closing Hibernate SessionFactory

Saturday, November 7, 2009

Wireless Network disappeared after Ubuntu 9.10 (Karmic) upgrade

Upgraded to 9.10 this morning but funny thing was - wireless networking wasn't working anymore - ath_pci module is gone from the release.

Fixed by loading the ath5k module, as suggested by the ThinkPad wiki. You can append it to /etc/modules for it to be automatically loaded.