Senin, 26 Agustus 2013

Conference!

Finally! For the very first time, my research paper is accepted at international conference. I think, I've made a pretty good step in the education career road if I want to continue my career as a researcher. I personally do not know how hard is a paper to be accepted to a conference, but I've heard some conference had acceptance rate below 10/20%. Fortunately, I do not think that this conference is that hard. :D

Anyway, I will be going to Bali to attend the conference at 28 and 29 September. I will write the details about the conference later to share my experience. Thanks and have a good day. :D

Senin, 19 Agustus 2013

Deploying Django Application into Server

Okay, this post will be very technical. I do make web applications using python and Django. So, I think it would be nice to share the experience. This guide will assume that you want to deploy the app into your own server, not some PAAS like Heroku or Google App Engine. Okay, first let's see the software stack. I this tutorial, I used Ubuntu Server. 
  1. Django (Web Framework)
  2. Gunicorn (WSGI Server)
  3. Nginx (Web Server)
  4. Supervisor (Process Manager)
  5. Fabric (Server Automation Tools)
  6. VirtualEnv (Manage Production Server)
  7. Git (Versioning Control System)
First Step - Setting up the Production Environment
The first step to deploy your app is to set up the server. You need all library you user at development at the server. In order to manage the library, we need virtualenv because every project need a different library and it could broke the system if there are more than one version of library. Virtualenv will create an environment for each app so that that will never stuck.
 sudo pip install virtualenv  

And then make a new environment by calling this command.
 virtualenv nebeng
 source nebeng/bin/activate  

After that, you can install all the dependency manually or using the pip requirements file. After you finish this step, you have created an isolated python environment for your own application.

Second Step - Configuring Fabric
Okay, the second step is get your code into the production server. In order to make your app is running, the server must get the code from your repository. For me, it is a tedious task to clone and pull the latest code on the server. You need to access the secure shell and run the command. Fabric is the solution to this problem.  Run this command to install the latest version of fabric
 pip install fabric  

Fabric let's you stay in the localhost, code the command, and let it do the work. To do this, install Fabric and put fabfile.py. Here is my fabfile.py. 
 from __future__ import with_statement  
 from fabric.api import *  
 env.hosts = ['Your server']  
 env.password = 'Your password'  
 env.directory = '/home/edwin/nebeng/app/nebeng'  
 env.activate = 'source /home/edwin/nebeng/bin/activate'  
 APPPATH = '/home/edwin/nebeng/app/nebeng'  
 def migrate():  
   with cd(env.directory):  
     with prefix(env.activate):  
       run('python manage.py migrate')  
       run("sudo supervisorctl restart nebeng")  
 def update():  
   with cd(APPPATH):  
     run("git pull")  
     run("sudo supervisorctl restart nebeng")  
 def deploy():  
   code_dir = '/home/suitmedia/edwin/nebeng/app'  
   with settings(warn_only=True):  
     if run("test -d %s" % code_dir).failed:  
       run("git clone git@bitbucket.edwin/nebeng.git %s" % code_dir)  
   with cd(code_dir):  
     run("git pull")  
     run("cd nebeng")  
     run("sudo supervisorctl restart nebeng")  

This is my full fabfile.py. I will explaining a little and explain the rest at this guide. the env.directory is your application root directory. the env.activate is the location of the virtualenv file that I will explain it later. The migrate() function is to do database migration. The run() function is fabric function to do command from ssh. If you look into the command, you will see the supervisorctl command. It is the process manager I talked above. I will explain it later. For now, go to your console, go to your project directory, and run "fab deploy". It will invoke the deploy() function. The function will clone  the app from the repository.

Third Step - Configuring the Application and Web Server

Okay, after cloning the code into the server, we need to set the app and web server. Gunicorn the application server is used for handling the request into a response object. The Nginx web server, will listen to your default HTTP port, 80 and sent the request to the appropriate local application port based on its namespace. okay first install gunicorn using this command
 pip install gunicorn  

and create a "gunicorn.py" file in your root app directory and put this code.
 import multiprocessing  
 bind = "0.0.0.0:10000"  
 workers = multiprocessing.cpu_count() * 2 + 1  

Simple, it is the Gunicorn configuration file. This is very minimum configuration for production. With this configuration, you can run the app, but if you want more advanced configuration, you can see it here. After that, running the Gunicorn with this command at the app root directory will run the server.
 gunicorn_django -c gunicorn.py  

