Getting Started with OneAuth Bundle

Anyone who has dealt with OAuth, OAuth2, XAuth and OpenID would agree that it’s a great approach but hard to code with. For example, if I choose to integrate my application with Twitter OAuth I probably can choose 1 out 5 libraries. What if I now need to integrate with Facebook? or Github? Would you want to have a library for each provider?

The problem has later solved in Rails, with OmniAuth and now ported over to PHP (FuelPHP) Land as NinjAuth Package. This is great! However since I already moved from FuelPHP to Laravel I figure Laravel need some OAuth love too and decide to port NinjAuth Package into OneAuth.

Continue reading

That awkward code

<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

That awkward moment when you browse a prospect employer and you see this on their website.

Just crashed a browser today

Check out the code below, a simple JavaScript code:

var Lists = ['hello'];

for (var i = (Lists.length - 1); i--; ) {

Working fine? Yes but what happen when we change var Lists = [];. It seem that for (var i = length; i--;) would only stop at zero ONLY when the length is greater than zero.

Lesson learn, always test your code and assuming is root of evil.

dispatchMethod() WTF!

It might just be me but I really don’t find the logic of these code.

Taken from

public function dispatchMethod($method, $params = array()) {
    switch (count($params)) {
        case 0:
            return $this->{$method}();
        case 1:
            return $this->{$method}($params[0]);
        case 2:
            return $this->{$method}($params[0], $params[1]);
        case 3:
            return $this->{$method}($params[0], $params[1], $params[2]);
        case 4:
            return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
        case 5:
            return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
            return call_user_func_array(array(&$this, $method), $params);

Just another PHP coder.