Friday, May 31, 2013

javascript lesson 3

this is my continuation to last lesson.

Here learning about for loops

the for loop is very similar to 'C'

for ( var initialize; var condition; var increment){
...
}
ex:
for (var counter = 1; counter < 5; counter++){
console.log(counter);
}

Arrays in javascript can store different types of data at same time
ex:
var mixed = [ 23, "us" , 44];

syntax for array is : var name = [var, var, ..];
** the counting inside a array is started from 0

**we can use .length for both arrays as well as strings

**some strings or texts could be quite long, so put '\' backslash at end of each line to wrap to the next line of editor. Best way to avoid using long line

** .push for elements to push to array
ex: array.push(a[0]);   here we are pushing element 1 of 'a' to array

while loop is very similar to 'C'
syntax:
while(condition){
do something
}

we check condition by '===' ex:  if ( a === 0) {}

** to make sure loop runs atleast once we use 'do while' loop

to print a bool value, and we use String() function, actually string converts anything to string format
ex: var b = true; console.log(String(b));   output is 'true'

learn a word a day 3

previous words of the day are

facetious and fastidious

todays word is "Motif"

: A decorative design or pattern
: A distinct feature or dominative feature or theme in a artistic or literary composition

the motif of my story is very similar to that of 'game of thrones'

javascript lesson 2

i decided not to learn the git basics now, i need to concentrate more on completing the javascript tutorial on codeacademy.com, this is more important.

so javascript again

so learning about functions now,

how to define a function in javascript
syntax here

var nameoffunction = function(parameters){
...
};

ex:
var dividebythree = function(number){
    var val = number / 3;
    console.log(val);
};
//calling a function

dividebythree(9);

Here in the syntax, the keyword function tells the computer it is a function not something else. ***Remember to end the function } with a semicolon;

When we call a function we don't always want to print stuff, sometimes we want to return something.
So we use 'return' keyword which ends the function and returns the value that came out of the function

ex:
var fuc = function(parameter){
    return par;
};
here the o/p of the fuc function is value of 'par'.

any global variable can be used inside a function, but it is not a good habit to define many global variables.

**Math.random() function will return a value between 0 and 1
doing a mini project in the training course

** to check the variable type in javascript , use typeof() function
ex:
if (typeof(x) !== 'number') {
           return "wrong";
}


Thursday, May 30, 2013

After seeing myself waste a lot of valuable time, i decided to log my time usage fastidiously, i hope no one gives a facetious remark or comment on this post for telling this.
I really need to see where and how, how much i am wasting time in a day.

My log starts now, that is 10:06 AM in India, 31st may, i going to take a bath

10:28 AM bath is over

10:29 AM trying to read about git, but digressed due to break fast and watching 'the dark knight'

10:50 AM starting to read about git basics

11:01 AM stopped reading git, first need to complete my javascript training. anyway i wasted these 10 min on reading some stupid news

11:15 AM power is gone, till then i completed 2 sub parts of the training. So started reading this book 'Making ideas happen' which actually inspired me to write this blog. As you can see the motif in all the posts is my struggle to organize and execute ideas. I read and ate lunch.

3:15 PM Finally finished reading the book after so many days since power came just now. After this Wasted time for 1 hr

4:15 PM After wasting 1 hr time, i decided to start my training in javascript again, but i have to digress to write this blog as well as correctly define and refine my projects for the next few days without any distractions this time.

4:30 PM I finished updating my goals in my skydrive notebook.

4:31 PM Now for the training part in codeacademy

5:20 PM taking a break now

6:51 PM wow, a lot of time for break, this may look facetious to you , but i am fastidious in my time management, i also ate food and went outside for some personal stuff. started studying 'introduction to algorithms' huge book

7:00 PM will start training javascript again.

7:12 PM 10 minutes wasted, just some stupid shit

7:47 PM again wasted 35 minutes on some stupid news obsession and something else

7:50 PM started training javascript again, albeit slowly and very less concentration

