PoiNtEr->: April 2011

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Monday, April 25, 2011

CLIPS {c language integrated Production system}

CLIPS is a public domain software tool for building expert systems.

Install CLIPS:
On Ubuntu : sudo apt-get install clips
on terminal

for Windows and MacOs:
click here

Facts and rules:

 At its most basic, CLIPS operates by maintaining a list of facts and a set of rules which operate on them. A fact is a piece of information such as (colour green) or (parent_of John Susan). Facts are created by asserting them onto the fact database using the assert command. Here’s an example, complete with the response from CLIPS:

    CLIPS>(assert (colour green))
The part is the response from CLIPS to say that a new fact (fact number 0) has been placed on the fact database. The (facts) command will list all current facts. Try it, and you’ll get the following:
    CLIPS>(facts) f-0 (colour green) For a total of 1 fact.
Facts may also be retracted (removed) from the fact database by using the retract command. As an example, assert two facts as shown:
    CLIPS>(assert (colour green)) CLIPS>(assert (colour red))
Then retract the first fact and display the fact list:
    CLIPS>(retract 0)CLIPS>(facts)f-1 (colour red) For a total of 1 fact.
There are two things to note here: firstly, to retract a fact you must specify a number (the fact-index), not the fact itself, and secondly, fact-indices are not reused. Once fact 0 has been retracted, the next fact asserted will have the index 2, not 0.
Facts on their own are of only limited use. The application of rules is necessary to develop a program capable of some useful function. In general, a rule is expressed in the form ‘IF something is true THEN do some action’. This kind of rule is known as a production. For this reason, rule-based expert systems are often known as production systems (CLIPS actually stands for C Language Integrated Production System). In CLIPS, a typical rule looks like this:
    (defrule duck
      (animal-is duck)
      (assert (sound-is quack)))
