Posts

Estimating the value of Pi using Monte Carlo Method

Image
The very first moment I was shown this, I was amazed. Estimating something using random events is pretty amazing. The first time I did this in MATLAB, but now, I think I will attempt to do the same in JavaScript.
The undelying concept of Monte Carlo Method is to use randomness to determine the value. The method is often used to solve problems that are hard to determine exactly, when there is enough statistical data available.
Let us define a square centered at the origin with side of length 2. A circle centered at the origin is inscribed in this square.


The assumption that we are using in this method is that if we randomly take a few points within the square, the ratio of the number of points that falls within the circle to the total points taken is equal to that of the area of the square and the circle. That is,
Area of square / area of circle = totalRandomSamples / totalPointsInCircle Let us write a JavaScript program that could do perform this with a huge number of random sample p…

Programming bouncing ball in JavaScript

While studying Newton's laws of motion during my schooldays, I found some of the questions related to bouncing ball quite fascinating. The sheer number of different kinds of questions that one could come up with just a ball bouncing on the ground is quite a lot.
My attempt is to create the example as simple as possible. I would not be defining additional classes; I would be using the position value which is already present in the DOM Element and adding velocity as a parameter to the DOM Element.

First, let us define the HTML and CSS to get the visual appearance of the ball and the floor right.

<html>
<style>
#ball{
    position: absolute;
    left: 50%;
    top: 0;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #005eff;
}
#floor{
    position: absolute;
    bottom: 2px;
    background: #000;
    width: 100%;
    height: 20px;
}
</style>
<body>
    <div id="ball"></div>
    <div id="floor">&l…

Nine year anniversary for BuddyGo

Image
It has been nine years since I bought the domain buddygo.net. Prior to buying a .net domain, I used to use a .tk domain as it was free. As I started this project during my childhood, it was hard for me to convince others to pay for this, but eventually, I saved up some money and did it. For a few years, I paid for the domain just for the sake of keeping the ownership.



As I have mentioned in one of the previous blog posts, BuddyGo started of as a social network. Later, I started a few blogs in different subdomains which turned out to have pretty high traffic. In the subsequent years, I had to take the project down for many reasons, the main one being my academics.

Bringing it back up as a blog, I believe, is a good decision that I made and I think I will keep on writing more posts.

Cheers!

Slideshow on Google Images

Image
I opened Google Images and searched for Batman, which is probably my favourite Super Hero. I had connected my laptop to a TV screen and I wanted to see all the images as a slideshow. And, just like many other posts in this blog, I started using the Chrome Developer Tools.
I clicked on the first image. The image was being displayed on the side and a button to move to the next image came in. I right-clicked on the button and did an Inspect and I found that the button was having classes KJaJCe irc-rab. I ran the following command to see if there are other elements with the same class.

document.getElementsByClassName('KJaJCe irc-rab')

I saw that there were three elements, but the button to go to the next image was always having an index of 1. So, I went ahead and did the following:

a = document.getElementsByClassName('KJaJCe irc-rab')[1];
a.click();
Each time I ran a.click it showed me the next pic on the right-hand side and I was convinced that if I keep this in a setInt…

Creating a Neural Network to Predict Periodic Data

Image
Two years ago, Arijit Mondal,  a professor of mine who was teaching us a course on Deep Learning, asked a question on how to make a Neural Network that can predict periodic data. The students started shouting out their own version of answers, most of them involved the usage of some form of recurrent neural network structure. I had a different answer.
I was not a very good student during my initial semesters during my bachelors. I missed several classes due to the lack of motivation which were supplemented by the change in environmental condition that I had been used to growing up. But, I could recollect some of the things that were discussed in a Math course, which was regarding fourier series. Just by using a bunch of sine waves, the series was able to approximate many functions to an excellent accuracy. How is this any different from the Universal Approximation Theorem that was tought during the initial lectures of this course?

It striked me - the easiest way neural network can lea…

