Archive for the ‘code’ Category

Webmethods running linux commands as a java service

Tuesday, February 3rd, 2009

Recently a friend asked me how in webmethods, she could fire linux specific utility tasks. She wanted to find out if the disk space is full on linux. This can be done very easily by the “df- kh” command. But how to invoke this through webmethods?

Solution: Follow the steps below.

Step 1: Create a Java Service with the following input and output

webmethods-java-service-1

Step 2: Paste in the following code:

//—- BEGIN OF CODE
//Author: Hussain Fakhruddin
//Date: 20090203
IDataCursor cursor = pipeline.getCursor();
//Return if no command is specified…
if (!cursor.first(“command”)) return;
String output = “”;
try {
String command = (String)cursor.getValue();
String line=”";

//Creating a Process Instance and executing the command..
Process p = Runtime.getRuntime().exec(command);

// Capturing the output.
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = output + line + “\n”;
}
input.close();
}
catch (Exception err) {
// Do something on error… may be throw a ServiceException
}
// setting the outputMsg for whatever output the command has given.
cursor.insertAfter(“outputMsg”, output);

//—–END OF CODE————

webmethods-run-external-command-or-programs

Step 3: Run the program and pass the unix/linux command

Note: DO NOT use commands which are not exiting after giving an output. For example “tail -f” . This service is only for commands like “df -hk” or “cp file1 file2” or “pwd” or “ls -lrt“.

If you face some issues, do feel free to write back.

Rediff.com Coding Standards: An Analysis

Monday, October 20th, 2008

By Hussain Fakhruddin

hussulinux@gmail.com






Rediff has a lot of portals within its main portal.

This is how they organize their re-usable code.

The first thing I did is logged on to: http://indian-railways.rediff.com/



I opened my Fire Fox’s Error Console and found this:




The next thing I did was to open up the source code:

I was shocked. I could really figure out that this type of code was

1) Written by just “Jugard” of code from their own paces here and there!

2) Not at all reviewed!

3) Done in haste to meet the deadlines!



I will put some screenshots to prove my point:(Please enlarge them as needed)




  1. Are these written by the same programmer?

Subsequent lines of code, but one in caps and other in small.

- Seems like they have just copied it from some previous page.

  1. Dirty CSS to look good? : Reuse of CSS codes, but not at all arranged in a proper manner. They are probably using the code which is lying here and there.

  1. Code lying here and there + insert what is needed and get the things done!

  1. JavaScript in the middle of an external CSS.

    Why not place it together along with the code above!

  1. Just Wow: Internal JS > CSS > External JS > Internal JS

    CSS surrounded between JavaScript and JavaScript surrounded between CSS!

  1. Where are your code conventions Mr. Rediff?

    See the CSS classname ‘Naming standards’

  1. Rediff’s way of importing external JS!

They are using JavaScript to import another JavaScript code!

Look carefully!



  1. Debugging debris remains…

  1. Reuse the code, but not in the same page man!

    I saw this CSS defined AGAIN somewhere below the code!
  2. What a waste of memory!

    Everything commented inside the function, what does this function do then?!



  1. Agreed we all use broadband, but what a waste of Bandwidth?

Why so many wide spaces!

Don’t you guys know browser ignores them but bandwidth network doesn’t!


  1. Broken Link

Wanna report?

  1. Total time over 512KBPS

    No comments!

  1. 19 Requests to the server! Woah!

    Thank you that I have an advance browser to do these for me!

  1. So many DNS resolutions

    My ISP might think I am doing a DNS attack!




16. Best of all:

Around 8 MB of Memory occupied by just 41KB of HTML code!



Single line of HTML crashes IE 6

Wednesday, August 8th, 2007

A Japanese blogger who goes by the name Hamachiya2 has discovered a single line of HTML and CSS that crashes IE 6. The line is:

<style>*{position:relative}</style><table><input></table>

If you’re brave, you can click here to try it out. The code is rendered correctly in Firefox, Safari and Opera (didn’t get a chance to try any other browsers, but presumably they work too). But in IE 6 it raises a fatal error in mshtml.dll.