The rule consists of three parts. The first part, (defrule duck, simply gives the rule a unique name. The second part, (animal-is duck), is the pattern (the IF part) of the rule and the last part, (assert (sound-is quack)), is the action (the THEN part). In plain language, this rule means ‘if there is a fact (animal-is duck) on the fact database, then assert another fact, (sound-is quack), onto the fact database’. Try it. Clear the system, then type in the rule exactly as printed above. Typing (rules) will give you a list of rules (just the one, in this case) present in the system. At this point, there are no facts present. Now, type (assert (animal-is duck)). Check the fact list - there’s one fact. To trigger your rule, type (run). Although nothing appears to happen, if you check the fact list again you’ll see that there is a new fact, (sound-is quack), which has been inferred by the rule. This is the power of rule-based programming - the ability to make inferences from data, particularly as the results of one rule can be used as the pattern for another. Add the rule
    (defrule is-it-a-duck
      (animal-has webbed-feet)
      (animal-has feathers)
      (assert (animal-is duck)))
Then type (reset) to clear the facts (the rules will be untouched). Note that this rule has two patterns. Both must be satisfied for the action to be taken. This translates to ‘IF the animal has webbed feet AND the animal has feathers THEN the animal is a duck’ (taxonomists and pedants may disagree with this rule). If you now assert the facts (animal-has webbed-feet) and (animal-has feathers) there will be two facts present. (run) the rules, and suddenly there are four. Firstly, rule is-it-a-duck has fired, asserting the fact (animal-is duck). This fact has then triggered rule duck, which has asserted the fact (sound-is quack). Very powerful systems can be built using this ability to chain rules.
Asserting facts is a rather unsatisfactory way of presenting results. Type in the first rule again, this time with the multiple actions as shown below:
    (defrule duck
      (animal-is duck)
      (assert (sound-is quack))
      (printout t "it’s a duck" crlf))

 {*well i am working on Expert system Project these days so if you have any problem related to expert system just comment below*}

Sunday, April 24, 2011

Reset USB Modem on Ubuntu without ejecting it!!

$ lsusb
This will print out all USB devices connected system bus:

Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub                                                 
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub                                                 
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub                                                 
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub                                                 
Bus 001 Device 007: ID 19d2:1010 ONDA Communication S.p.A.                                                     
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
In my case the line:
Bus 001 Device 007: ID 19d2:1010 ONDA Communication S.p.A.  
is my Vodafone USB mobile broadband device, where 19d2 is vendor ID and 1010 is product ID. Now that we have this information we can attempt to reset it with usb_modeswitch. Switch to root and execute the following command with the information you retrieved previously:
# usb_modeswitch -R -v 19d2 -p 1010
Looking for default devices ...                                                                                
 Found devices in default mode or class (1)                                                                    
Accessing device 007 on bus 001 ...                                                                            
Using endpoints 0x01 (out) and 0x81 (in)                                                                       
Using endpoints 0x01 (out) and 0x81 (in)                                                                       
Not a storage device, skipping SCSI inquiry                                                                    
USB description data (for identification)                                                                      
Manufacturer: Vodafone (ZTE)                                                                                   
     Product: Vodafone Mobile Broadband K3571-Z                                                                
  Serial No.: P680A8VDFD000000                                                                                 
Warning: no switching method given.                                                                            
Resetting usb device .                                                                                         
 OK, device was reset                                                                                          
-> Run lsusb to note any changes. Bye

APT Package Manager in Debian

APT package manager in Debian systems can be used to download and install packages from online repositories. The APT commands (apt-get, apt-cache, and so on) can be used to install packages locally. However, it’s normally used for working with online software.
sudo apt-get update
Consults /etc/apt/sources.list and updates the database of available packages. Be sure to run this command whenever sources.list is changed.
apt-cache search
Case-insensitive search of the package database for the keyword given. The package names and descriptions are returned where that keyword is found.
sudo apt-get install
Download and install the given package name as found in the package database.
sudo apt-get -d install
Download the package only, placing it in /var/cache/apt/archives.
apt-cache show
Display information about the software from the named package.
sudo apt-get upgrade
Check updates for all installed packages and then prompt to download and install them.
sudo apt-get dist-upgrade
Updates the entire system to a new release, even if it means removing packages. (Are you on nuts to do this?)
sudo apt-get autoclean
Can be run anytime to delete partially downloaded packages, or packages no longer installed.
sudo apt-get clean
Removes all cached packages from /var/cache/apt/archives to free up disk space.
sudo apt-get –purge remove
Remove the named package and all its configuration files. Remove the –purge keyword to keep config files.
sudo apt-get -f install
Do a sanity check for broken packages. This tries to fix any “unmet dependency” messages.
apt-config -V
Print version information of installed APT utilities.
sudo apt-key list
List gpg keys that APT knows about.
apt-cache stats
Print statistics on all packages installed.
apt-cache depends
Print dependencies for a package (whether it’s installed or not).
apt-cache pkgnames
List all packages installed on the system.

Saturday, April 23, 2011

HTML5 Speech Recognition

(Requires Chrome browser).
Note: The demo uses the Google Speech API. At the time of this writing, not all browsers yet support this HTML5 feature. We have found it works in Google Chrome. Furthermore, I have only tested it successfully with Windows 7.
The only change was to replace
<input type="text" size="60" name="input"/>

<input type="text" size="60" name="input" x-webkit-speech />

There are a couple of "tricks" you need to know to test the speech API:
1. Click on the little mic icon to begin speaking. The speech API will detect when you have finished speaking and, when it has finished processing, will display the text it detected in the text area.
2. If you are satisfied with what the speech API detected, click the "Say" button to transmit it to the bot.
The quality of the speech recognition may not seem very high. There are a number of factors that affect the accuracy of speech recognition: the quality of the microphone, background noise, the accent of the speaker, the type of sound card on your computer and so on.
Enabling Chrome Voice API
The Chrome voice recognition API may not be enabled by default. Follow these steps to create a shortcut to Chrome with voice recognition enabled.
1. Create a desktop shortcut to Google chrome with copy and paste. (You may also want to rename this shortcut something like "Chrome Voice").
2. Right click on the shortcut and select "Properties"
3. On the Shortcut tab, modify the Target field to include the flag "–enable-speech-input". For example if the Target was originally
change it to
C:\Users\drwallace\AppData\Local\Google\Chrome\Application\chrome.exe –enable-speech-input
4. Click OK and use this Chrome Voice shortcut to enable speech recognition

Defusing Fork Bomb ,limit user environment on ubuntu(linux)

Whether it is user intention or just accident it may happen, that a single user can eat up all available system resources such as RAM memory or disk space. Depends on the nature of you Linux system you may want to limit your users to only what they might actually need.
Let's start with something like a fork bomb:
:(){ :|:& };:
The line above can almost instantly consume all resources since it creates recursive function all to it self as it forks unlimited children processes. One does not even need a root privileges to crash your Linux system. What about to limit user by a number of process he/she can spawn:
NOTE: All limits are applied to a current shell session only. To make a permanent change system wide use /etc/profile .
$ ulimit -u 10
$ :(){ :|:& };:
bash: fork: retry: Resource temporarily unavailable
This takes care of the fork bomb problem. But what about disk space? Linux command ulimit can limit users to create files bigger than a certain size:
$ ulimit -f 100
$ cat /dev/zero > file
File size limit exceeded (core dumped)
$ ls -lh file
-rw-rw-r--. 1 linux commands 100K Feb 21 18:27 file 
Some extreme examples:
With ulimit it is also possible to limit a maximum amount of virtual memory available to the process:
ulimit -v 1000
[lilo@localhost ~]$ ls
ls: error while loading shared libraries: libc.so.6: failed to map segment from shared object: Cannot allocate memory
Limit a user by number of opened files ( file descriptors )
$ ulimit -n 0
$ echo ulimit > command
bash: command: Too many open files
To check all your current limits use -a option:
$ ulimit -a

Friday, April 22, 2011

Install NoteBook Remix on Ubuntu 10.04


Take the synaptic package manager

System => administration => Synaptic Package manager

search for the package netbook-launcher-efl . Click on it and select the mark for installation. Click on the apply button to start downloading the package and installing it.

After installing, take the gnome-terminal and type in as follows

$ netbook-launcher-efl

Then the netbook launcher application will start in the next moment.

You can add this netbook launcher to load automatically everytime you boot. Take the startup application from System => Preferences => Startup Applications

Click on the add button and type in the textbox corresponding to the command as 

Thats all... enjoy the Netbook remix in your box...

fork bomb :({}:)

***Don't try this @ your home ....Injurious to your computer's health***
Defining the fork bomb . . .
A fork bomb is simply a line of some characters entered into the command line of a Unix system, and when the enter key is pressed, within seconds the computer will crash... The little program we entered in to the bash shell act as a process & make multiple copies of itself, setting off a chain reaction and thus quickly exhausting the system’s resources. Most computer operating systems can be simply crashed or at least brought to a coma stage when users, even those without superuser privileges, launches this 'logical bomb' that eat up all memory and CPU time. "Forkbomb" does nothing but launch two or more copies of itself upon startup. Since these copies do the same in turn, this sets off a chain reaction with an exponentially growing number of processes. A fork bomb process "explodes" by recursively spawning copies of itself using the Unix system call fork().
Working of the 'bomb'...
A process begins execution when it's execution environment and corresponding threads are created. Before execution the process has to take a room in the process table, which is a data structure for holding information required by the kernel to run the process such as...
> Process state
> Several process IDs
> User IDs for determining process privileges
> Pointer to text structure for shared text areas
> Pointer to page table for memory management
> Scheduling parameters, priority values
> Timers for resource usage etc...
A fork bomb creates a large number of processes very quickly and begins execution one after the other by seizing the process table. So whenever a free slot occurs in the process table, another copy of the bomb process enters it and start spawning new bombs. When process table becomes saturated, no new programs may start until another process terminates. Even if that happens, it is not likely that a useful program may be started since the instances of the bomb program will each attempt to take any newly-available slot themselves.
In addition to using space in the process table, each child process of a fork bomb uses further processor-time and memory. As a result of this, the system and existing programs slow down and become much more unresponsive and difficult or even impossible to use.
see the defenition for fork bomb in wikipedia,
In computing, the fork bomb is a form of denial-of-service attack against a computer system which makes use of the fork operation (or equivalent functionality) whereby a running process can create another running process. Fork bombs count as wabbits: they typically do not spread as worms or viruses. To incapacitate a system, they rely on the (generally valid) assumption that the number of programs and processes which may execute simultaneously on a computer has a limit.
Some bombs that you can try @ your friend's pc
Fork Bomb in windows
Open up notepad and type the string below and and save
it as fork.bat :
On double clicking this file,it will lead to total CPU jam
by opening a large no. of processes of command prompt.
In UNIX C or C++:
Compile and execute the following C/C++ code snippet
in Unix to understand (???) the bomb...
int main(void)
for(;;) //for(;;) or while(1) makes an infinite loop
return 0;
Bash Shell Fork Bomb
Following is the most coolest one i had ever seen. Take the bash terminal and just type in the following code....
: (){ : |:& };:
This code is the elegant and most beautiful example of a fork bomb.
:() _ define ':' , like a function call
{ _ beginning of what to do when we say ':'
: _ load another copy of the ':' function into
| _ ...and pipe its output to...
: _ ...another copy of ':' function, which has to be
loaded into memory (therefore, ':|:' simply gets
two copies of ':' loaded whenever ':' is called)
& _ disown the functions, that is if the first ':' is
killed, all of the functions that it has started
should NOT be auto-killed...
} _ end of the definition of ':'
; _ Having defined ':', like in structures etc... we
should now...
: _ ...call ':', initiating a chain-reaction: each ':' will
start two more.
Simply the above function is the same as the code below
forkbomb(){ forkbomb|forkbomb & } ; forkbomb
How to get out of the bomb . . .
One may have to reboot the system to resume its normal operation destroying all running copies of it. Trying to use a program to kill the rogue processes normally requires creating another process — this is an impossible task if the host machine has no empty slots in its process table, or no space in its memory structures. Furthermore, as the processes of the bomb are terminated (for example, by using the kill command), process slots become free and the remaining fork bomb threads can continue reproducing again, either because there are multiple CPU cores active in the system, and/or because the scheduler moved control away from kill(8) due to the time slice being used up.
A simple solution is that we can stop (“freez”) the bomb's processes, so that a subsequent kill/killall can terminate them without any of the parts re-replicating due to newly available process slots:
killall -STOP bombprocess
killall -KILL bombprocess
...Bye till the fire and smoke settles...