8:15 PM completed today's part, need to take a break to continue further

9:15 PM wasted time till now

9:16 PM started training again,

9:45 PM completed one more session starting next one after a 5 minute break

11:05 PM completed one more session taking a break


scripting language, javascript in html,

So now i am learning what is a scripting language?, it is a important question and could be asked in interviews.
scripting language is a programming language  that supports writing of scripts, which are programs written for a special run-time environment, that can interpret and execute the automation of tasks, which could alternatively be executed one-by-one by human operator.

Man i had to copy half of this meaning from wikipedia, it is really difficult to remember computer terms.

For a more subtler and simple definition, i am doing a google search . I still cannot find a simple meaning.

Javascript is mainly used by integrating into HTML and CSS. We can use the actions of mouse-click or hover and many more to write javascript and integrate it on client-side calculations or scripting.

So how to insert javascript in html page.

<script>
alert("My first script">
</script>

upto know , what i learned here in this post is executed when the page loads.
But we can execute scripts only when an event occurs,like when an user clicks a button.

We know that hml pages have two main parts, <head> and <body>

the <head> element is a container of all head elements like <title> which shows title of page.
others like <style> <base><link> and <script> and <noscript>

<base> tag can be used, so we can use relative addresses for images or files , because base stores the main address where they are stored.
Slowly this project is going down the drain,i am already experiencing low determination levels. I don't know what happened to my fastidious approach.
But one thing i am glad is i am able to use the words i am learning every day in the blog posts. I am glad that my blog doesn't have any facetious remarks or comments or thoughts.

I need to boost my determination levels, so i need your support guys, come on you can do it.

javascript lesson 1

I am learning javascript tutorial from that website i mention www.codeacademy.com
since it is very interactive not much to post here

//   - for writing comments

to open popup  boxes we use these functions
confirm();
or prompt();

we use prompt() cmd for example
prompt("what is your name?");

this function will take your name as input

the confirm() function will take input as 'true' or 'false'

.length counts every character in the string including spaces
ex: "i am good".length  gives o/p as 9

we can directly get evaluating expressions, for example 5<4 yields 'false'

strings are always in between the " "

console.log() shows what the interpreter is doing completely
ex: console.log(4*5)
console.log("hello")
the o/p shows all the steps including intermediate steps, not just the final result.
These console.log() can used to check how much or which direction did the javascript program traverse and line number as well

and the if loops are very very similar to 'C' language more than the shell scripts i learnt yesterday.
the syntax is
if (2 > 4)
{

}

as we all know that % is used to calculate remainder
4%5 gives 4

there is a substring function as well
ex: "wonderful day".substring(3,7);
this will output from 4th letter to 7th letter
remember the numbering in string starts from 0

To define variable in javascript, we do this

var variable1 = "string";
var number2 = 2;

another one of the most confusing things in the programming of any language is postfix and prefix increment/decrements

var++ : the o/p is evaluated but the old value is returned
--var   : the o/p is evaluated but the new value is returned

this is my first experience of the first part of tutorial , it is fun and very interactive  to learn using this website. I recommend it to anyone who wants to learn programming. This website pleases even the fastidious people as well.

javascript beginnings 1

So what's the way to learn javascript, it is not the first time, i tried to learn it. But this time i want to complete the whole journey rather digress and go along a different path completely ignoring it.

So i googled "best way to learn javascript", trying to find solution for my problems

I am a great procrastinator and extremely lazy, i need to be disciplined and learn this language as quickly as i can and start using it, instead of making it stagnant in my memory. I already know that, it has great applications especially in making addons , so i have to learn the basics quick and be resourceful to learn deep concepts along the way while doing projects rather than static learning. Since i realized it is futile at least for me.

I found a great interactive website to learn all the web-based languages. You should also check it out, it offers free learning in HTML,CSS, Javascript, PHP, Python, Jquery and others as well.
The website : www.codeacademy.com

I decided that there are no limits for the day, since the honeymoon period of learning new things is very brief, i am thinking of utilizing it for my full potential. Though learning after the honeymoon stage is the real test.

learn a word a day 2

yesterday's day is facetious: 
once again , the meaning: taking serious issues with deliberate and inappropriate humor
or humorous or amusing

Today's word of the day is 

fastidious : excessively particular or critical or demanding, hard to please
ex: a fastidious man who is a critic of movies

                    requiring or characterized by excessive care or delicacy
ex: i am not much of a fastidious man, but hope to become fastidious about these projects, because that's the only way i think, i can complete them for now

Wednesday, May 29, 2013

linux article 2 - for loop, if, vi editor, $?

From now onwards, i decided to save all my important documents esp educational material in dropbox, since it is available in all platforms and provides excellent usability.

So for the next part

more commands for vi editor

there are two modes for this editor

command mode  - press 'x' to delete the character under the cursor
and to cut or copy text, press 'v' and move the cursor and to select the text, then press 'y' to copy the selected text or press 'x' to cut it. Moved the cursor to the desired position and then press 'p' to paste the selected text.
insert mode  -  press 'i' to enter the insert mode at point
                       press  'o' to open a new line below the current line and enter the insert mode

Great cmd

in command mode press 'u' to undo the change of previous command
                                Press 'U' to undo the changes in the current line

I am studying about how to write shell scripts.
So when you type a cmd or script, we give arguments or parameters to them, they are saved automatically under these variables , $0 has the command, $1 stores the argument 1, and so on

and with echo cmd , the backslash(\) is treated normally by default just as any other character
but if we use "echo -e", then backslash interpretation of escapes is enabled.

$? stores the exit status of last command used. 0 means cmd executed normally.
we can print it on screen by using : echo $?
a great use of this mentioned in this article, it has a program which checks whether the user is registered user in the system or not.
this is the link to the article
http://www.cyberciti.biz/faq/shell-how-to-determine-the-exit-status-of-linux-and-unix-command/

so with my voyage to the kernel, from now.

we can send all the useless output by sending it to /dev/null, instead of default terminal
so we can : echo "who" > /dev/null
where nothing is printed on screen

the main thing to remember with if or while, if the cmd in the 'if' condition is executed , then the block of if is executed, if cmd execution failed, the block code in 'if' statement is not executed as well.
example:

if date
then
....
fi

this is executed

there should always be some kind of cmd or script in the condition statement.

if n
then
...
fi

this is not executed

Remember , it doesn't check the output status of the cmd, because the output status of any succesful cmd is 0, which is essentially false for other languages. so output status of cmd doesn't matter, only the succesful execution of cmd, even with 'expr 1 = 1', here output put status is 0, but the output is 1. so it is  executed.

the only exception is when we directly evaluate expression by using this

if [ ] : we use these boxes to evaluate expressions
example:

if [ var1 -eq var2 ] then

fi



For loop can be done, just like C

structure:

for  (( i = 0 ; i < 2 ; i++))
do
...
done

to print stuff in the same line as before , use : echo -n

Looks like the voyage is done
goodbye





So today with 'A voyage to Kernel' again, it's been two days since i had read another volume of this. So today i need to rejunevate my determination to complete all the volumes

By the way, i am also decided and determined to learn php and javascript to my project list
Oh man, just now, i already wasted by surfing and reading about some stupid article, i am really addicted to this news stuff. I should get rid of this obsession or distraction whatever it is.
Come on you can do it.

Now before learning this , i should say something about the usage of vi editor

excellent to use: shortcuts are

Esc+ i     to insert  new text
Esc + :w                     to save a file
Esc + :w filename     to save a file with name
Esc + :q!                  quit without saving
Esc + :wq                  save and quit
Esc + yy                    to copy a line where the cursor is staying
Esc + dd                    delete the line the cursor is staying
Esc + wd                   delete the word from the cursors position
Esc + /word               search a specific word
n                                 to continue with search

the main stuff of this experiment will be in the next post, goodbye for now

i am really nervous today , hence the inactivity. This anxiety is caused not by a facetious matter, but rather a very serious matter, my exam results. Still didn't know the result, hoping to know by tomorrow. Please god! let me pass in this exam. So i can continue to effectively achieve my goals.

I want to continue doing my projects as i had already mentioned, but there is huge elephant in the room waiting to crush me with its failure. But i am hoping from now till tomorrow, to ignore and continue doing my project. Just stop thinking about it, you can change what already happened, so engage in your  projects rather than wasting time browsing net or thinking about the results

By the way, i realized that most of my time in a day is wasted mostly due to facetious browsing without any educational or learning purposes.

Come on you can conquer this stupid monster. You are master of your life

Tuesday, May 28, 2013

learn a word a day

Today's word is facetious

it means treating serious issues with deliberately inappropriate humor
other meanings are amusing or humorous or lacking serious intent

example: I hope this grand project of mine is not a facetious one, since the previous projects were taken in a facetious manner
the method by manipulating the /etc/fstab table is system wide mounting, but for a user specific mount on command line, we can use the udisks cmd
first find partitions by

sudo fdisk -l
then use

/usr/bin/udisks --mount /dev/sda2 or anything
we can also use UUID
for this method , first find UUID by
ls -l /dev/disk/by-uuid/
then use this cmd

/usr/bin/udisks --mount /dev/disk/by-uuid/----
new idea, i am thinking of learning a word(good word) a day, try to use it as much as i can on that day.
It is really an exciting idea, but the problem is discipline which i completely lack, hence i hope i will follow this everyday. come on, you can do it.
Starting tomorrow
Another idea, try to solve hindu crossword , allocate an hour for this everyday, since there is power cut everyday, it is the ideal time to read or solve crossword puzzles. make use of the time as best as you can
first i had faced this problem a lot of times,since i had started using Linux Distro 4 years ago. But i had never bothered to solve it by using a permanent solution.
This is my first step towards execution

problem: mount ntfs or any partition from the start
my journey to the solution, after a long and tedious search i finally found a website, which had shown different methods to do it, rather than showing some narrow minded and simple way, it explained all the methods properly. So i chose the best solution as a core linux user should have, the manual way

for this i need to understand the use of this important command   fdisk

fdisk - used to view and manipulate the partition table
should use this command with root
so , the cmd is

sudo fdisk -l          to view the parition the table of all disks

this showed my partition table, then i got to know about this as well, what is the difference between hda and sda drives being shown here
hd means ide drives which parallel ATA
sda means serial ATA

SATA replaced PATA these days

since it is resolved, now

another important stuff for this is to know the device UUID, this has been used since if the device partition is changed then it will be known by a different name, hence to identify the device irrespective of the partition , UUID is used

Therefore, this is the cmd or path to know device UUID

ls -l /dev/disk/by-uuid/

this will show all the devices UUIDs in the partition table

now we have to learn about an important file /etc/fstab
this file contains the mount information which is used at boot time to mount the drives
an example is here


/dev/hda1   /media/windows   vfat   user,fmask=0111,dmask=0000   0   0

the first field is the drive
second is mount point
3 rd is filesystem type, mine ntfs, but to allow access to everyone use ntfs-3g
4th is options, need to explore this , but that is for another day
5th option is dump, later
6th is pass, which gives the order in which they are checked at boot time, linux partition is always 1

So this is the code i inserted in the /etc/fstab file

UUID=88E0876FE0876274 /media/windows-xp ntfs-3g user,fmask=0111,dmask=0000 0 0 

reboot
voila! the work is done



It all started when I was reading this book "Making ideas happen" by Scott belsky. As a person who has very less productivity this is my chance to understand and experiment with this book's guidelines or whatever you may call it to increase my productivity.

So here it is my first project

Complete all the volumes of "Voyage to kernel" , there are 24 volumes and i already completed 2 of them.
So here it is my third one today