ranjan

Archive for the ‘Geek Stuff’ Category

Groovy – Producing JSON using Groovlet and JSONObject

In Geek Stuff, Groovy and Grails on November 19, 2009 at 8:09 am

Groovy – Producing JSON using Groovlet and JSONObject

All right I admit I like groovy, because it’s gives you taste of best of both worlds – all the dynamism of Python and Ruby and still be close to Java.

I was trying to create simple JSON output using Groovlets and JSONObject and this is what I came up with.

In order to use Groovlets use the this link to set it up in your favorite IDE.

And then

  1. Create index.groovy in WEB Folder.

  2. Download the source code from json.org/java site

  3. put in your src folder of web project.

  4. In your index.groovy put in this code

Here’s the code

import org.json.*;
import com.ranjan.*;

/***************************************************
*
*       
Setting up response content type is
important
*       
and in best practice.
****************************************************/

response.setContentType("application/json");

def fromMap =
[name:"Frederic Jean",age:32] 
as JSONObject
def fromList =
["English","French","Spanish"] 
as JSONArray



def newMap =
[
    world:[
        countries:[
            india:[
                cities:["delhi", "bombay"]
            ],
            america:[
                states:["new york", "chicago"]
            ],
            japan:[
                states:["tokyo","some great japanese city"]
            ]

        ]
    ]
] 
as JSONObject 
// this is what does the trick


println newMap


The result...


Designing an Web Interface.

In Interaction Design, Uncategorized on November 2, 2009 at 11:08 am

Lately I have started to love to think about user interface, specially web user interface. I’m not sure where I caught the bug from or how it began, but it has kept me thinking a lot lately of how to design webui.

There are lot of design sites and consultants and some of them you can find on nettuts.com or on W3CSites.com but these are again one page design and my head is filled with more of design issues we face in business software, especially communication software ( microsoft exchange sucsk ) and in particular e-commerce.

Here’s the layout I came up with, and this very basic and will be progressively enhanced later on.

Layout Design 1

There are some issues i know, like the footer still looks ugly and clueless.

By the way this is just a layout design and has no content design added as of yet, but it would be interesting to read comments and get feedback on this. Please feel free to do so.

I will publishing more enhancements later on.

Vista used as Punishment in some companies.

In Geek Stuff on September 13, 2008 at 5:09 am

I heard a weird form of punishment. It’s that if you don’t meet your targets, you get Microsoft Windows Vista as punishment. I haven’t worked on Vista, but I’ve heard how it crashes and people loose their work and their patience and their mind. In my office people are desperate to downgrade their shiny new vista with XP. I think in the end windows was always “Lipstick on a pig”, but after all windows was always a pig.

Can’t we have Java to PHP compiler !

In Geek Stuff on July 11, 2008 at 11:24 am

You would have already come across something called GWT ( Google Web Toolkit ). Basically it compiles your Java code to JavaScript and HTML. Very interesting as it takes care of all the nuisances of the browser incompatibility ( specially IE ) and hand coded HTML.

But what came across my mind is that why can’t we have a compiler that compiles Java to one the ugliest ( second to perl ) langauges. Yup I’m talking about PHP.

PHP has huge market share becuase it’s quick and dirty. All you want is set up is a simple page, obviously your preferred language of choice will PHP. No question about that and yes it’s very handy. But again don’t expect it to go beyond that quick and dirty job of yours. There are several pros and cons and this blog isn’t about that.

What I’m trying to say is for Java developers who love the language, platform and tools can we have something that basically alleviates them from writing PHP.

KIRA is one of the compiler that is trying to solve this problem. But little is known at this point of time.

It’s not a Java to PHP compiler, but it compiles a functional langauge to PHP. It’s built using ANTLR which is again a compilers compiler built in Java.

Wouldn’t it be fun to have a library together with GWT that compiles Java to JS, HTML and PHP in one go. Just deploy that anywhere on Apache ( running mod_php )and there you go…a fully functional application all written in Java that runs in PHP platform.

django – My First Impression

In Geek Stuff on July 2, 2008 at 4:03 am

I really love python. But I don’t really know why. I come mostly from Java background and I wanted to use something in python so that i could quickly prototype my application which then i would have ported to Java.

I came across several post saying nice things about django framework in python and i decided to give it a spin.

After doing some basic crud application, i felt disappointed. Don’t get me wrong, i’m not biased towards Java. It’s just that I wanted to build applications for the enterprise and clearly saw that django was too trivial for such kind of task.

django is really for the Publishing world. Ya , it can churn out database driven application pretty easily and I liked it’s templating engine, but there was no clear level of separation and productivity which I was looking for.

In django the urls.py file is basically the controller, in the sense it decides which url request will go to which views. The views will have all the business logic ( it’s bit confusing in django ). The views after doing some business logic can send the data back to the template along with context data with it, which is automatically populated in the template.

so the flow is kind of

url request -> urls.py -> views -> template

and ya the good feature is you can direclty use ORM in case of django.

After having worked in Spring and Struts framework, I don’t think django framework can be that maintainable as far as enterprise software is concerned.

If anybody of you know or are doing some enterprise stuff in django, apart from CMS, Blogs or wiki than please let me know.

As i said, I really do like python.

Processing : Crazy Programart

In Geek Stuff on February 28, 2008 at 11:31 am

I can keep looking at these videos for hours. What these guys have created is pure art

and I love the fact that it’s been created by programming in Processing that runs on top

of Java WOW.

Checkout these videos on Vimeo .
By Simon

Untitled from Simon on Vimeo.

By blobshift

blobshift from lennyjpg on Vimeo.

This what happens when good open source ideas come together.
As against some proprietary Flash technology in which you can never achieve these effects.

Net4India and Indiaaccess eats up my domain

In Geek Stuff on February 19, 2008 at 9:15 am

I registered my domain name with Indiaaccess which it got registered through Net4India.

I needed to transfer my domain name and when I contacted Indiaaccess they never replied or gave me

wrong telephone support number. After many angry mails I got information that Indiaaccess registers

domains through Net4India and Net4India is not responding even after raising a priority ticket.

AND AFTER SOME TIME MY DOMAIN NAME WAS GONE.

These guys have absolutely no concept of after sales support and people with corporate

domain name could loose their domain just like that.

 I know there could be many arguments, but this is my case here.

AJAX Demo : Simple , Cross Browser

In Geek Stuff on October 10, 2006 at 2:17 pm

Please follow this link to see Truly Cross Browser XMLHTTPR

AJAX Demo : Simple , Cross Browser & Beginner Level

  • Simple hello world code ( Tested on Firefox and IE ).

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<script type=”text/javascript” language=”javascript”>

var http_request = false;

function makeRequest(url) {

http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,… code

// checks Universal Browser Read for Netscape family browser
// furthur info
//http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php

try {
netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);
} catch (e) {
alert(“Permission UniversalBrowserRead denied.”);
}

// creates XMLHttpRequest for Netscape family browser

http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType(‘text/xml’);
}

// creates XMLHttpRequest for IE

} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}

if (!http_request) {
alert(‘Giving up :( Cannot create an XMLHTTP instance’);
return false;
}
else{
window.alert(“welcome http_request object created”)
}
http_request.onreadystatechange = alertContents;
http_request.open(‘GET’, url, true);
http_request.send(null);

}
//———— if there’s is a problem
function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert(‘There was a problem with the request.’);
}
}

}

//————————-

</script>
</head>
<body>

<input type=”button” name=”button” value=”create XMLHttpRequest Object”
onclick=”makeRequest()”>
</body>
</html>

Follow

Get every new post delivered to your Inbox.