RSS Feed
  1. Team’s reaction to work

    January 27, 2012 by roguejs

    Here’s how we responded to our CTO’s announcement.

    PS: In case you’re wondering, this was staged. Not with our CTO’s foreknowledge though. :P


  2. My new bash prompt

    December 22, 2011 by roguejs

    Had some fun playing around with custom bash prompts, and managed to fix a bug resulting from my previous attempt. Here’s how it looks like right now:

    That’s right, that’s me flipping you the bird. smug

    Articles I read to make this happen:


  3. Now I know why MOSTI wants CPB 2011

    December 12, 2011 by roguejs

    TIL that the government have a bad habit of hiring complete morons to work on their websites. Things that the private sector seem to be immune from.

    Do this my friends, type mosti.gov.my into your address bar without the “www” before it, and press enter. Enjoy your infinite redirect loop. Now do this: click view source.

    <script language="Javascript">
    window.location = ''
    </script>
    

    Ready? HAHAHAHAHAHAHAHAHAHAHAHAH HAHAHAHAHAHHAHHAH HAHAHAHHAHAHAHA HAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHA HAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHAHAHAHAHAHAHHA HHAHAHAHAHAHAH AHHAHAHAHAHHA

    On a sidenote, if you are a Malaysian engineer, do read the latest draft of the incredibly stupid Computer Professionals Bill 2011:

    http://www.mosti.gov.my/mosti/images/stories/pdf/2011/ruu_bcpm_v17.pdf

    Edit: There is a document that is collated by IT professionals as we speak right now in preparation for tomorrow’s public hearing of the proposed act. Do join in the conversation!

    Edit: As of 14 Dec 2011, this problem has been rectified. Took them 24 hours to fix a one liner in htaccess. Good job!


  4. Awesome drawing programing online

    December 8, 2011 by roguejs

    Damn, I found this online drawing canvas and it totally kicks ass. In minutes with just my mouse, I created these:

    Some sphinx thing, and …

    A bird?

    Best part about this is that I’m no artist. No, seriously. Anyway, go check out this fun drawing tool!


  5. Malaysian Government trolling the IT industry?

    December 8, 2011 by roguejs

    Is our dear Malaysian Government trolling our IT industry with a bill to eventually prevent non degree holders from being employed, or forcing entrepreneurs to have professional certifications before being able to start a business?

    Bill Website

    Screenshot or it didn’t happened:

    Clicking on the “Feedback” button takes me to Google. What the fuck am I supposed to do? Google for “Morons”?


  6. OAuth is the future for us

    December 8, 2011 by roguejs

    In our latest rewrite of edgɘyo, we made a decision early in the implementation phase to rely on OAuth providers for login and authentication. Given that this is the 7th re-implementation of the same software, I’ve written/integrated 6 authentication already, and honestly speaking I’m quite tired of reimplementing the wheel.

    The gist is this – if you are operating a web service/app that is not seeking to create a brand new market or take over the world, integration should be the key to your app’s success.

    I would argue that Instagram would not have succeeded had it not integrated with Facebook; or that smartphones would be pointless had they not integrated with Twitter, Facebook, and other social services. Most users begin their internet life through a social service nowadays. It’s their window to the rest of the internet world, and to re-implement the whole authentication system would be foolish if your webapp is not an app that seeks to do that (as in, being the fulcrum of your user’s entire internet existence).

    As of now, we have integrated with Twitter, Facebook, Angel List, Github and Linked In, and planning to add in Google, Dropbox and Tumblr.

    This of course, creates an ecosystem issue where with so many providers to choose from, our users might forget what provider they initially logged in from.

    Organizing the OAuth spaghetti

    Our current solution is a 3 step process which we hope to mitigate this problem to an extend:

    1. Make users create a username and provide an e-mail address upon signing-up through any provider
    2. The system takes the username->email combo to check if there’s already another such combo registered with another provider
    3. If found, the user has the option to send a “Join Account” link to that user and e-mail address

    At this point the user can log in again using the original provider, and he will see a notification on his dashboard asking to join the accounts. Upon authorizing it, the user will now be able to log in via either accounts.

    Having said that, obviously our technical implementation is far more complex than just that.

    OAuth is ridiculously easy

    The real point of this article is that I personally believe OAuth should be part of every web developer’s toolkit. Implement a pet project using OAuth, try it out, deploy it, and know how to play around with the protocol. OAuth is the future, there’s no doubt of it.

    On my side, I absolutely love everyauth. It just works™. We implemented all our current OAuth providers easily in less than 2 hours, with the majority of time spent setting up app accounts in the respective providers rather than writing code.

    Here’s how our everyauth code looks like:

    'use strict';
    module.exports.make = function make(deps) {
        if (undefined === deps) throw new Error('No dependency injected');
        var auth = {
            callbackError : function callbackError(req, res) {
                res.redirect('/error/401');
            },
            touchUser : function touchUser(session, accessToken, accessTokExtra, metadata) {
                var db;
                db = deps.db;
                return { user : 'soggie' };
            },
            init : function init() {
                var eauth, config;
                eauth   = deps.eauth;
                config  = deps.config;
                // Setup github oauth
                eauth.github
                    .appId(config.github.appId)
                    .appSecret(config.github.appSecret)
                    .handleAuthCallbackError(auth.callbackError)
                    .findOrCreateUser(auth.touchUser)
                    .redirectPath('/dashboard')
                    .scope('user');
                // Setup linkedIn oauth
                eauth.linkedin
                    .consumerKey(config.linkedIn.consumerKey)
                    .consumerSecret(config.linkedIn.consumerSecret)
                    .handleAuthCallbackError(auth.callbackError)
                    .findOrCreateUser(auth.touchUser)
                    .redirectPath('/dashboard');
                // Setup twitter oauth
                eauth.twitter
                    .consumerKey(config.twitter.consumerKey)
                    .consumerSecret(config.twitter.consumerSecret)
                    .handleAuthCallbackError(auth.callbackError)
                    .findOrCreateUser(auth.touchUser)
                    .redirectPath('/dashboard');
                // Setup facebook oauth
                eauth.facebook
                    .appId(config.facebook.appId)
                    .appSecret(config.facebook.appSecret)
                    .handleAuthCallbackError(auth.callbackError)
                    .findOrCreateUser(auth.touchUser)
                    .redirectPath('/dashboard');
                // Setup angellist oauth
                eauth.angellist
                    .appId(config.angellist.appId)
                    .appSecret(config.angellist.appSecret)
                    .handleAuthCallbackError(auth.callbackError)
                    .findOrCreateUser(auth.touchUser)
                    .redirectPath('/dashboard');
            }
        }
        return auth;
    }
    

    Ridiculously simple eh? Sorry that I removed all line spacings in that code snippet. My markdown plugin doesn’t play nice with my syntax highlighter.

    Anyway, much love to OAuth, and the node community. Signing out now!

    PS: I noticed that most of the services I mentioned are all OAuth 2. The “OAuth” termed here is an umbrella term I use to refer to all OAuth (both 1 and 2) implementations in general.

    PSPS: I blogged further about 5 Reasons Why Startups Should Use OAuth in the edgɘyo blog too.


  7. Removing C-styled comments using Javascript

    December 2, 2011 by roguejs

    In the course of writing norris-json, I wrote a simple piece of code to remove C-styled comments from JSON strings, which should work just as well for any projects. It’s not perfect, and if I missed anything please open an issue in my github repo.

    function _removeComments(str) {
        // Remove all C-style slash comments
        str = str.replace(/(?:^|[^\\])\/\/.*$/gm, '');
        // Remove all C-style star comments
        str = str.replace(/\/\*[\s\S]*?\*\//gm, '');
        return str;
    }
    

    Check out the tests folder to see my test cases, and do let me know if there are cases that I did not manage to cover with them.

    Thanks!


  8. Console colors in node.js

    November 30, 2011 by roguejs

    After failing my google on how to crease a strict mode complaint way to do colors in the console/terminal, I finally solved the problem and hope to share my method with the rest of the internet.

    Coloring it the ANSI way!

    First, look at the ANSI escape code list, and find the exact effect that you want. Remember the code. Next, put it in your console.log(), and don’t forget the reset it after you’re done!

    var red, blue, reset;
    red   = '\033[31m';
    blue  = '\033[34m';
    reset = '\033[0m';
    console.log(red + 'This is red' + reset + ' while ' + blue + ' this is blue' + reset);
    

    The above, when run in the terminal, will give you:

    So there you have it, using ANSI escape codes to color your output in the terminal.

    Strict mode “fix”

    But wait! What happens when you add a “use strict” to your file? If you’re like me, who tries to code everything in strict mode, then you’ll run into this error message when you try to run your code:

    SyntaxError: Octal literals are not allowed in strict mode.

    This is because the “\0″ escape is no longer allowed under strict mode. So what do you do now?

    Well, the solution is surprisingly simple. Just replace “\033″ with “\u001b” instead:

    'use strict';
    var red, blue, reset;
    red   = '\u001b[31m';
    blue  = '\u001b[34m';
    reset = '\u001b[0m';
    console.log(red + 'This is red' + reset + ' while ' + blue + ' this is blue' + reset);
    

    And your problems will go away. For your information, “\u” is a unicode escape sequence, and “001b” in unicode is equivalent to your escape character. But I am not really sure on this part – I just know the solution, but the exact explanation evades me.

    After asking this question on the Malaysian NodeHack Group, I got a pretty detailed reply from Mats Engstorm:

    Octal literals can be identified by a numeric value starting with a leading 0 (zero). Since this is a source of a possible unintentional octal values when the programmer zero-pads decimal numbers of varying lengths in the source code to make then look prettier and more uniform. The strict mode disallows the octal mode due to this reason.

    The ESCape code can be represented in a number of ways. Decimal 27 , Hexadecimal 1B , Octal 33 or Binary 00011011.

    So instead of write the ESC code in a string as \033 you can as well just choose one of the other modes. Hexadecimal for instance: \x1B.

    In your example you used the two-byte unicode representation of the character \u001b which works just as well.

    I’m still an oldschool C head and usually assumes all strings to be plain ASCII so I’d use \x1B by default instead of this newfangled unicode crap Java is using. ^_^

    Finally, doing ANSI console colors all by yourself is quite tedious, and there are already a few NPM modules out there that’s designed to make your life easier. Go search in the NPM repo for one that suits you. Personally I recommend these modules:

    Do share if you are using a different ANSI coloring module! :D


  9. Open Source Isometric RPG Game

    November 29, 2011 by roguejs

    This is quite a nice find, I’m keeping this here for archiving’s sake and quick reference.

    Flare


  10. Toyota ninja torture – for sale!

    November 26, 2011 by roguejs

    Can somebody tell me what the heck is a toyota ninja torture?

    Original link