Tuesday, December 20, 2016

Some life principles for a Happy Life

This blog post is just to inspire people about life and saying goodbye to worries.

We all have aims and goals in our lives. There is a necessity for them. For example, I cannot live a life with no goals and watch tv series, sleep 10 hours a day. Though this looks fine for a day, 3 days, a week, enough! But this makes me carry unnecessary burden on my mind. Also due to lack of social circle, many people fall under depression and live life in despair.

In today's life, we worry way too much. But in reality that worry is not the worth. Constantly worrying causes depression, irritation, frustration, and bad mental health. I have adapted to the following 3 steps to stay away from these:

Step 1: Think about the worst possible outcome of the present situation.
Step 2: Accept it.
Step 3: See the possible actions you can do to make the outcomes less unfavorable.

On one side there is Napolean Bonaparte who had fame, power and money but couldn't recollect even six happy days of his life. On the other hand we have Hellen Keller, who was dumb and deaf but described life as the most beautiful thing.

We must keep ourselves engaged in some activities. Keep yourself busy. Just make sure that they are productive, require focus and enhance your creativity. For people who aren't that fond of reading(Look who's talking), they must give it a shot! Its worth it. Their have been 1000s of generations that have passed and have left their experiences. Its very good to read about random stuff daily.

This was what I learnt from my mother this December. She was noticing my behavior and finally made me realized where I was going wrong. I will definitely try to live by this and make my life much much stress-free.  Following is the video she whatsapped me.

                                      
Pro Tip: We must remember the people who are close to us and make us happy. I feel thankful to my parents and close ones for being my moral support and feel blessed to have a perfectly complete life. :) No matter in how much trouble I am, there are people who will stand besides me. Trust is the most beautiful thing after love. Give it to people and never break it.

Thursday, December 15, 2016

Removing "Hover to Expand Ads" using JavaScript


I am sure most of us have seen this irritating "Hover To Expan Ads". They were even displayed on ideone some time ago. I spent a few minutes to get over with this irritating stuff. Just paste the below code in the URL. Note that as you paste the link, "javascript:" gets removed. So type it again in the beginning and press enter.



You can save the pain to copy paste this again and again simply by creating a bookmarklet with above code. Then all you need to do is click on the bookmarklet. Bookmarklets are nothing but the JS code that runs when you click on it. See this to add a bookmarklet.

Binary Heaps in C++

Pre-Requisites: What are binary heaps?
See here.

I personally found the implementation given in the above GeeksForGeeks link very long.
The aim of this post is simply to provide a short and efficient implementation of min and max heap in C++.
This helps me to revise just before the placement interviews too. :P

Advantage:
1. Short and efficient code.
2. Works as both max-heap as well as min-heap.

Here is the link of code at ideone.

#include using namespace std; class heap{ vector a; int order; #define l(x) 2*x+1 #define r(x) 2*x+2 #define p(x) (x-1)/2 #define null -INT_MAX public: heap(int x = 0){ order = x; } bool cmp(int x, int y){ if (order == 0) return x>y; //min-heap if (order == 1) return x=n and R>=n) return; int v = (L a{13, 1, 10, 34, 42, -10}; for(int x: a) H.add(x); for(int x: a) cout << H.extract() << " "; return 0; }

Friday, December 9, 2016

Solving Linear Congruences $a*x \equiv b\ (\textrm{mod}\ n)$


Note:   $(x,y)$ means $gcd(x, y)$
Given: $a,b,n$ and $(a,n)=1$
To find: $x$ such that $a*x \equiv b\ (\textrm{mod}\ n)$

This video explains how to solve this problem using extended gcd method.

Solution:
$\because (a, n) = 1$
$\therefore$ $1=M*a+N*n$ for some integers $M, N$.
Taking modulo $n$ on both sides,
$a*M\equiv 1\ (\textrm{mod}\ n)$
Simply multiply by $b$ on both sides,

$a*M*b\equiv b\ (\textrm{mod}\ n)$
$\therefore x=M*b$

Now problem is how to find $M,N$. We can use the Extended GCD Method as explained in the link. Following is the C++ implementation for the same.

Problem to practisePrime Connection
Solution? Click here

Art of Time Management | Achieving Multiple Things in Life

rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain micr...