Skip to main content

Posts

Periodically run a method without freezing UI.

 This was one of the requirements to periodically check if the internet connection for a system is on / off. Based on the Internet Connectivity Status, it will do certain actions. How do I check the Internet Connection Status periodically and asynchronously?  To solve this programming puzzle (in C#.NET ), I have used System.Timers.Timer class. There was one more class available in the .NET framework, that was, System.Threading.Timer. I have chosen System.Timers.Timer class, because it is thread-safe but System.Threading.Timer class isn't out of the box. Step 1: Created an elapsed event handler for the timer class: <Code> // Create a timer with 10 seconds interval in the init method of the form application; m_Timer = new System.Timers.Timer(10 * 1000); /* It's going to fire the below-highlighted method every 10 seconds*/ m_Timer.Elapsed += checkInternetConnectionState ;  m_Timer.Enabled = true; </Code> Step 2: Created  checkInternetConnectionState  async method defin

A concept to a product (Kimidori [ 黄緑]) - Part 3

 The previous pos t explored the report part of the malicious link(s) with as many details as possible. So far the tool can be used any number of times to figure out whether a link is malicious or safe to use. Kimidori [ 黄緑] is not limited to only malicious link detection. This tool can be leveraged to detect the browsers installed on the system along with their executable as well as cookie path. So, far it can detect the following browsers if present / installed in the system.  1. Brave 2. Chrome 3. Edge 4. Firefox 5. Ice Dragon 6. Opera 7. SeaMonkey 8. Vivaldi 9. and WaterFox Support for other browsers will be given eventually.  Here is a glimpse of the page where it shows the browser details fetched by the tool: More browser support will be added soon along with cookie analysis for the user to let the user know what kind of cookies gets created by surfing the internet web pages by different browsers. This part will revisit soon. Along with browser-related stuff, this tool also digs

Variadic template function - Part 1

 In C, we know we have something called printf() function. This printf() function can take any number of arguments of any built-in type (not user-defined type). As an example, the following piece of code is valid for the standard built-in printf() function. <Code> const char* msg = "%s can accept %i parameters (or %s)."; printf(msg, std::string("Variadic templates"), 100, "more"); </Code> The problem in this code is, it will not print the string part, but it gets compiled with the MSVC as well as GCC 8.2 compiler. However, if I change the code like below, now it prints everything properly. <Code> const char* msg = "%s can accept %i parameters (or %s)."; printf(msg, std::string("Variadic templates").c_str() , 100, "more"); </Code> The printf is like a variadic template function but it sticks to only built-in types. Now the question comes how can I write variadic template functions in C++. In C++ 11 the

Bucket Sort using Insertion Sort

 A simple implementation of Bucket Sort, using insertion sort to sort bucket elements.  #include <iostream> #include <cassert> #include <algorithm> #include <vector> template<class FwdIt, class compare = std::less<>> void insertionSort(FwdIt begin, FwdIt end, compare cmp = compare{}) {     for (auto it = begin; it != end; ++it)     {         auto const insertion = std::upper_bound(begin, it, *it, cmp);         std::rotate(insertion, it, std::next(it));         assert(std::is_sorted(begin, std::next(it), cmp));     } } void bucketSort(float arr[], int N) {     std::vector<std::vector<float>> arrBucket(N); // Created N empty buckets     /* Segregating array elements in different buckets*/     for (int i = 0; i < N; ++i)     {         int bucketIndx = N * arr[i];         arrBucket[bucketIndx].push_back(arr[i]);     }     for (int i = 0; i < N; ++i)         insertionSort(arrBucket[i].begin(), arrBucket[i].end()); // Sorting elements in

A concept to a product (Kimidori [ 黄緑]) - Part 2

In the previous part , we have seen KIMIDORI [ 黄緑] detect if a URL is malicious. In this part, we will see the details that KIMIDORI [ 黄緑] fetches out of the URL provided. As an example, provided a safe URL, https://www.azuresys.com/, and let's see what it brings out: As we can see, the link is safe and the link is active, which means we can just click on the link to open it on IE.  Now it's time to look into the URL report (still under development):  We have URLs IP, Location, and HTTP Status code. The Report part is a sliding window, the Show Report button shows as well as hides the report. Show / Hide Report is a toggle button. Let's see if we get the same details for any bad (phishing / malicious) URL: Took an URL example from a phishing link and tested it. The tool detected it as not a good link (Screen Shot Below) & link does not activate unlike a safe URL: Now let's see the report part for more details including domain registration details: It looks like it&

A concept to a product (Kimidori [ 黄緑]) - Part 1

It has been 3.5+ years since I have taken a career break due to aging parents. Soon after my career break Dad passed away and Mom was detected with third-stage of throat cancer. I became a full-time caretaker of my mom. During the peak phase of COVID-19, I was daily visiting the hospital for her chemo and radiotherapy. The hospital wasn't willing to admit the patient due to COVID-19 fear. However, I continued my service in the hope that one day she will recover but after almost two years of battle I lost her. Life is seemingly strange to me. I was under the illusion that I can cure my mom. But divinity had a different plan. Her demise put me on a different level of thought process. I felt strongly nothing is really permanent in this material world. My mom told me that just before her demise, she possibly realized that her time is short and asked me to let her go as she was not able to take any more pain. She told me that 'sometimes losing somewhere, marks the beginning of winni

The Facade pattern

Facade design pattern is a structural design pattern and it's used widely. The aim of this design pattern is to provide a simple interface to the client for a complex underlying system. So, facade means face of the building. This design pattern hides all complexities of the system and just displays a simple face. Very common example could be URL interface of a browser, which hides all complexities behind and only accepts a URL which user intends to browse. Another common example could be withdrawal / deposit of money from banking system via ATM. To withdraw money we need following steps to achieve successfully: 1. Validate card / account number 2. Validate pin 3. In case of withdrawal check account balance and allow / disallow withdrawal 4. Follow steps 1 & 2 for account deposit (Steps 3 not needed). 5. Finally show the balance. Code Example:  <Code> File: WelcomeBank.h #pragma once #include < fmt/format.h > class WelcomeBank{     public :         // ctor...