Thursday, July 14, 2016

phpmyadmin not found on LAMP install in Ubuntu 16.04+

Hey folks,

Just another quick one. Recently I installed Ubuntu 16.04 and Ubuntu 16.10 both uses the shinny new php7.0. And some newer version of apache as well. And both times when I installed phpmyadmin, and go to or
it gives me a simple, annoying 404!

Well there's a lot of solutions for this in Q&A threads, but for me the only working solution is that, you need to Include the phpmyadmin configuration at the end of the apache2 configuration, so that apache knows that phpmyadmin exists. Here's how

1) Open up apache configurations

sudo nano /etc/apache2/apache2.conf

2) Add the following to the very end

Include /etc/phpmyadmin/apache.conf

3) Save and exist and then restart the apache server

sudo service apache2 restart

4) Browse


Saturday, May 21, 2016

Tomcat error when deploying web app : addFilter, addServlet NoSuchMethodException

Hey peeps,

Just a quick update on something i found today. I was hacking things with a tomcat server (wso2 IS). My need was to duplicate a webapp and make some changes as I like. But when I changed those 'stuff' in the webapp source I had to specifically mention some dependency versions (build tool was maven) rather than obtaining them from the parent pom.

And when I generated the war and deployed it in the server I got the following error


It turns out that the reason for this error has nothing to do with the actual content of the web.xml
But a dependency mismatch
That is some libraries in your WEB-INF\lib directory of the war file is conflicting with some libraries already loaded. So the fix was for me to delete the lib directory completely and deploy which worked!

But according to some stackoverflow answers, deleting just tomcat-catalina.jar and/or all tomcat-*.jars will fix it

Happy Deploying! :D

Monday, April 11, 2016

Laravel 5 : Getting started for collaborative development

Hey folks,

Laravel, for those who aren't familiar is a php framework that is widely gaining popularity these days. This came into my attention when I had to implement an HR system in PHP. Usually I would have gone with Symfony, which I know has a larger support base. But the issue is that Symfony has a huge learning curve and I have to work with a team. Laravel on the hand has a less difficult learning procedure and it can be used to start implementation rapidly.

But Laravel it self is really confusing sometimes. Mostly if you are not familiar to tools like composer and git (for collaborative development). So here's a quick tutorial in which I mention steps I took to setup Laravel and a git repo for development.


1) Git installed 
You can download git for any platform here,
Make sure if in windows, that you add Git to shell commands when they ask to, so that you can access git from command prompt at any place.

2) LAMP / WAMP installed
Linux Apache MySQL PHP (LAMP)
Windows Apache MySQL PHP (WAMP)
You can do this per your liking

3) phpMyAdmin installed
If you are a windows user using popular WAMP like XAMPP, you will have phpMyAdmin already installed. LAMP users need to add it manually.

4) Composer installed
Composer is a dependency management tool for Laravel. Much like Maven  (if you are familiar) it will take a list of necessary dependencies and download these to the computer which removes the need of uploading all the 3rd party libraries everywhere.
Download and install composer according to the instructions given here

Oookay now we are officially ready to start off with the things.


1) Make an online repository to host your source code
For collaborative development, first thing you need it to host your code somewhere. Since we are using git for source control, we need a host that supports git.
Github : will let you have public repos for free
Bitbucket : will let you have private repos for free (plus team integration with limits)

I went with bitbucket since our code is SUPER SECRET!
So goto, make a new repo. let's say "AwesomeHR"
Now ask all your team members to sign up with bitbucket as well and in your repo settings, add all of the team members and give them write / read access.

2) Clone your repo to the local drive
It's time to get your repo to your hard drive. Goto your webroot directory (usually www, htdocs, etc depends according to your server) and clone the repo using this command,

git clone

3) Installing Laravel

There are 2 ways of installing Laravel,
One is the official guide in their installation page using composer and laravel installer

Second one is the hard code way in which we download the Laravel master branch from their github repository and extract it where we want. I had more success with this method in several platforms than using the installer (which has varying steps depending on the platform)

i. First download the Laravel master repo as a zip file from their Github repo
You can also use the following link for a direct download

ii. Next extract it to your newly cloned directory so that when you go into your AwesomeHR folder, it shown all the php files (not laravel-master folder, in that case move everything inside laravel-master to outside)

Now comes a very critical understanding. Laravel has 1000 different 3rd party libraries in use. Those libraries as well as the Laravel core source are NOT included in the zip file you just downloaded. why?

  • Because doing such would make it a very big file
  • We can't always have the latest version of the library if you pre bundle it with the Laravel source, any bug fixes won't reach once downloaded.

So here's how composer come into play. Composer's job is to download all those other libraries into the directory named "vendor" in your Laravel installation and setup them so that it works smoothly.
But keep in mind that you SHOULD NOT copy this vendor directory when you are sharing your code. In other words, the vendor directory be default has a .gitignore file which prevents ANY file inside that folder being uploaded to your remote repo.
Any collaborator using your code has to follow the steps of cloning your repo and then using composer to download the additional libraries.

iv. After that loong discussion, you use the following command while being inside of the extracted folder (AwesomeHR)

