Mobil Mewah

Salah satu sumber Inspirasi.

Mobil Sport terbaik

Anda pasti bisa memilikinya.

Bermain dengan pesawat

Salah satu ide yang gila, Balapan di udara.

Bermain di angkasa

Apakah ini salah satu Goals dalam hidup anda? anda pasti bisa mencapainya

Tuesday 26 September 2017

Installing Multiple Erlang version in one systems

In python you can have multiple python version installed in your systems using virtualenv. I like to do this with Erlang, as need to test my code on several erlang versions. Its not effective if you install and reinstall the version you need if you want to test out.

And in Erlang of course there is such package to manage multiple instance of Erlang. This is used for developer of course. Come the rescue Kerl , an erlang application that make it  "Easy building and installing of Erlang/OTP instances" .

So with no further do, i installed in my debain dev machine. Here are my steps by steps to make use of kerl. You can also see the documentation from kerl on how to work with kerl. In this blog i just documenting what important to run it and ready for developement.

Install Kerl using easy way with curl.

$ curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl

Don't forget to set it executable .

$chmod a+x kerl

Then you can list what release supported by kerl by running :

$./kerl list releases

You will get all the supported erlang version from R14 to R20.0 in current version as for now.
But before can build it using Kerl, need to install some of the prerequisite like gcc, ncurses-dev.
In debian you can install with this command :

#apt-get install build-essential ncurses-dev libssl-dev 

And in ~/.kerlrc add this entry :

export CFLAGS="-DOPENSSL_NO_EC=1"

Then we need to build the erlang version we need.
$./kerl build 20.0 20.0

This will download and build erlang version 20.0 and put it in ~/.kerl/builds/20.0

If you have multiple builds can do :

   ./kerl list builds

To install the builds run :

./kerl install 20.0 ~/kerl/20.2

This will install in your home directory, inside kerl/20.2/ folder.

To see installed erlang release, you can run :

./kerl list installatins

And to use specific erlang version do this :

$. /installed/path/of/kerl/20.0/activate
$erl --version

To deactivate use this command :

$ kerl_deactivate


Happy coding with erlang / OTP.

Reference :
- Kerl source

Sunday 24 September 2017

installing python-ldap support

When installing python-ldap package, we need to prepare the libs required by python-ldap. Some of it are :

  • linux build package
    install using apt-get install build-essential
  • libldap2
    Install using apt-get install libldap2-dev
  • libsasl2
    Install using apt-get install libsasl2-dev

After complete with the prerequisite, python-ldap will be happily installed. To install in python run :

# pip install python-ldap

I am using simpleldap package so install simpleldap will also installing python-ldap.

# pip install simpleldap

To test the python-ldap package do this :


  import ldap
  
  conn = ldap.initialize('ldap://192.168.100.100')
  conn.protocol_version = 3
  conn.set_option(ldap.OPT_REFERRALS,0)
  conn.simple_bind_s('administrator@susu.local', 'secretpassword')

Hope this helps, as i try with many other package, its fails. With python-ldap success now.

Installing package in python the easy way

Every programming languange or scripting langguange or any computer language has its own tools to make the job easier and done faster. Come with python is their installation systems.

For installing package in python, there are several ways to do it. You can download the source, unzip and run python setup.py install , or using a package installer which will download the package you specify and also download its dependency.

I choose to use pip package installer. It is lot easier and faster with pip. If you use python > 2.7.9 pip already included in python installation. If not come along for installing pip.

First get the get-pip.py file from Here . The script will installing pip for you when your run i.
After download it, do python get-pip.py as root.

After complete you can pip install package-name , and it will download and install all the python package from python repo.

If you have your development machine with all the required package installed, and you want to move your machine, cumbersome task right to install from start again. You can make it easier using pip freeze. It will list you all the python package installed. Just dump it on a pip file with this command :

pip freeze > requirements.txt

Then in your new machine, transfer your file requirements.txt using this command :

pip install -r requirements.txt

Then all the package will installed in your new shiny machine.

