Wednesday, June 18, 2014

Deprectaed and Abandonened...

Well, this is a slightly off technical discussion. However, it is nice and interesting to take a note of what software industry uses the word for something which is not going to be there anymore. These words differs in the context they are used.

Below are some common used words, in no particular order.

Deprecated: This is something which we often see while using  a programming language or a framework, where some methods/members are deprecated, meaning they are either no longer used, or they are replaced by some other methods/members.

Obsolete: Obsolete is word which people use to refer to something very old, such as a process or methodology which was relevant few years back, but not recommended any more or replaced by some better relevant process or methodologies or technique.

Withdrawn: For example, some product developers may withdraw BSD License, and provide their product with LGPL license, which is little more strict license in open source world.

Decommission: Lets say an enterprise has started to switch over to a new version control system or to a new version of RDBMS. Then, once the transition happens the old system are usually decommissioned.

And, there are some more:
  • uninstalled
  • discontinued
  • deactivated
  • unsupported
  • EOL (end of life)
  • Sunset
  • Dead (We witnessed an interesting discussion by some industry stalwarts likes of David, Kent and Martin on is TDD dead just a few weeks back )

Any other words comes in your mind? Please leave your comments :-).

Wednesday, June 4, 2014

Unix Tip: Working with CSV file in Unix


One of the unix problem I worked recently, thought its worth sharing.
The problem required to query over csv files in unix, like we query database using sql.
So, these commands work quite like SQL. :)

Requirement:

To get the first record for where 2nd column is null, that is, emp_name has been left blank for the below input file content.

Input File Name:

test_data.csv [1]

Input File Content:

employee_id,emp_name,emp_age
234,Ram,27
235,Shyam,21
236,Mohan,40
237,,25

Command:

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$2 ~/NULL/'  | sed 's/,NULL,/,,/g;' | head -n 1

Description:


- sed 's/,,/,NULL,/g;' test_data.csv : replaces all empty values with the string "NULL"
- awk -F, '$2 ~/NULL/' : finds all the values where 2nd column is NULL, -F option is used for defining field separator
- sed 's/,NULL,/,,/g;' : reverts back all the NULL to empty values
- head -n 1 : prints only the first record, if you remove this you will get all the records. [2]



Other examples:

1) Get all employees age greater then 20

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$3 > 20' | sed 's/,NULL,/,,/g;'

2) Get all employees whose employee_id is equal of 234

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$1 == 234' | sed 's/,NULL,/,,/g;'

3) Get all employees whose employee_id is less than or equal to 235

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$1 <= 235' | sed 's/,NULL,/,,/g;'


--------------------------------------------------------------------------------------------
[1] CSV: A CSV file contains comma separated values and can be easily created/edited with Microsoft Excel, almost like normal excel files.
[2] In case we don’t need entire row, we can also use cut command here to get only one field or a few fields

Tuesday, June 3, 2014

Unix Tip : Unix command to find the files modified 'n' number of days ago


Find is the command for searching files in a unix folder. Probably, this is one such command which you might need quite often.

And, while working on a project, with VCS ( version control ), you often need to find the files that have been modified today, in last couple days and so on. So, this is one the way find command comes handy. It finds the files recursively as well.

Examples:

# replaces n with number of days here
> find . -mtime –n 
# A minus (-) before n indicates number of days ago 
# i.e. include those file which falls between today and nth day
> find . -mtime n    
# display list of files modified exactly ON the nth day, from today
> find . -mtime +n 
# A plus (+) before n indicates file modified even prior to nth day

In case you need to find the files that have been modified few minutes ago, or some 'm' minutes ago, you can use the option mmin instead of mtime.

------
Reference: http://linux.about.com/od/commands/l/blcmdl1_find.htm

Friday, May 30, 2014

How to read JSON data (json request) from http request in a servlet or controller


If you use a javascript AJAX request which sends the http request in JSON data format and not in normal key value pair, you might need this.
One such example is the ExtJS store's, api config. For all the write operations the proxy for create/update/delete (use AJAX) sends the records in json form, in case the reader is defined as json.

Code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException {
  
 PrintWriter out = response.getWriter();
 StringBuilder jsonString = new StringBuilder();
 
 String jsonToken = null;
 
 BufferedReader reader = request.getReader();
 while ((jsonToken = reader.readLine()) != null){
  jsonString.append(line);
 } 
 // converting the JSON String into a JSONObject, which almost work like a Map  
 try {
  JSONObject requestJsonObject = new JSONObject(jsonString); 
  // JSONObject from JSON Java API from json.org
  System.out.println(requestJsonObject.toString());
 }catch(JSONException jsone){
  jsone.printStackTrace();
 } 
  
 // further processing goes here....
} 

Interesting reads:

Tuesday, May 27, 2014

ExtJS: Panel Vs ViewPort

Working with ExtJS apps, we often get advice from the senior programmers that we should use ViewPort instead of Panel.
So, the question that we arise is when to use a ViewPort and when to use a Panel. Or, why to use ViewPort if Panel suffice the need.

Well, ViewPort is particularly useful in case you are looking to create a single web page application.
I think designers of ExtJS have put together all the essential components very nicely which allows you to develop Single Page WebApp quite elegantly.

Using viewport you can utilize availbale height and width of browser. You can use screen.availWidth and screen.availHeight to give you component proper dimension.

When I tried to do a little bit of search on google and forms, couple of interesting points came out which can help understanding answer when and why:
  1. There may be only one ViewPort for a page for obvious reason that it is specialized container which give you the entire view area of browser. But of course you can use a layout like border layout and add Panels as child component.So, in case you have a
  2. And, in cases where you do not have the liberty of using the entire view of the document/web page, use Panel instead. For example, in case your entire web page is using JQuery, but you want to keep a ExtJS grid component, you can do so using a grid panel.
     
The below forum links might useful to further reading:
The only tricky thing that I found with ViewPort is when you want to have the scrolling option, meaning the scrollbars should appear when you reduce the browser window size.
There is  autoScorll config, which is by default false. Although there implies that if you make it true it should show you the scrollbars. But, that does not happen often. The reason is something interesting to know.

If you take a look at the docs for ExtJS (4.x), it clearly states, "The Viewport does not provide scrolling, so child Panels within the Viewport should provide for scrolling if needed using the autoScroll config."


All this is little contradictory. But the problem gets solved once you provide the width/height or both for the child Panels. The scrollbar does appear after that.

So, in case you want to keep the scrolling, you need to take care of child Panels.
-----------------------------------------------------------------------------
  1. Please note the properties in EtxJS are case-sensitive, so "autscroll" won't work, it must be "autoScroll".
  2. screen.availWidth and screen.availHeight are provided by java script. You can alternatively use Ext.container.Viewport.getWidth() and Ext.container.Viewport.getHeight() as well.

Sunday, March 30, 2014

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...