After that, we need set up the Nginx. Install Nginx in every way you want. Then, open the nginx.conf. Mine's at /etc/nginx/nginx.conf and put this code.
  server {  
       listen 80;  
       server_name nebeng.test.com;  
       client_max_body_size 50m;  
       location /static/ {  
        alias /home/edwin/nebeng/app/nebeng/static/;  
        expires 30d;  
       }  
       location /media/ {  
        alias /home/edwin/nebeng/app/nebeng/media/;  
        expires 30d;  
       }  
       location / {  
        proxy_pass http://0.0.0.0:10000;  
        proxy_set_header Host $host;  
        proxy_buffers 8 16k;  
        proxy_buffer_size 32k;  
       }  
  }  

This configuration will let the nebeng.test.com into the port number 10000. The static and media files will be served by Nginx. After changing the Nginx configuration file, do not forget to reload the file using.
 sudo nginx -s reload  

Last Step - Configuring Supervisor the Process Manager

Okay, after setting the Nginx and Gunicorn, you need something to control the application server. You need ther server running in the background process and if the server reboot, your application server needs to start running immediately. Supervisor will do all these things for you. Install the Supervisor by running this command.
 sudo pip install supervisor  

And then, create the configuration file at /etc/supervisor/conf.d/. You can name the file anything. For example, nebeng.conf. Here are the codes.
 [program:nebengers]  
 command = /home/edwin/nebeng/app/nebeng/script.sh  
 directory = /home/edwin/nebeng/app/nebeng  
 user = suitmedia  
 autostart = true  
 autorestart = true  
 stdout_logfile = /home/edwin/nebeng/app/nebeng/log/s_out.log  
 stderr_logfile = /home/edwin/nebeng/app/nebeng/log/s_err.log  

Then, we need a script file to run the Gunicorn. Create a "script.sh" file in the root directory of your app and put this code.
 #!/bin/bash  
 set -e  
 LOGFILE=/home/edwin/nebeng/app/nebeng/log/nebeng.log  
 LOGDIR=$(dirname $LOGFILE)  
 cd /home/edwin/nebeng/app/nebeng/  
 source ../../bin/activate  
 test -d $LOGDIR || mkdir -p $LOGDIR  
 exec gunicorn_django -c gunicorn.py --log-file=$LOGFILE  

The script is quite simple. It would create a log directory is it was not created. Then, run the Gunicorn. Do not forget to make the script executable using chmod +x script.sh. To invoke the supervisor, you need to load the configuration files first. Run
 sudo supervisorctl reload  

Then, to start the Gunicorn server, run
 sudo supervisorctl restart nebeng

It is done! Now you can use all the fabric command or you can write a custom command for yourself. You can check into nebeng.test.com to check whether the configuration is good or not. Check the log files, or maybe playing with configuration files. I will post the troubleshoot page later. Thanks. :D

Kamis, 15 Agustus 2013

Little Tips While Buying a Laptop or PC

Hi everyone, since I'm a tech savvy, I know a lot about computers, laptops, phone, and many other things that related to technology and I want to share to you how to choose a good laptop for you. It is simple. You do not have to learn to programming. You just have to be sure you are not lazy enough to read the computer specs and stick to my reccomendation, I'm sure you will be fine. Alright, here we go.

Processor
The first one to see is the processor. It is simple, do not bought laptop or PC with a "celeron" or "atom" within it's processor. It is severely outdated an do not give you much processing power for today's application. Aim for i3 at minimum if you use the computer for browsing and simple office task. Take i5 if you work with graphics and want to play games. i7 is for those who search great performance, but I think the price is too high and the performance is not improved as good as i3 to i5. For AMD, you can try to find A6 or A8. The key key point here is to see the version of the processor architecture. For now, stick into "Haswell". 

Memory (RAM)
This is the most easy part. Do not bought laptop or PC with memory less than 4GB. The difference of 2GB and 4GB or RAM is very very noticeable, while RAM is very cheap on the market. $GB or more RAM will make your work and life more convenient. If you happen to have PC or laptop with 2GB of memory, upgrading it to 4GB will give you freedom. It's like flying. My personal recommendation is 4GB is minimum, 6 GB is recommended, and 8 GB is good. They are not very costly compared with other peripherals. Always put a lot of budget in this because it will give rocket performance boost.

