The snippets below illustrate Parallel LINQ in C# by crawling a web page in parallel. The Crawler class is responsible for crawling a web page (only one level deep) and returning a list of documents. The Document class represents an HTML document.
Category Archives: C#
The snippets below illustrate GZip compression and decompression using the GZipStream classes.
As a quick alternative to the Html Agility Pack, HTML can be parsed into a DOM tree using the built-in XmlDocument class. The following snippets illustrate HTML parsing in C#.
These snippets illustrate the natural sorting order. Suppose you’re using numbers within your file names. For example: file1.png file2.png … file10.png file11.png file12.png You’d expect to see them in the above order. However, they are (by default) sorted as follows. file1.png file10.png file11.png file12.png file2.png …
Also extended C# LINQ and Extension method (simple) to include the last (MAX) Date Created property, added a new Folder class (model) with properties and included them in a List. Also, amended the LINQ statement to get the MAX(Date Created) .
This snippet pulls down an image from a URL into a byte. From there you can re-size or save. Don’t forget the necessary try – catch.
Prime numbers have many applications. For example, in cryptography. The RSA algorithm for public-key cryptography uses large prime numbers for generating keys. Quote: The RSA algorithm works as follows: take two large primes, p and q, and compute their product n = pq; n is called the modulus. Choose a number, e, less than n [...]
Downloads contents as a byte array or string, depending on need.
Microsoft has released the Roslyn CTP which allows developers to use the Visual Basic and C# compilers as APIs. The snippet below can be used to execute C# code at runtime.
Huffman coding is an encoding algorithm used for data compression. So called Huffman trees are used for encoding and decoding of data. The leaves of these trees contain the symbols and their frequencies. Each parent node contains the sum of the frequencies of its children.