You are currently browsing the archives for the Development category


Compiling nginx 1.4.0 With SPDY on CentOS 6

Just a few days ago, the latest version of nginx at 1.4.0 was released to the public. The version bump adds a lot of new capabilities for your web stack. The most interesting for me was support for SPDY 2 protocol.

Excerpts from Chromium SPDY’s page reads below:

As part of the “Let’s make the web faster” initiative, we are experimenting with alternative protocols to help reduce the latency of web pages. One of these experiments is SPDY (pronounced “SPeeDY”), an application-layer protocol for transporting content over the web, designed specifically for minimal latency.  In addition to a specification of the protocol, we have developed a SPDY-enabled Google Chrome browser and open-source web server. In lab tests, we have compared the performance of these applications over HTTP and SPDY, and have observed up to 64% reductions in page load times in SPDY. We hope to engage the open source community to contribute ideas, feedback, code, and test results, to make SPDY the next-generation application protocol for a faster web.

In order for SPDY to work, one will need an SSL certificate and OpenSSL 1.0.1c at least to compile and run a website successfully with nginx. SPDY needs NPN enabled with OpenSSL and CentOS only provides 1.0.0. According to a blog post here, we can just add a repo to get OpenSSL to work nicely.

Here are the steps needed to compile nginx with SPDY support:
$ rpm -ivh --nosignature http://rpm.axivo.com/redhat/axivo-release-6-1.noarch.rpm
$ yum --enablerepo=axivo update openssl
$ cd /opt/src
$ wget http://nginx.org/download/nginx-1.4.0.tar.gz
$ tar xfz nginx-1.4.0.tar.gz
$ cd nginx-1.4.0
$ ./configure --with-pcre --with-http_ssl_module --with-http_spdy_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --prefix=/usr/local/nginx
$ make -j4
$ make install

Now that the steps above are through, it’s time enable SPDY with your websites assuming that you already have a working nginx configuration with SSL enabled. It’s actually really simple, the full explanation is located at nginx’s SPDY documentation.

server {
listen 443 ssl spdy;
ssl_certificate server.crt;
ssl_certificate_key server.key;
...
}

Now test your website at spdycheck.org to see if your SPDY implementation is successful. Cheers!

chuck-norris-php

It is what is – A PHP client to get Chuck Norris from The Internet Chuck Norris Database: icndb.com.

Codes at the usual - https://github.com/tistaharahap/chuck-norris-php

Chuck will come after you…you have been warned!

[Techtorial] Responsive With Zurb Foundation & HTML5

Responsive techniques with websites have been around for a while now. Not many websites here in Indonesia are responsive. Being responsive for me is out of necessity, mobile web traffic is increasing very rapidly and being responsive is the next logical step despite already having a mobile web. It will look good with search engines too :)

Zurb Foundation is one of a handful collection of frontend Responsive frameworks out there. However, to get your website to be really resilient, you should start from the server side. There’s a slide show here by Yiibu covering all the aspects why being responsive starts from the server side part. Keep in mind that frontend Responsive frameworks does not actually help with optimizing the images your clients will download nor do it will strip HTML fragments that shouldn’t be included, it simply hides them with CSS, but with some clever JavaScript, you could take them off from DOM but then again that’s more work for handsets with minimum CPU power.

To get into perspective, by making your website Responsive, you start Mobile First. Why? Because mobile version is considered as the lowest fidelity in terms of the Information Architecture and also from a visual point of view. By doing this, you can actually devise a scale of priority and get to know your products/features deeper. If you’re still not sure, you can always A/B test it.

For the purpose of this Techtorial, we’re going to build a simple news reader application for my friend‘s Tech Blog DailySocial.net. We’re going to extract contents using only frontend technologies, JavaScript to be exact. There will be no caching (persistency) at all, you are welcomed to fork and do your own implementation, you could try to persist by using Local Storage or even cookies (beware of the 4 KB limit for this).

Before going through, these are the things you will need for later:

  1. Zurb Foundation 3.0
  2. Code editor, Smultron will suffice for Mac users
  3. Some HTML5 Knowledge
  4. Github repository for the source code in this tutorial is available here

We’re gonna start by building the layout. Every layout elements in Foundation is made up of grids. Every row, there are 12 columns with a default gutter size of 30 pixels. The interesting part of Foundation 3.0 is that now it provides mobile columns. Mobile columns spans 4 columns and it will be really useful in cases like when on the Desktop the first column is 4 columns wide, the second is 8 columns while on the mobile version you’d want it to be equally divided columns. You can create your own custom Foundation by the way.

Starting up we want a layout with a website name at the top, articles at the belly, sidebar on the right and some fancy notes for the footer.

You can see how easy it is to do the columns. Of course, it’s just a single row occupying the whole width. Let’s make it more interesting by dividing into 2 belly columns consisting of the articles and a sidebar.

When you resize your browser, the layout will automagically be adjusted with the screen resolution. Looking the code above, I encourage you to hack the left column by adding a mobile-three class and a mobile-one class on the right. The behaviour of the layout changes by persisting the sidebar to always be on the right. Doesn’t look good right? Revert it.

Now the footer is done and you’ve got a working layout that is responsive and ready for some JavaScript manipulations.

The data source comes from DailySocial’s JSONP endpoint. If you don’t know what JSONP is, there’s a good reading about it here. Because of the nature of JSONP, all we gotta do is just create a callback function in JavaScript and include a script from DailySocial’s JSONP endpoint after your callback function is declared.

We’re done! So quick and painless to finish this Techtorial right? There are a lot of improvements in store for this DailySocial reader. On the next tutorial, we’re gonna cache our JSON into the browser’s Local Storage. So for now, have fun with the codes!

Simple Naive Bayes Classifier for PHP

Recently Hacker News is flooded with numerous articles discussing or at least mentioning Naive Bayes Classifier algorithm. It’s a basic algorithm to classify a set of words into a certain category (set) based on prior learning of words and its probabilities. It sounds simple enough but without actual technical guide book, it’s quite trivial since most of the information out there regarding it is too messy for newbies like myself.

Just today, there was an article by Alexandru Nedelcu about Naive Bayes Classifier here which is exactly what I am looking for. It’s simple, to the point and most importantly outlines the benefit of using the algorithm with practical examples. The codes are in Ruby but I think the article is finely written, you don’t have to look at the source code.

So I somewhat forked and ported the idea into PHP and voila, the PHP counterpart is available at https://github.com/tistaharahap/Simple-Naive-Bayes-Classifier-for-PHP. It’s still very basic, just a prove of concept with MySQL as its persistent storage. The Store is abstracted so you can write your own Store with any database you’d like.

My focus is creating codes that will scale for big documents, and yes MySQL won’t be a definite winner here for scalability but I’m using it now to make learning easier. I’m planning on creating a HandlerSocket Store as well as a MongoDB Store.

The codes at the repository for now is not ready for prime time, however, feel free to fork, port or anything you feel right with the codes. Have a great time ;)


photo of Batista Batista R Harahap [email protected]
Jl. Bango II/29C, Pondok Labu
Cilandak , DKI Jakarta , 12450 Indonesia
62817847023

This hCard created with the hCard creator.