Wednesday, November 6, 2013

ReplaceAll Function in Javascript

Replace All Function in Javascript : Implemented through Recursion
 function replaceAll(word, text, newWord){
  var pos = text.search(word);
  if(pos == -1)
   return text;
  var str1 = text.substr(0, pos);
  var str2 = replaceAll(word, text.substr(pos+word.length), newWord);
  return str1+newWord+str2;
 }

Sunday, October 6, 2013

Prolog - XSB Execute Prolog in Command Line and drop result in file.

Here I would like to discuss on How to execute a Prolog Expression, and store the result in a file,
Also Execute the prolog Expression through Comand line,

Solution:
For implementing the Prolog, I have chosen XSB:
Once the XSB is installed, I kept the XSB/bin folder in System variables, so that I can execute from command line from any locations.

WRITE Operation in Prolog:
For writing the content to a file, Similar to any Streams in programming Language we can set the Streams here as follows.

open('RESULT_1380695160492.txt', write, H),
    tell(H),
    write('Hello World'),
    told.

First we open a file and assigned to a Handler H.
Method tell(H) : it will change the Stram to the provided Handler H.
told: Works as Stream writing is completed, and it will close the file.

Example : Evaluation of recursive Expression to a File.

Find the indirect paths from the provided direct paths.
Expression:

File Name : direct.P
direct(a,b).
direct(b,c).
direct(c,d).
direct(d,e).
indirect(X,Y):-direct(X,Y).
indirect(X,Y):-direct(X,Z), indirect(Z,Y).

calc :- open('TEST_RESULT_FILE.text', write, H),
tell(H),
calcResult,
told,halt.

calcResult :- indirect(X,Y),
    write(X),write('   '), write(Y),nl,
    fail.

calcResult.

To execute this program from command line, Execute the following command.

xsb -e [direct], calc.    //Here direct is teh file name.

It will Execute the Command and store the result in the file Called : TEST_RESULT_FILE.text

The result is as follows.
a   b
b   c
c   d
d   e
a   c
a   d
a   e
b   d
b   e
c   e

Regards
Asker Ali M

Wednesday, June 26, 2013

Node.js - A Simple example for starting up


I have been trying to understand what is this Node.js, Got confused, and went through the Google to find the simple working of it, Finally I got a wonderful example in the following Link.


It is Awesome, Some codes are Depticated, you can use teh following code to avoid warning.

var express = require('express');
var app = express();


Thursday, April 25, 2013

Scala Cross Compilation Issue with Different Versions - Unknown Scala Classpath Problem


Scala Eclipse Compilation Issue:
scalatest_2.10-1.9.1.jar is cross-compiled with an incompatible version of Scala (2.10). In case of errorneous report, this check can be disabled in the compiler preference page.

Solution:
I feel The Issue  is the Eclipse is Using the Library of Scala 2.10, But the eclipse Plugin is compiled of Scala 2.09.

I got resolved this issue By Downloading Eclipse Juno, and Installed Scala Pluggin, which is compatible with Eclipse.

The Version of Scala Plugin is 3.0.0.v-2_10

Hope it will Resolve your Issue.

Regards
Asker Ali M





Friday, January 11, 2013

Draw Arrow in HTML5 Canvas.

In this tutorial we are going to draw two lines in HTML5 Canvas.



  1. An Arrow with Stroked Head
  2. An Arrow with lines as head














  
  HTML5 Canvas - Draw Arrow