Cron Job

A very interesting service that the linux provide to run our command at regular interval.
it is very easy to use.
Note:- “/usr/bin:/bin” this is the default path use by crontab. any command outside this directory will not be run. for that you have to provide the direct link of your command to run

basic syntax
* * * * *  <command>

you can see the 5 star above which represent the schedule to run you command.

the first * represent minute (0-59)

sec * represent hour(0-23)

third * represent day of month(1-31)

forth * represent month(1-12)

fifth * represent day of the week(0-6)

<—————>

For simple demo
to open your crontab type

env EDITOR=nano crontab -e 

this open your crontab in nano editor. here you can have number of cron job. all the command must be in separate line.

Example 1

6 * * * *  /Applications/XAMPP/xamppfiles/bin/php  ~/Desktop/phpFile/example.php

this will run the example.php file located at Desktop/phpFile folder in every 06 minute of any hour.i.e 1:06,2:06

curl: (60) SSL certificate problem: unable to get local issuer certificate

If you ever get this types of error while downloading anyfile using curl then,

just go to this link http://curl.haxx.se/ca/cacert.pem  and download this file to you home directory

then write this command to your terminal or shell
export CURL_CA_BUNDLE=”/home/cacert.pem”

what is hoisting in Javascript?

Let’s take a simple example
suppose,

var a = 1

function test(){

if(!a){ var a = 2}

console.log(a)

}

test() // now call test function what do you think

/* let me guess you are thinking that output will be 1

but i’m afraid that not true

it will output 2

Why ?

*/

 

…….

at the runtime this same code will look like this

var a;

a = 1

function test(){

var a // re write the outer scope a variable. ie undefined

if(!a){a = 2} // if(!undefined) this condition gets true

so console.log(a) output 2

 

 

Javascript Callback with an example

function cal(cb){
/* you can write any operation that takes time here then send the result to callback as given bellow */

console.log(“After exact 1sec you will get hi message”)

setTimeout(function(){

cb(“hi”)
}, 1000)

}
}

cal(function(result){
console.log(result)
})

String to object conversion

if you want to convert this type of string format such as

“(51.60693037835707, -99.25735473632812),(45.816357959181346, -93.19290161132812),(45.13846137581871, -121.93313598632812),(51.60693037835707, -99.25735473632812),…..”

to

{

1:{“lat”:51.60693037835707,”lan”:99.25735473632812},

2:{“lat”:45.816357959181346,”lan”:93.19290161132812},

3:{“lat”:45.13846137581871,”lan”:121.93313598632812},

.

.

.

}

then here is the simple code

var string=”(51.60693037835707, -99.25735473632812),(45.816357959181346, -93.19290161132812),(45.13846137581871, -121.93313598632812),(51.60693037835707, -99.25735473632812).”

 

var array=string.split(“,”);
var coordinates_array=[];
array.forEach(function(value,key){
var obj={};
if(key & 1){
var first=array[key].replace(‘)’,”);
coordinates_array.push(first)
}else{

var sec=array[key].replace(‘(‘,”);
coordinates_array.push(sec)

}
})
// console.log(coordinates_array);changing the string to array excluding ‘(‘ &  ‘)’
var i=-1;
var obj={};
var result={};
coordinates_array.forEach(function(value,key){
if(key %2 ==0){
i++;
result[i.toString()]={};
delete obj;
}
if(key & 1){
result[i.toString()][“lan”]=value
}else{
result[i.toString()][“lat”]=value

}

})

console.log(result)// desire result

To show on which git branch you are working currently

function parse_git_branch () {
git branch 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/ (\1)/’
}

RED=”\[33[0;31m\]”
YELLOW=”\[33[0;33m\]”
GREEN=”\[33[0;32m\]”
NO_COLOR=”\[33[0m\]”

PS1=”\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ ”

 

 

if you are Mac user paste the above code in .profile file of the current user of your system home directory

if you are Linux user the paste it in the .bashrc file of the current user of your system home directory

simple way to determine weather the given number is odd or even using & operator

& operator is very useful to determine whether the given number is odd or even in any programming language.it is called bitwise operator which operate using the bit of the number. i.e

1=001

2=010

3=011

it is in 3 bit representation.so our concern is whenever we do anding with & operator we get 0 or 1 depending upon nature of the number.if it is even we get 0 otherwise 1.

eg

var a=5;

if(a & 1){

//(“it produces 1”)

console.log(“this statement is true”)

}

now

a=4;

if(a &1){

// it produces zero

so if condition if false

}

Give me one reason why you shouldn’t code?

I think everyone can code.Man itself a learning machine.he/she brain can capture, manipulate and analyse any kind of information that can be perceive by his/her sense organs.then why can’t he/she code?

I like to say coding is one of the measure to check the ability of the person whether or not he/she can solve a give problem in given amount of time.

coding is a long work.it makes our mind sharp, increase our problem solving skill and teaches us iterative procedure to solve any kind of problem.

i feel really sorry for those person who say i can’t.i like to advice those people plz don’t say no to any work.i think as we are being gifted with such powerful tool(brain), we must use it to create S.t beautiful,useful to the mankind.don’t let your life just being past away.leave behind some mark that identify your existence.