Thursday 31 January 2013

Top 3 Google chrome tricks

Data urls in the browser search field of the form given below will cause the browser to treat it as a syntax ,

 data:text/html,<HTML code can invoke javascript>



1.Speech to text

Just type

data:text/html, <html><body><input type="text" x-webkit-speech /></body></html>

in search field.

2.Notepad in browser

Type

data:text/html,<html><script>var saveIt = function() {document.location = 'data:text/html,' + document.childNodes[0].outerHTML;}; var updateId = function() {document.title= document.body.innerText.replace(/\n[\s\S]+$/," - ")+new Date().toString();}; window.setInterval(saveIt, 30000); window.onload=function(){var a=document.body;a.addEventListener("keydown", function(b){if(b.ctrlKey&&83===b.which){saveIt();b.preventDefault();}},!1);updateId();};</script><body contenteditable></body></html>

in search field

3.Chrome offers loads of features, type  chrome://chrome-urls

Lets see some interesting chrome-url features.

Check out chrome://predictors/   ,Chrome actually learns your browsing pattern by predicting the urls as you start typing.The larger the hit count the more successful it is in predicting your intentions !!

chrome://cache shows a list of all the url's that has been cached .It's a good place to observe all urls that have been processed by chrome.Including the url's that belong to ads,analytics,images etc.

chrome://credits/ shows you a list of tools that has been used in developing chrome

chrome://dns/ provides a complete domain name server activity with statistics included.

For those who want to check out the flash plugin in your browser
Go to   chrome://flash/


There is also an option to trace browser activity with regards to resources in use,
in chrome://tracing . start tracing ,open a new tab and load a page,later when the page is loaded you can stop the tracing and check the resource usage of the webpage.

if you want to view resource usage as a task manager, use shift+esc it will open up a chrome specific task manager


Similarly  chrome://memory will indicate the memory in use of all the tabs.

Complete network statistics can be obtained at chrome://net-internals






Linux File system

VIRTUAL FILE SYSTEM
Linux has a virtual file system(VFS) , which is sort of a kernel layer which is responsible in providing a common interface all file systems.Thus you can invoke file related system calls (reading,writing etc) to different file systems be it  ext3,ext4,VFAT etc.
Those of you using windows as well as linux in your machine would know that you can mount a windows defined C drive (FAT or NTFS) in linux environment but windows dosen't allow you to mount linux (ext*) file system (Use ext2explore software for mounting ext2 in windows).

Thus all your file related system calls is screened by a VFS , what it does is,it observes the system call to a particular file system and handles the structural manipulations and translates the user system call to physical file system code which then can be used to perform the file chores for a given file system.


Thus the VFS stores information related to mounted file system,such as blocksize,inode and dirty flag etc.Which it uses while translating system call to file specific commands


INODES
All resources in linux such as hard disks, serial ports, memory etc are treated as file objects.Each file is represented by a structure called inode.Inode contains all information about the file such as file type,access rights,time stamps,size etc.



The directories are implemented as files composed of list of entries ,each indicating the inode number and file name,where each entry identifies a file in the directory.

Linux scheduler

The most fundamental part of any operating system is its scheduler which manages all the processes (tasks) in the OS.
If you look into /usr/src/linux-headers/include/linux ,you will find all the system files which makes up the kernel .Here search for sched.h ;This would be our scheduler and if you open it in a text editor,you will find a task_struct structure.

 This represents the process control block(PCB) which is a datastructure holding all essential details of a process

you can view a partial PCB of a process by
$ cat /proc/pid/status  

here pid is the process id of the process ,whose status you want to view.



PCB is composed of all details needed for running a process along with details of resources which a process has access to,and the scheduler uses it for context switching or switching between process for CPU access .


Kernel keeps a list of process descriptors wherin a doubly linked circular list is maintained ,this linked list is composed of all process descriptors including the init.


Here each block is a PCB for that task, Now the scheduler needs to make a list of tasks which are ready to be executed.The ready queue is implemented in this circular linked list itself .


Here the scheduler just have to know the pointer to the beginning of the queue and to the end.The red arrows indicate the pointer from 1 PCB to the next in the ready queue.Similarly a wait queue can be maintained just by managing pointers in the PCB.The next process to be run is determined  by Struct task_struct *next_run; 


Source codes for scheduling algorithms using pthreads in c are available here

Wednesday 30 January 2013

Making a script run as an app in ubuntu launcher

Don't we all love to execute scripts without the geeky looking terminal ?, say we have a shell or a python or a tcl-tk script ,we want now to run this as any app with an icon, Well there is a way.

Install gnome panel by using
$ sudo apt-get install gnome-panel


gnome-panel is just a taskbar application in desktop for ubuntu.

Once the installation is done type
$ gnome-desktop-item-edit --create-new ~/Desktop

you will then observe a create launcher applet , select type as Application
Give any funky name you want for your application.
And in the command field, provide the command which you use to run your script in the terminal.

so to run a tcl-tk application , use wish path_name/file_name.tcl


 You can now click the icon to run your script.

You can also edit your application icon , just open it in gedit , the icon is saved as name.desktop

in the above case someapp.desktop



#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_IN]=python
Exec=wish path_name/file_name.tcl
Name[en_IN]=someapp
Name=someapp

extracting emotion from text

Here we shall look at a simple procedure to perform a sentiment analysis of the given text,

We proceed by making a list of words and associating with a value indicating the degree of emotion conveyed by the same.

something like :

awesome 4
bad -3
sad -3
cool 2

etc

Here the positive value indicate a positive emotion ,and the negative with negative emotion conveying words.The value indicate the degree of emotion conveyed by that word.
Now all we have to do is demarcate the text into constituent words and individually look up in this list,and sum up or take the average of the corresponding value to get the emotion value conveyed by the text.You can be wise enough to avoid usage of "stop words" in the list as they do not convey any meaning. 

Personally i adore python for the awesome text processing capabilities , you can use the text as key and look it up as a dictionary ,have a look here.

 A front end browser with a backend python script computing the emotion conveyed.

You can also use twitter to get general opinion on a particular topic

use http://search.twitter.com/search.json?q=topic_name

 (all spaces in topic_name is to be replaced with +)

Twitter returns data in json format which you have to parse to extract the texts and use your python script to compute the emotion values which you can add or average as a whole to get general opinion



Using google map service without API key

To use google map service, you are instructed by the developer manual to generate an api key using your google account.You may have to cough up money to google if the number of hits to your site increase beyond a certain number.

But can we do the same sans api key ? +

Yes, well at-least for the geocoding and reverse geocoding service.

All you have to do is to ping :  https://maps.google.com/maps?q="location name"

example  https://maps.google.com/maps?q=washington or https://maps.google.com/maps?q=new+york

see how i replace spaces with + in the url.

To use it locally request data in json format, something like https://maps.google.com/maps?q="location name"&output=json

All you have to do is parse it for the required fields and there you have it,your data with no api key. Don't we love free stuff !!