Flat Preloader Icon

It's Study Time

Categories
Computer

How to recover WiFi password using command line

Open command prompt

Type netsh and enter

Type wlan show profile and enter. This is to list all the WiFi the system had connected to.

Lets say we want to reveal the password of Iron Bridge,

We run following command wlan show profile “Iron Bridge” key=”clear”

and Voila!! The password is now revealed.

Categories
JavaScript

Angle between Hour and Minute hands in a clock: JavaScript

This is a very frequently asked question in interviews to write a program for following problem.

The question goes something like this: Write a program to find out the angle between the hour hand and minute hand at a given time when two inputs, Hour and Minute are given.

Lets try to understand the problem first before diving into writing the solution.

We know that a complete rotation on the clock is 360 degrees. So for every hour the hour hand will move by 360/12 degreess

Similarly for every 60 minutes the minute hand will move 360 degree. So, for every minute it will move 360/60 degrees.

This looks very simiple till now but when the minute hand moves the hour hand moves too. So for every minute the hour hand moves a little too by 360/12 ÷ 60 .

As we have all the details lets create the program in our favorite language JavaScript.

const claculateClockHandAngle = (hour, minute) => {
    const MINUTE_HAND_ANGLE_PER_MINUTE = 6, //360/60
        HOUR_HAND_ANGLE_PER_HOUR = 30, //360/12
        HOUR_HAND_ANGLE_PER_MINUTE = 0.5; //30/60

    const calculatedMinuteHandAngle = minute * MINUTE_HAND_ANGLE_PER_MINUTE;
    const claculatedHourHandAngle = hour * HOUR_HAND_ANGLE_PER_HOUR + minute * HOUR_HAND_ANGLE_PER_MINUTE;

    const angleBetweenHands = Math.abs(claculatedHourHandAngle - calculatedMinuteHandAngle);
    
    //return only acute angle
    return Math.min(360-angleBetweenHands, angleBetweenHands);
};
Categories
Uncategorized

Fizz Buzz program in JavaScript

Fizz Buzz is one of the simplest but frequestly asked program in all laguage interviews.

The question goes like below.
-Write a program that prints the numbers from 1 to n. While printing the number if the number is divisible by 3 print ‘Fizz’ and when the number is divisible by 5 print ‘Buzz’. When the number is divisible by both 3 & 5 it should print FizzBuzz.

Lets write the program in JavaScript

//The simplest form which is self explanatory
for (let i = 1; i <= 20; i++) {
    if (i % 15 == 0) {
        console.log('FizzBuzz');
    } else if (i % 3 == 0) {
        console.log('Fizz');
    } else if (i % 5 == 0) {
        console.log('Buzz');
    } else {
        console.log(i);
    }
}
//Lets make it little shorter. Now the program is like below

for (let i = 0; i < 100; ) {
    let isFizz = ++i % 3 ? '' : 'Fizz';
    let isBuzz = i % 5 ? '' : 'buzz';

    console.log(isFizz + isBuzz || i);
}

This can be written in shorter form like below

for (let i = 0; i < 100; ) { console.log((++i % 3 ? '' : 'Fizz')+ 
(i % 5 ? '' : 'buzz') || i); }
Categories
Uncategorized

Hoisting in JavaScript

Hoisting in JavaScript is the process in which the interpreter moves the declaration of variables, functions or classes to the top of their scope, before the execution of the code.

Hoisting of function is a very useful way to call it even its written after the code like below.

//Hoisted function call
console.log(hoistedMethodCall());

function hoistedMethodCall (){
    console.log("Hoisted method is called even before its declared");
}
//Hoisted variable usage

    console.log(hoistedVariable);

    var hoistedVariable;

    hoistedVariable= 10;

    console.log(hoistedVariable);

//Output
undefined
10
 console.log(undefinedVariable);

//Output

Uncaught ReferenceError: undefinedVariable is not defined
Categories
JavaScript Uncategorized

Currying in JavaScript

Currying converts a multi argument function to sequence of function calls with single arguments. Like below

//In normal function syntax

const multiply = function (a, b){
    return a * b;
};
const output = multiply(2, 3);
console.log(output);

//In Arrow function syntax

const multiply = (a, b) => a * b;

const output = multiply(2, 3);
console.log(output);

To

//In normal function syntax

cont multiply = function (a) {
    return function (b) {
        return a * b;
    };
};

const output = multiply(2)(3);
console.log(output);
// 6
//In Arrow function syntax

const multiply = a => b => a * b;

const output = multiply(2)(3);
console.log(output);
// 6

To the naked eye currying looks like converting a very simple function like in the first function to a little complex function unnecessarily. But there are usecases which will make this very useful.

Lets dive in. Lets say, I have a function requirement with three arguments. And the first argument remains same for few calls. In that case, I will have to pass the same argument again and again for each call. Currying can be a great way to avoid that.

Lets take the example of logging a series of messages into console with time after an even is fired. Obviously I would like to log the same time for all the logging in the series.

Lets code that

const logData = time => id => message => {
    console.log(`Time is ${time} and data is ${id} and ${message}`);
};

const logDataWithTime = logData(new Date());

logDataWithTime(1234)('Dummy Message 1');
logDataWithTime(1235)('Dummy Message 2');
logDataWithTime(1236)('Dummy Message 3');

/*
Time is Wed Jan 05 2022 06:25:49 GMT+0530 (India Standard Time) and data is 1234 and Dummy Message 1
Time is Wed Jan 05 2022 06:25:49 GMT+0530 (India Standard Time) and data is 1235 and Dummy Message 2
Time is Wed Jan 05 2022 06:25:49 GMT+0530 (India Standard Time) and data is 1236 and Dummy Message 3 
*/

As you can see in the above example we do not have to pass the date/time to the function again and again for each call.

How does this work?

Its simple to understand if you take one function at a time. If you look into the first function it creates a lexical scope for the variable a and returns another function like below. As the returned function has access to variable a, it will be like below to understand.

return function (b) {
        return 2 * b;
    };
//2 inplace of a that was passed in the first function

There many applications of currying in JavaScript like in events, logging etc.

Categories
Computer

C# – Learning a new Language

Why for me, although I have a UI background?

I work for a company called Toluna. The company has a vision that everyone should be excellent in everything so that in the time of crisis in Production, anyone available could jump in and start addressing the issue. Sounds good, right? Believe me the idea of the managemnt is definitely not to make every developer “Jack of all trades master of none“.

It can be a good idea, if executed properly and the developers are given enough time and support to get into new technologies initially. At least I believe that.

I am a UI developer having years of experince in various UI technologies. I always prefer to learn a technologies which aids my existing experience and help me to achieve new heights on that. I love to work any UI technologies and related backend technologies like NodeJs. Would love to work on ReactNative if my project/company needs a mobile developer. I am confident I can be in the level of a very good productive developer in no time.

C# is a different challenge for me for below reason

  • Its not related to UI
  • Its a language like Java where you need to know everything before you can be considered a good developer. In short not a scripting language
  • I had very little interest in the past to learn this.

But

Now my employer needs this and as I get my bread and butter from them, heck yes. Lets learn it.

Next many blog posts will be dedicated to C#. I will write down everything that I learn in next few days/weeks.

×

WhatsApp Chat

×