Tuesday, 22 September 2020

C# LINQ - Partitioning the List Collection Into Chunks

















Partitioning is the key part while working with the large collections in programming. LINQ helps in dividing the huge collection into chunks. 

Below code snippet takes the list and the chunk size and yields the chunks from the collection.

public static IEnumerable<List<T>> Partition<T>(List<T> source, Int32 size)
{
    for (int i = 0; i < Math.Ceiling(source.Count / (Double)size); i++)
        yield return new List<T>(source.Skip(size * i).Take(size));
}

Test Results:





JavaScript - window.location.origin is not working in Internet Explorer


window.location.origin does not work on Internet Explorer. 

Follow the below code which will set the window.location.origin value by concatenating the portions of the URL. 

 if (!window.location.origin)
    window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : ''); 
}

window.location properties

window.location.protocol         - Return the protocol of the current URL
window.location.hostname      - Returns the domain name of the web host
window.location.port                  - Number of the internet host port (of the current page)

Saturday, 29 August 2020

JavaScript - How to Download All Pictures from Instagram Profile on Single Click


1. Open Instagram profile you want to download images from in Chrome browser.

2. Open Chrome Console (Press F12).

3. Enter the below script in console window then all appearing images in the Instagram profile current screen will be opened into a new tab.


document.querySelectorAll("div.v1Nh3.kIKUG._bz0w a").forEach(function (item) { window.open(item.querySelector("img")["src"]) });