Have a good python experience.


Monday 18 September 2017

Windows server evaluation auto shutdown

Microsoft provide a evaluation version of their Windows servers for 90 days. After the trial period expires, it cannot renewed even you  have a genuine licence, or downgrade or upgraded to another edition. So what will happend to the server you install? Well, it still works but it will automagicly shutdown. This is by design for microsoft evaluation version of windows.

You will need to reinstall it and move your data to the new server. This is not an issue if you have the license and the evaluation version install only for testing. But there is a solution if you still want to use the machine  install.

Actually the automatic shutdown is done by a process inside the windows server using a scheduled services that run and check for the license when you logged in to the server. THe service are "Windows License Monitoring Service" (WLMS).

What it do was basically monitor the license state of the machine you install and if it has expired, the automagic shutdown will be triggered every 1 hours of usage/ login. You can try to end the process of WLMS in task manager, and you will get a famous BSOD.

Of course this is not what you want. You want to still able to use the windows installation in evaluation version. Here i will show you the way to be able to extend the evaluation time, but please not to pirate it. Microsoft still will able to detect your server license is illegal.

Here how to do it step by step.


  1. Download Windows PSTools. This tool is from Microsoft to maintaining process and services through comand line. Download Here
  2. Extract it to c:\ps or any folder you like on your hard drive
  3. As administrator, open Task Manager - File - New Task.
    Check the "create this task with administrator privileges"
    Type cmd then enter.
  4. You will get a new command prompt. Go to the PS folder where you extract the files.
  5. type psexec -i -d -s cmd
  6. Click Agree on the license agreement.
  7. Then you will have a command prompt run under "nt autohrity\system"
  8. To make sure it run under "nt authority\system" do type whoami on the command prompt.
    You should see nt authority\system.
  9. Next step type sc delete WLMS  , then enter.
  10. Next open regedit. Type regedit 
  11. Registry editor will open.
    Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
  12. Local WLMS
  13. Then right click the WLMS key and delete.
  14. After this you can restart your computer.
Now you will have the windows installation running without automagicly restart every 1 hours after you login. This seems apply to all windows evaluation versions available to download.



Tuesday 12 September 2017

Javascript promise error handling

Javascript promise error handling
On web application, the standard will have javascript code. Especially with ajax call method and event driven application design.

One of my experience just now was with using promise in javascript. It not catch the error status code returned from the server backend, but in debug mode in the browser status returned was 401 or unauthorized. I using Marionette JS as my development framework and my backend using Chicagoboss.

So the story was that user need to login before access the API. When request coming without authorization code, it will return 401 status code. My backend API try to be Restfull. And i want my web application automatically cacth the 401 error globally and will show login form when 401 status code encountered within the app run time. So the code was like below :

            var defer = $.Deferred();
            options || (options = {});
            options.reset = true;
            defer.then(options.success, options.error);
            var response = data.fetch(_.omit(options, 'success', 'error'));
            response.done(function(){
                defer.resolveWith(response, [edonationboxes]);
            });
            response.fail(function(response){
                defer.reject(response);
            });

And i have the ajax setup when the webapp start to detect the 401 globally.

    $.ajaxSetup({
        statusCode: {
            401: function(){
                // Redirec the to the login page.
                window.location.replace('#login');
            },
            403: function() {
                // 403 -- Access denied
                window.location.replace('/#denied');
            }
        },
    });

So the problem is when i refresh page, it correctly detect the 401 and login page shown. But when application run and the request triggered within the app, by accessing a menu, it not cacthing the 401 error.

When debugging, the statusCode was 0. So google for a while, seems issue with the API backend which not returning correct headers for CORS request. So when fixed the app behave correctly. Login page show when 401 detected.

So make sure in the API response header return this : access-control-allow-origin:* 
With javascript promise, it wont behave correctly if CORS involved and not set correctly, especially in SPA web application.

Hope this helps someone, as i have debug this almost 3 hours.

Twitter Delicious Facebook Digg Stumbleupon Favorites More