How to check whether two HashSets are equal in C# .NET

Two HashSet objects in C# are equal if they contain the same values regardless of their order in the collection.

Consider the following integer sets:

HashSet<int> intHashSetOne = new HashSet<int>()
{
	1,2,6,5,7,5
};

HashSet<int> intHashSetTwo = new HashSet<int>()
{
	2,2,8,5,9,4
};

HashSet<int> intHashSetThree = new HashSet<int>()
{
	6,7,5,5,2,1
};

Read more of this post

Using webpack 2 and NPM to bundle various resources of a web application part 5: adding babel.js for ES5 transformation

Introduction

In the previous post we first briefly discussed the output that webpack generates in the bundle.js file. Simply put, webpack extracts the dependency graph from the various JS input files and organises the elements into functions that in turn are placed into an array. The functions in the array are invoked in a sequence that reflects the dependency graph. Then we also built a minimal HTML page to execute the bundle in various browsers. Our ES6 code was successfully executed in all of them except for IE11 which is obviously too old to correctly interpret the new ES6 features. We would see the same in older versions of Chrome and FF as well.

In this post we’ll explore another great feature of webpack, namely the ease at which we can add plug-ins to the bundling process. We’ll specifically add babel.js to transform ES6 code to ES5. The point here is that JS developers want to be able to use the latest and greatest of ES6 and other future versions of JavaScript without having to worry about JS support across various browsers.

Read more of this post

Structurally compare two arrays in .NET

In this post we saw how to determine if two arrays are structurally equal in .NET. Two arrays are said to be structurally equal if they contain the same elements in the same order.

Structural equality has a comparison counterpart: IStructuralComparable. It determines if an array comes before or after or is equal to another array based on the elements within it.

Read more of this post

Compressing and decompressing strings with BZip2 in .NET C#

There are times when you need to return a large text from a web service. The large text will then need to be handled by the recipient. In order to reduce the size of the message you can combine two simple techniques:

  • Compress the string value with a compression algorithm, such as BZip2
  • Base64 encode the resulting byte array

You will be able to send the base 64 encoded compressed string over the wire.

Read more of this post

Using webpack 2 and NPM to bundle various resources of a web application part 4: executing the bundle

Introduction

In the previous post we successfully configured webpack and executed it to create a bundled JS file in the build folder. We saw that the bundle.js file is larger than the two small input JS files together. That’s understandable as the generated bundle contains a lot of configuration code that webpack added on top of the file.

In this post we’ll briefly look at the generated bundle and also create a HTML page to execute bundle.js.

Read more of this post

Divide an integer into evenly distributed groups with an ES6 generator

Say you’d like to divide an integer, e.g. 20, into equal parts of 3 and distribute any remainder equally across the groups. The result of such an operation would be the following 3 integers:

7,7,6

20 can be divided into 3 equal parts of 6 and we have a remainder of 20 – 6 * 3 = 2. 2 is then added as 1 and 1 to the first two groups of 6. The result is a more or less equal distribution of the starting integer.

The following ES6 generator function will perform just that:

Read more of this post

Using ES6 generators for custom iterators

We looked at the basics of using ES6 generators in this post. Generators also come with symbol iterators which can be applied to objects. A symbol iterator helps us implement a custom iterator for our objects. We can declare how our object should behave in a for-of loop. Symbol iterators also involve some weird syntax but generators are weird anyway so a little more weirdness should be fine.

Let’s start off with a simple example:

let partyOrganisation = {
  host: 'John',
  dj: 'Jane',
  food: 'Peter',
  games: 'Mary'
}

Read more of this post

Using webpack 2 and NPM to bundle various resources of a web application part 3: configuring and executing webpack

Introduction

In the previous post we started setting up a minimal project for our webpack demo. We installed Node.js so that we can create an NPM project where NPM stands for Node Package Manager. We also installed webpack as a development dependency and discussed the difference between development and production dependencies in an NPM project. We went through the role of the package.json file and saw where the dependencies are installed on disk. Finally we added two JS files to our src folder but left them empty.

In this post we’ll first briefly discuss dependencies between JS modules. Then we’ll go ahead and configure webpack, activate it for our demo project and run it using NPM.

Read more of this post

Resolving null values in C#

Say you have a method which accepts a string parameter. The method may need to handle null values in some way. One strategy is to validate the parameter and throw an exception:

private static string Resolve(string input)
{
	if (input == null) throw new ArgumentNullException("Input");
.
.
.
}

Another strategy is to provide some default value with an if-else statement:

Read more of this post

Using webpack 2 and NPM to bundle various resources of a web application part 2: code beginnings

Introduction

In the previous post we introduced the topic of this series which is the basics of webpack. Webpack is a bundling and packaging tool whose primary goal is to bundle the various JS and CSS scripts and images into minimised files that are faster to download in a web browser. Webpack is often associated with Single Page Applications that heavily rely on JavaScript to render and re-render the same page according to the actions of the website user. To be more exact, the various popular JS frameworks like React or Vue use webpack behind the scenes to build a deployable package out of a set of components of an SPA. Normally the command line tools associated with these frameworks, like the React command line interface (CLI), already have webpack configured that fits most needs but it’s still good to understand how webpack works and what it does in isolation. Otherwise newcomers to the technology don’t even dare to touch the webpack configuration file since it seems to perform a lot of woodoo magic.

In this post we’ll set up a minimal environment and start coding.

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

ARCHIVED: Bite-size insight on Cyber Security for the not too technical.