Skip to main content

Posts

MQTT server up and running in 7 simple steps

In this post I won't be talking about what MQTT server is why is and all, may be I'll write a different post for that. This post focuses on installing MQTT broker and getting it to work in 7 simple steps. Step 1: sudo apt-get update Step 2: sudo apt-get install mosquitto Step 3: sudo apt-get install python-pip Step 4: Install mosquitto module for python > sudo python-pip install mosquitto Step 5: Install mosquitto client > sudo apt-get install mosquitto-clients After executing above command you can start publisher and subscribe modules. These publisher subscriber can use a topic and write/read data from it respectively.   Step 6: Start subscriber client => mosquitto_sub -h <hostname> -t <topicname> -v > mosquitto_sub -h localhost -t testTopic -v Step 7: Start publisher client => mosquitto_pub -h <hostname> -t <topicname> -m "<message>" > mosquitto_pub -h localhost -t testTopic -m "Test Messages" P
Recent posts

What is the difference between Node.js and AJAX?

Node.js - Node.js is an Asynchronous single threaded server. - Node.js runs on V8  environment. - Can not access DOM objects in Node.js. AJAX stands for A synchronous J avascript A nd X ML. - It is a client side technology usually used for updating part of the page on the client side dynamically i.e. without reloading the whole page hence, these type of pages are also called as dynamic pages. - Also, it saves sending lot of data from client to server and vice-versa.

Pangram : Problem on hackerrank

This is a problem mentioned on Hackerrank. Below is my attempt to solve this problem. Problem Statement Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly because it is a pangram. ( pangrams are sentences constructed by using every letter of the alphabet at least once. ) After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams. Given a sentence s , tell Roy if it is a pangram or not. import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         char[] str = in.nextLine().toCharArray();         boolean[] resultArr = new boolean[26]; int smallMax = 'z'; int capMax = 'Z'; for (int i = 0; i < s

Insertion Sort

  Insertion sort is like picking a card from a set of unsorted cards and comparing it   to all the cards present on the left for higher or smaller values and inserting this   card into right position. After every pass, the picked value reaches at its right position.     for e.g.   input : 10,5,3,4,12,1,13   after First Pass :   -> 5,10,3,4,12,1,13   after Second Pass:   -> 3,5,10,4,12,1,13   after Third Pass:   -> 3,4,5,10,12,1,13   in fourth pass when the pointer is pointing to 12 there is not need to move it since   it is already greater than the immediate next element i.e. 10:   -> 3,4,5,10,12,1,13   after fifth Pass:   -> 1,3,4,5,10,12,13   in sixth pass also there is no need to move the elements   and you get your output     It's time complexity is O(n^2) but still it performance much faster than bubble sort and   slightly better than selection sort.     Below is the code for same. public class InsertionSort { public static vo

Binary Search

You have a big list of numbers and you want to search an element from it, how to do it? Simplest approach would be to compare this number with all the elements from the list. In this case, if the element is the last element then we have to go through all the elements till we reach the element we want and what if it doesn't exist. There are many searching algorithms to get it done efficiently, one of them is Binary Search. In binary search : Step 1. Sort the list of elements in ascending order Step 2. Check the value of element that needs to be search (lets call this 'x') with the middle element (midElement) in the list. Step 3. If the value of x is greater than midElement then the value is present in the right half of the array or else it is present in the left half of the array. Step 4. Depending on the right or left half of the array, x will be compared. Lets assume it is present in left half, then the leftMidElement is compared with x and then Step 3 is repeated until w

Hashing

Consider a use case of Electronic health record where you have a unique key for every record and you have some data associated with it like persons name, address etc. then how can you handle this data. Some ways to store this information would be to use array, linked list, trees or may be direct access table. But all these also have some problems as below : In case of array and linked list if you want to search for a record you have to search linearly. We can keeps them sorted so we can apply some searching algorithm and can get faster search results but this will create another problem of inserting  and deleting. In this case every time you insert/delete a record you must also check for the order of the array/linked list. If we consider a balanced tree then we can get the results for search/insert/delete in moderate amount of time. O(Logn) time. Out of all these, Direct Access Table shows some promising results. Direct Access Table is nothing but a huge array where the index of

Everything you need to know about ShellShock.

Shellshock was a security threat that was identified by Stéphane Chazelas on 12 September 2014 and was disclosed and announced to the public on 24 th September 2014 with the fix ready for distribution. It was assigned the identifier as CVE-2014-6271 . By the way, this is another security bug with cool logo after Heartbleed. 1. What is Shellshock? Shellshock is a name given to a vulnerability in Bash which allows an attacker to execute remote commands on vulnerable system. Bash is a command-line interpreter available on most of the operating systems like Apple’s OSx, windows and present on many versions of Linux. Bash also acts as a parser for the functions given to it.  2. Why is it harmful? Shellshock is significantly harmful for the servers connected to internet. Since, it lets attacker to escalate their privileges and potentially they can gain access to root. This gives access to the attacker as if they are the actual user and they can perform any ope