Skip to main content

Posts

Showing posts from May, 2023

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