Video Card (VGA)
This peripheral will determine how good you computer graphics quality. "Is that laptop can watch movie or play games?" is a wrong question. Every computer can play games or watch movies. The question is how well? Or maybe what kind of games do you want to play? First of all, you need to understand the VGA code like 620m or 540m. The first number on the code tell us the whole version of a VGA. 6 has better architecture than 5. 7 is better than 6. Then, you see the second and third number. These two numbers if used to compare another VGA inside a VGA version of the first code. So, 540 is better than 530, but 540 is not better than 630 because it has different architecture. The rule of thumb is to stick to the latest VGA version. In the time of this article is written, the 6 are the most mainstream VGA and the 7 are just coming out, but not yet in my country. For now, go with 6.  An on-board video card is good for browsing or daily office task like excel, word, and playing solitaire. If you want to play some today's games 620 or 630 is enough. If you want to play newer title or design, a 650 is recommended.

The rest of the list is optional. The most important when it comes to performance it the three above.

Hard Drives / SSD
Simple, if you want performance and have the budget for it, go for SSD. If you want spaces and low on bugdet, go for simple HDD. SSD cost 10 times more to achieve the same space like HDD, but it was about 10 times faster. With SSD, your computer boot faster, start application faster, and everything is faster. Most people recommendation is using both SSD and HDD or hybrid build. 32Gb or 64GB SSD is not that costly with a good HHD. It works!

Motheboard (PC only)
This kind of thing is fairly complex to choose because it comes with a lot of specs. Fortunately, if you want to buy a laptop, you do not have to think about it's motherboard. The simple rule of choosing motherboard is find the cheapest motherboard that all your other peripherals like processor or VGA can fit. You'll be okay. I will write a single article for choosing motherboard for advanced.

Okay, that's it. My simple last tips is always stick to the newest version of each peripherals. That way, you can use today's application gracefully. :D. Thank you and have a good day.


Senin, 12 Agustus 2013

"Smart" Phone

Yeah I truly know the smartphone hype is so up right now and maybe until a couple more years again. There are so many types of smartphone is every different level of society. Technology is designed to make people more productive and effective while they are doing their work. You can checking emails, send message, view news, playing games, and so many more activities with the little device. Unfortunately, I've seen a lot of people do not understand the basic principle of smartphone. Here is it, smartphone will be a dumbphone if the user never tried to find the smartness of smartphone. Okay you can see a map from the smartphone rather than bought a map from home into your backpack. I do not think it is smart enough to consider a phone is smart. It is just simplify things. Simplephone is a more appropriate name for it.

In computer science term, we called something a smart if there is a certain algorithm that could make prediction of something. For example, my smartphone can give a reasonably good prediction with my typing method to guess the next word I gonna type. Showing news that I fond of. Giving knowledge about the traffic around my workplace and home. Or maybe, my phone can give suggestion about their smart feature. I mean, without good application, smartphone will never be a smart one. I've seen numerous parent giving their children smartphone just to satisfy the lust of their children. Most of them use it to play games and chatting though. 

It is not a hard task to find a good app for your smartphone. I do not really like to point which app is good because every people has it's own taste. I prefer to tell you to search it's by your own. I believe, it will produce better result. :D. Good luck.

Jumat, 09 Agustus 2013

The Proper Profile Picture

Well, hello. Right now, I will talk about a ubiquitous phenomenon that recently bugged me to write this. It is about profile picture. Whatever the application, Facebook, Twitter, or Line. It is all using profile picture as main identification to each person. Unfortunately, a lot of people seems, using filter, make-ups, sharp angle to get their profile photo. I mean it is just silly to look to my friends profile picture and remembering their reality. The difference are so subtle. In one way a girl picture can be more pretty than an actress, but sadly in reality, I won't see her like that way. This meme just comes out after I had this thought. It fits perfectly to the situation.

Internet dating
(copied 9gag)

My personal thought, profile picture should be a good way to let your friends identifying yourself. Your normal and real yourself. Do not take photos from 45 degrees angle and then using make ups that really change your image as yourself. That would the real sign of gratitude of your life. It is just awkward to see a cool profile picture of you, but when I meet you at reality, it sucks.I do not have any problem with people that use animals or any other pics for their profile photo. It's just, them. :D