## Posts

Showing posts from March, 2011

### Aspect Ratio came to rescue

In my present assignment I had to deal with large JPEGs ( 2000px:3000px ) images and wanted to store their scaled version (preferably of size 400px:500px ). If we randomly scale an image without considering its Aspect Ratio, the resized image looses clarity very quickly (depends upon how smaller you are trying to make it). The solution is Aspect Ratio . So, you have the original width and height ratio ( 2000px:3000px ) and need to find out scaled width and height. We need to keep either width or height fix. In my case, I kept the scale width fixed to " 400px ". Now, if we apply a simple mathematic equation- width_original : height_original = width_scale : height_scale height_scale = (width_scale * height_original) / width_original So, height_scale will be 600p x . Above calculation will determine the scale width and height which will make sure your scaled image is keeping original Aspect Ratio intact and thus you'll get the best quality resized image! I am usi

### Regular Expression in JavaScript

I was struggling to get familiar with JavaScript's Regular expression handling and thought my learning might help others. Here I'll explain exec()  function to parse/search matching regular expression in a given string. Regular Expression is a special string in JavaScript which need to be inside of 2 " / " characters i.e. / REG_EXP / , you don't need to use ' or " characters. " i " and " g " followed by last " / " indicates whether you want to do i gnore case and g lobal search . REG_EXP can contain all standard regular expression syntax . Another important thing, we need to escape any Regular expression character if you put this in REG_EXP with " \ " e.g. /\d{3}/ . That's it! we are now almost ready to use Regular Expression. Following is a quick reference of mostly used RegEx Literals- Position Matching:  ^ (Start of String), \$ (End of String), \b (Word Boundary) and \B (Non Word boundary) RegEx

### JSON- Parsing Apache Lib

I'm back again, last few months I was busy with my own Web 2.0 project and trying to build a platform which will use advance JavaScript and once that is done will write a JSON based Web API which can be accessed from Mobiles. So, thought lets share few exploration on Javascript and JSON. Here I'll explain how we can efficiently parse JSON to Java Object and vice verse. So if you are looking for similar stuff, keep reading following sections...   JSON (JavaScript Object Notation) is an wonderful and light weight piece of Object notation for data exchange. If you compare this with XML, you can easily make out that this representation is pretty compact compared to XML which need to use extra piece of information (XML Node name, start and end tags) to distinguish each node. Moreover JSON is closer to Object representation of your programming language Java or it is very easily supported in JavaScript ( eval() ). So if you are using AJAX, this is the best fit. So, next time you