Sunday, October 19, 2014

ok in this post I will try to explain a somewhat difficult concept, javascript closures.
I will try to explain the concept of closures in a very practical oriented way.
so simply put javascript closures allow you to define some kind of privacy, umm sort of like private fields in java, c++ etc.
So anyway we know that javascript has no direct notion of private variables. so variables are either public scope or local.

More specifially , what I mean is that there is no simple way to do the following in javascript

//a java example
class Counter
{
private int counter=0;
public int add(){
counter++;
return counter;
}
}

//okay so in java we could use this class as
public class myclass
{
public static void main(string args[]) 

Counter ct=new Counter();
ct.add(); 
ct.add(); 
int res=ct.add(); 
system.out.println(res); //so result is 3 
ct.counter=23423; //wrong . you cannot access a private variable directly
}
}

so if we were to do this example in javascript we could do this as (using the google chrome console)

var counter=0;
function add(){
counter++;
return counter;
}

//so we use as
add();
add();
var res=add();
alert(res);
counter=45235; //THIS IS ALLOWED

you see the problem?. we can have access directly to the counter variable in javascript whereas in java we cannot
so how do we make the counter variable private .

okay so we will use concept of local scope in javascript.
what I mean is
function Counter()
{
var counter=0;
}

so now we cannot do this

counter++; //WRONG. counter is not defined in global scope

oh cool. But but how do you access the counter variable at all ??
remeber we still need to increment the counter variable from outside.

okay for that we will create a function inside the function Counter

function Counter()
{
counter=0;
 function add()
 { 
 counter++;
 return counter;
 }
}

yes this is allowed in javascript, in case you were wondering
oh good. so we have a private variable, a function to modify that.

so now can we do this??
add();
No we can't , as add() is local to the Counter() function.
so what we do is , we need a reference to the add function. Then we can call it
What i mean by the above line was this
function message()
{
alert("hello world");
}
var a=message; //get a reference or pointer to the above function, whatever you like to //call it
a(); //so alert is displayed 

Again in case you were wondering, yes this is possible in javascript. functions are treated as normal variables.

so in the example of Counter() function , we need to get out a reference to the add funcion to the outside world.
so we have, finally

function Counter()
{
var counter=0;
function add()
{
counter++;
return counter; 
}
var a = add; // get a reference to the function add
return a; //and send it to the outside world, by way of specifying it as the return value
}

So in the above function, we are returning a reference to the function
That is function Counter() does not return a string, number etc. It returns another function.
Or more precisely, a reference to the another function

so now we can use this as
var a=Counter(); // Counter() executes and returns a reference to the add function inside it
a(); //so the variable a points to function add() defined inside the function counter
a();
var res=a();
alert(res): //so displayes 3

Thursday, February 20, 2014

Screenreader is a google chrome extension (it's completely FREE) to read ebooks aloud, with single key presses to jump to next/previous sentence

Find it on the chrome web store screenreader standalone

 The idea is simple.Since reading ebooks while looking at the computer screen causes eystrain and headaches, the extension provides a very simple way to read aloud the text. You can
 jump from one sentence to another, read same sentence multiple times , jump to a particular point and read from there etc.Also importantly, using the software you can put your own pronounciations
 for words , as read "not equals" for "!="  etc. Also importanty you can specify pronounciations for unicode characters as alpha, beta etc. The program is targeted primarily at normal sighted people and not blind people.
 Infact i am using it myself to read any ebooks,tutorials etc. and give my eyes a rest(I can see quite well ). Infact using it you can avoid eye work almost completely(while reading only, of course) and avoid
 all of eye strain problems while working at computers. also you need not assume a constant pose( thus avoiding back problems etc). you can just lean your head down, since you are only listening.
 Just press a single key and you can jump to next sentence,prevois sentence, jump to sentence start, read word by word, i.e press a key once
 to read next word only etc.
Next version will have the option of holding down a specific key , for example ctrl key. This can be very useful in situations like when an application repeatedly requires a specific modifier key to be held and also helpful for certain games.

Saturday, January 11, 2014

Auto Keypresser Introduction

Keypresser is simple program for generating repeated keypresses.It will keep on generating and sending keystrokes to the current active application.
it can be useful in situations where you want to generate repeated keypresses . Maybe like generating f5 repeatedly and keeping your web browser in foreground to refresh some website.
Detailed input info is given below:
Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}". To specify brace characters, use "{{}" and "{}}". Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that might be significant when dynamic data exchange (DDE) occurs.
Caution noteCaution
To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes in the following table.
Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC} (reserved for future use)
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
Keypad add {ADD}
Keypad subtract {SUBTRACT}
Keypad multiply {MULTIPLY}
Keypad divide {DIVIDE}
To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.
Key Code
SHIFT +
CTRL ^
ALT %
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
Eager to hear feedback

This was the introduction to auto keypresser. To view more
updates regarding it, click the Auto Keypresser label above.








To explore about my other programs check the other labels above.