composer install

It will take some time for this to complete. Be patient my friend.

To check if all went good, goto http://localhost/AwesomeHR/public/ and you see this

Ta-Daaa you have a fresh Laravel installation now!

4) Configuring Laravel
Still the shit ain't working. Obviously you need to follow an installation procedure.
You need a database for Laravel to store all the data to start with.
Goto phpMyAdmin and make a new database called "laravel"
I will assume our database configuration is as follows

Database name : laravel
Database user : root
Database pass : root
Database host :

To make Laravel use these settings, open the .env.example file in your laravel root directory using your IDE or something like SublimeText. (Notepad won't work)
Edit the lines 5 - 8 to match your configuration


Officially, you can start development with Laravel. You can try a few simple migration codes and make sure the installation is okay. Before you forget, you need to upload the code to the remote repo in bitbucket. Use the following command,

git add .
git commit -m "initial commit"
git push origin master

5) Collaborative development
To use the above code in a team mate's disk, follow these steps

i) Clone the bitbucket repo

git clone

ii) Use composer to install the vendor files

composer install

iii) Do configurations as in step 4

Happy Laravel-ing folks!

Friday, March 25, 2016

WSO2 Identity Server : Understanding XACML 3.0 policies, implementing them in IS and testing with SoapUI

Hi folks,

This is a weird way to resume a blog that was silent for a long time. But I guess this will do. The reason for this post is mainly GSoC 16' which is currently happening. And in selecting a project for it, I came up with WSO2 which has middleware based products. And with time constraints, I was forced to study a system overnight and thought that documenting what I found would be beneficial for those who try to do the same later.

So the question here is what exactly WSO2 Identity Server does?

WSO2 Identity Server (IS) is an identity management system based on open standards. It's a middleware that would connect all dispersed authentication services you have into one manageable system. It has many features that makes authentication and authorization of users for your resources a simple and efficient task. Since the scope of this post is not explaining what IS is, I recommend you to follow the following links to have a better idea. (Dear future GSoC applicant, it is very important that you go through those seemingly boring but highly important links :) )

Get to know the high level artichecture

A very simple getting started guide

The blog that would contains answers to many questions on IS

Now since you have some idea about IS, let's dig into XACML specification, its uses and how IS has implemented it.
XACML is set of standards by OASIS that are related to access control. In general, it specify a way or a language through which applications should communicate to request authentication and authorization data from eachother. Since the specification in discuss is XACML 3.0, from the following link you can observe how a XACML document would look like.

So why XACML is important to Identity Server is:

  1. It is used as the request/response language standard
  2. It is used as the access control policy standard

With that we get the question what exactly is a policy? and how is it all related?

Okay, let's take some theory in.
A policy (in this context) is a set of rules that would define to IS who can access what. Basically its like a paper from a rule book, Whenever someone asks if a user "A" can perform action "WRITE" to the resource "R", it will go through those policy pages and see if there's any policy defining those requirements.
Let's see the above explanation in a more technical way.

Assume there's a resource link. Whoever accessing the resource now would meet a blocker before the actual resource end point. This blocker is known as the Policy Enforcement Point (PEP). The PEP is like the guardian of the front gate that would catch the request and it wants to know if the requests comes from a client that actually has access to the resource. For that it sends the request data to a place called Policy Decision Point (PDP). PDP is like the rule book reader that matches requests data against any rules in the rule book. The rule book is known as the Policy Administration Point (PAP), it is where all the policies are written.
Additionally there's a component known as Policy Information Point (PIP). This is a place where the PDP can ask for more information of a user that's requesting the authorization.

Now the three parts PIP, PDP, PAP are working together to figure out if the request can pass through the blocker (PEP) and reach the resource. It can do so only if they given the 'Permit' flag back as response to the PEP. If you look at the following diagram things may get more clear.

[Well just looking won't help, you have to really try to understand]

XACML architecture implementation in IS

I think that actually clears-up the theory part. So we can now get into real action :D


Suppose there's a resource located at
And this service should only be accessed by admins (Or any user that is given the user role as 'admin')

1) Configure IS to have a policy to support the above rule
2) Validate the policy using the IS inbuilt Try-it feature
3) Use SoapUI to simulate a PEP that is sending a SOAP request to check if a potential user is can access the given resource

1) WSO2 Identity Server downloaded / build from source
2) SoapUI (free version would do)


1) Adding a policy to IS
Download and Start the Identity Server (Please read above links again if you have idea how to do that)
Login as username ; admin, password: admin
Goto Policy Administration -> Add New Entitlement
Note that entitlement is adding a new policy or a rule to the rulebook
Select Write Policy in XML from the list

2) Writing the policy
Now that there's a windows where we can write our policy in XACML format. We can also use their inbuilt editors, but for the scope of this we'll stick to the text editor.
Use the following policy code. paste it there and click Save Policy

A above policy defines a set of rules,
i) The policy has the id 'auth_admin'
ii) It matches the attribute resource to
iii) It matches the action to exactly be 'read'
iv) It matches the group of the user accessing to exactly be 'admin'

