Archive for January, 2012

How to connect SQLPlus without tnsnames.ora entry

January 31, 2012

In some weird companies, like the one am working, will restrict many things in our machine which will reduce the productivity. Recently I was trying to add a new entry in tnsnames when our database server got changed. And hell, I was not having rights to change the tnsnames file in my local machine!!! WTF!!! At the end of day I need to run one sqlplus command from the command prompt. SQLPlus needs an entry in the TNS Names file in order to work. Then I found out an way to execute the command by directly giving the connection string in the sqlplus command itself. Like this :

sqlplus username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost.mydomain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)))

BINGO! It works as hell. Please remember that there shouldn’t be any space in the connection string, also no carriage return (which might happen if you are copying the string from the tnsnames file.

Thats it guys. Happy Coding. 🙂

Echo Current Date and Time in Batch File

January 24, 2012

How stupid I am! In one batch file I need to print the current date and time and I googled for 5 mins to find it out. 😛 So here it is. For the other guys like me. he he.

ECHO Starting stored procedures execution at %date% – %time% >> log_file.log

Happy Coding. 🙂

Adding Glow to a Shape in AS3

January 12, 2012

Adding a glow to a programatically drawn shape is very easy in actionscript. We just need to create the GlowFilter object and apply it to the filters property. A quick example is follows

var whiteGlow:GlowFilter = new GlowFilter(0xFFFFFF, 0.8, 30, 30, 1, 1, false, false);

var sp:Sprite = new Sprite();
this.addChild(sp);
sp.graphics.drawCircle(100,100,50);
sp.filters = [whiteGlow];

That’s it. Similary you can add other filters such as GradientFilter, BlurFilter, etc. For a detail list of the available display filters refer the livedocs : Available Display Filters.

Happy Coding guys. 🙂

Drawing Circle Segment using Flex / AS3

January 12, 2012

I was working on an application which required to draw a circle using three different circular segment. First it seemed to be easy, but later found out that I needed to learn by trigonometry books again to achieve this. So here it is drawing a circle segment. You need to know the start point and end point of the arc, the center cordinates and the radius.

public function drawSegment(holder:Sprite,  startAngle:Number, endAngle:Number, segmentRadius:Number, xpos:Number, ypos:Number, step:Number, lineColor:Number, fillColor:Number):void {
     //holder-display object, xpos and ypos-center
     holder.graphics.lineStyle(2, lineColor);
     holder.graphics.beginFill(fillColor);

     //If we need to draw a segment from greater angle to smaller angle, split it at 360 degrees and draw two times
     var originalEnd:Number = -1;
     if(startAngle > endAngle){
          originalEnd = endAngle;
          endAngle = 360;
     }
     var degreesPerRadian:Number = Math.PI / 180;
     var theta:Number;
     startAngle *= degreesPerRadian;
     endAngle *= degreesPerRadian;
     step *= degreesPerRadian;

     // Draw the segment
     holder.graphics.moveTo(xpos, ypos);
     for (theta = startAngle; theta < endAngle; theta += Math.min(step, endAngle – theta)) {
          holder.graphics.lineTo(xpos + segmentRadius * Math.cos(theta), ypos + segmentRadius * Math.sin(theta));
     }
     holder.graphics.lineTo(xpos + segmentRadius * Math.cos(endAngle), ypos + segmentRadius * Math.sin(endAngle));

     if(originalEnd > -1){ // Start angle was greater than end angle and drawing the second segment
          startAngle = 0;
          endAngle = originalEnd * degreesPerRadian;
          for (theta = startAngle; theta < endAngle; theta += Math.min(step, endAngle – theta)) {
               holder.graphics.lineTo(xpos + segmentRadius * Math.cos(theta), ypos + segmentRadius * Math.sin(theta));
          }
          holder.graphics.lineTo(xpos + segmentRadius * Math.cos(endAngle), ypos + segmentRadius * Math.sin(endAngle));
     }
     holder.graphics.lineTo(xpos, ypos);
     holder.graphics.endFill();
     }

From the updateDisplayList method you can call the drawSegment method like this :

drawSegment(this, 270, 30, radius, uw/2, uh/2, 2, 0xEEEEEE, 0x003da8);

The idea is very simple. First draw line from the centre point to the starting point of the arc. Then keep on finding the next point in the circumference through which our arc will be passing. Then draw lines between these points until the end point is reached. After that draw the last line from the end point of the arc to the centre point.

The method considers horizontal point to the right side as angle 0. If we need to draw the line between say, angles 270 and 120, we will split this into two arcs. One from 270 to 360 and second from 0 to 120. We can tune it further to create simpler methods.

That’s it guys. Happy Coding. 🙂