Transferring Files between Computers and Phones using Wi-Fi

Image
Phones are essentially miniaturized computers. If you connect your phone to a monitor, keyboard and mouse, it essentially becomes a computer. In this article, let us discuss about how to use an Android phone or a computer as a server and transfer the data into another phone or computer.

Doing this procedure on an Android device, you just need to install the app named Termux, which provides you with a Linux Terminal on Android.

If you don't have python installed already, install it using apt-get or apt using the respective commands listed below on your Linux Terminal or Termux. Note that admin privileges may be required to do so.
apt install python
apt-get install python After you are done installing, before you create the server, you need to know what your IP address is so that other devices can access it. To obtain the IP address, simply type in the following command:
ifconfig 

In this case, the highlighted portion in the image above is the IP Address, 192.168.43.182. Now let us…

Extracting Stock Price Data Trend from Google Search to Train LSTM Network

Image
I am not very good with designing my own neural networks. I have attempted to create a few in the past, some worked out fine for proving certain points that I wanted to make, but whenever I tried to make something to participate in a competition, things were not very well. In this post, I do not intent on creating an LSTM based neural network to predict stock prices, rather simply use Google as a tool to extract the stock trends from the graphs.

To get started, search for "Amazon stock price" on google. You would be able to see a pretty nice graph. On right clicking on the graph and clicking on Inspect and reading through Elements in the Developer tools, it can be observed that the graph is rendered using Scalable Vector Graphics or SVG. This is an XML-based vector image format and the data required to create such a graphic would be available in a format that we'll be able to read. I also observed that the required SVG image has a class name uch-psvg and there is only o…

Sending a Facebook Message Challenge: Harder than it looks

I have been having conversations with a friend regarding how easy it is to use JavaScript to automate a lot of processes that we usually do, why it is easier to program in an interpreted language than compiled language, etc. Pondering about these conversations, I challenged myself to send a message to my girlfriend on Facebook Messenger using JavaScript console alone.

Before I started, these are the ground rules that I set:

I can use both keyboard and mouse, but the usage should be restricted to the JavaScript console alone.No other tab in the developer tools other than JavaScript console shall be used.I shall start with about:blank as the start page.

The first step is to open Messenger. That step was pretty easy considering the fact that I already knew how to use the window object to my advantage. I used the following command to open Messenger.

window.location.href = "http://www.messenger.com";
Luckily, I had already logged into Facebook and the cookies were not cleared. So…

Creating awesome text banners in Linux Terminal

Image
In several opensource projects that we see around in the web, certain developers prefer to add banners like the following at the top of the source code. These do look cool, but I have often wondered why anyone would waste so much time making things like these.

As I have been surfing around the web, I happened to see Linux Terminal apps that generates these for you. I have used them to generate such banners for the BuddyGo.

Figlet: To install Figlet, use the following command (if you have apt-get): sudo apt-get install figlet
Toilet To install Toilet, type the following in your linux command line: sudo apt-get install toilet
Banner: To install Banner, type the following in your linux command line:
sudo apt-get install sysvbanner

Now, you can also contribute to the Open Source community in style. Make contributions on GitHub, BitBucket, or whichever platform you are using.

How to Create your own Ad Blocker Chrome Extension

Image
Not very long ago, I read an article stating that Google banned advertisement blockers from its stores. There are several websites which does not let you in if you have an Ad blocker extension installed on your browser. I have not investigated on how these websites detect that, nor do I know whether our own version of advertisement blocker would be immune to that. But, isn't it fun to build something like this on our own?

As the first step, I found a random website that has a Google Ad. I right clicked on the Google Ad and clicked on Inspect button.


As I moved up the Elements inspector, I found that the id of the advertisement starts with "google_ads_". Therefore, I opened the console and typed in the following command:
div = document.querySelector('[id^="google_ads_"]') This selected the div that contained the advertisement. I went ahead and typed in the following command that would remove the div from the page.

div.parentElement.removeChild(div)


In a…