3) Testing the policy
Once you add the policy and save you will see it in the Policy Administration list. From the list there select Try
A new UI would open and select 'Create Request using Editor'
What we going to do here is to create a sample request that might be coming from an actual PEP and test it against our PDP to see if it's working.
Use the folloing xml code, which is a XACML request.

Now click Test Evaluate and you would see that the XACML response appear with the decision tag saying 'permit'. ta-daa! We have successfully made a working XACML policy in IS. Now try changing things in the request, like group name, and resource location and observe the response.

Finally we have to actually put the policy to working mode. This is done by publishing it.
Go back to Policy Administration and publish auth_admin

4) Simulating the PEP using SoapUI
Although we evaluated the Policy using the internet tools, we need to verify that it works from outside too. On the other hand, it is important to observe the response from IS to a PEP using SOAP.
We first need to prepare the IS to show the WSDL definition for SoapUI to extract all endpoints.

Open <product-home>/repository/conf/carbon.xml

Restart IS and navigate to, https://localhost:9443/services/EntitlementService?wsdl
You can see all the endpoints

Open SoapUI and add new project, then add wsdl and put the above url. Once entered you would see that SoapUI automatically identify the endpoints and the service names.
Goto getDecision and right click -&gt; add request
Use the following XMLto have a request

Now we have to put a XACML request INSIDE the SOAP request. In order for the 2 xmls not to fight with each other, we put the XACML request inside CDATA tag, which would prevent it from considering as XML, but it would still be a part of the request text.

Before sending the request we need to add authentication of course.
So add auth from SoapUI and of course put username:password as admin:admin
And hit SEND button. [That green triangular button]

And you would see a SOAP response, in which a CDATA section has the actual XACML response saying 'permit'

So this has been a very long post, and i hope to upload and fix issues here and there in this. But hope this helps.


Saturday, August 1, 2015

Explained: Finding the Longest Increasing Subsequence using Segment Tree

Hey guys,

Well this is just random but i found out that for my most disappointment that the tutorials on the above topic arent really useful for the novice. Most tutorials just give the procedure in english or the code but not both. Hence I'm trying to write something human-understandable in the simplest english i know :D


Find the length of the longest increasing subsequence in a given array of integers
For the context of the tutorial we assume all integers are positive hence 0 will be our minimum.
Read more about in the wikipedia article

So the most obvious method is the complete search of the array which would take O(n^2) time. This is highly inefficient for a data set of very large n. Thus an alternative method should be used. Using the segment tree we can find the answer in just O(nlogn) time which is acceptable.

For those who aren't familiar with Segment Trees please refer to wikipedia or this Youtube tutorial. I actually found the Youtube tutorial quite informative and simple to understand.

So back to the solution, what we gonna do is to build segment tree and find the length of the longest subsequence. Please note that this won't give you the actual sequence but just the length of it. But you can implement the finding sequence part easily.


1. Sort the original array but keep the original index of each element.
 original array  - the input array with the elements in their original order
 sorted array  -  an array of objects that contain information on the value of the element as well as its position in the original array. This array is sorted according to the value of the element.

2. Initialize the segment tree with all 0

2. We loop each element of the sorted array and in each iteration
      i. Take the original index of the element
      ii. Find the value corresponding to (0,index) from the segment tree. This would be 0 in initial iterations.
     iii. This value would be the length of longest subsequence upto that point, then add 1 to this value since obviously the current element has a value greater than all previous elements (since the array is sorted) and this extend the previous biggest sequence by 1.
     iv. Use this value to build the segment tree further. (update the tree)


Let's look at the code and then I'll do some drawing and stuff to explain the process VISUALLY *_*

So it looks all okay till it comes to the loop. What eaxtly happend when the buildTree and findMax methods are called? How the tree is built?

Let's take our array, sorted array and the initial segment tree

Let's go through our loops

So finally the root of our tree gives the answer :D


Wednesday, July 1, 2015

Things I wish someone told me when doing Haskell

Hey people,

Long time not posts, yeah i know. Stuck with useless stuff. Finally got some time for a post. This would really be a bundle of snippets mainly for the beginner haskell coders that will soon be frustrated with all the functional elements. I'll try to keep this updated with every new frustration i get :D


Doing IO was the worst thing i had to go through in haskell. As you know that haskell wont allow usual IO in a function, you have to explicitly use do to use a IO command

StdIn as a String

StdIn as an integer/double

Using a function inside a do block with IO

There are instance when our function has to perform IO function only in certain instances. Let's say I need to print numbers only under a certain condition. Then we will have a conditional statement in our function. But as we know every condition in haskell should be complete. If this else ?
For this simply use
return ()
Check this exmaple of printing the pascal triangle


Function defining has several forms and quite different according to what you wanna do.
For an example given here are two ways to define a function that would double the input amount if it's even or keeps the same if it's odd

Note : if is combined with else, otherwise is not combined with it

Friday, January 9, 2015

Function to generate a list of floating point numbers with defined precision in a given range in haskell

Well the top says it all
I'll just put the code here :)

n -  no of precisions
st - starting limit
en - ending limit