Introduction to CouchDB with .NET part 22: security continued

Introduction

In the previous post we started discussing the security features of CouchDB. An interesting feature of CouchDB is that by default, in the absence of any registered user, everyone is anonymous and all users have full access to all the parts of the Couch DB server: databases, documents, configuration, replication, everything. This is probably so that newcomers to CouchDB don’t need to spend time on security settings before getting started on its features. So the first step is to create a server administrator who then can create new users to prevent anonymous access to the server. We then created two new users, Peter and Mary, and they were promoted to database administrators to a selected database. They can now administer the database that they were assigned to. They still face various restrictions. E.g. they still cannot perform server admin tasks and they cannot delete the database they are administering.

In this post we’ll continue our discussion of this topic and concentrate on database level read and write access.

Read more of this post

Units of measure in F#

A very interesting feature of F# – besides many others – is that we can assign a unit of measure to a variable value. These units of measure are located in the Microsoft.FSharp.Data.UnitSystems.SI.UnitNames namespace. As the namespace suggests the units are taken from the international system of units.

They are surrounded with angled brackets in code. Here’s an example:

Read more of this post

Code comments in F#

F# uses the double-slash for single line comments like in many other popular programming languages:

//this is a single line comment

You might expect that /* … */ would work for multi-line comments but there’s a slight variation to that:

Read more of this post

Introduction to CouchDB with .NET part 21: starting with security

Introduction

In the previous post we looked at Mango operators related to arrays. With array operators such as $elemMatch, $in or $size we can write search terms related to elements in an array. Examples include searching for documents where an array field, such as “grades” includes at least one “A” or includes exactly two grades, not more or less. We’ve also seen how to dig deep into the object structure to query on elements that lie deep in the object graph, such as the price of a product of an order of a customer.

In this post we leave querying behind and start looking into some security aspects of CouchDB.

Read more of this post

Calculate standard deviation of integers with C# .NET

Here comes a simple extension method to calculate the standard deviation of a list of integers:

public static double GetStandardDeviation(this IEnumerable<int> values)
{
	double standardDeviation = 0;
	int[] enumerable = values as int[] ?? values.ToArray();
	int count = enumerable.Count();
	if (count > 1)
	{
		double avg = enumerable.Average();
		double sum = enumerable.Sum(d => (d - avg) * (d - avg));
		standardDeviation = Math.Sqrt(sum / count);
	}
	return standardDeviation;
}

Here’s how you can call this method:

List<int> ints = new List<int>() { 4, 7, 3, 9, 13, 90, 5, 25, 13, 65, 34, 76, 54, 12, 51, 23, 3, 1, 7 };
double stdev = ints.GetStandardDeviation();

View all various C# language feature related posts here.

Introduction to CouchDB with .NET part 20: Mango query array operators

Introduction

In the previous post we started looking into query operators in Mango. Query operators are prefixed with the dollar sign $ and define search operators such as greater-than, less-than-or-equal-to or not. They are quite self-explanatory and easy to use in JSON queries. At the end of the post we also set up two new databases: people and restaurants. They are better suited for the topic of this post which is operators related to arrays.

Read more of this post

How to build URIs with the UriBuilder class in C#

You can normally use the URI object to construct URIs in C#. However, there’s an object called UriBuilder which lets you build up a URI from various elements.

Here’s an example to construct a simple HTTP address with a scheme, a host and a path:

UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "http";
uriBuilder.Host = "cnn.com";
uriBuilder.Path = "americas";
Uri uri = uriBuilder.Uri;

uri will be “http://cnn.com/americas&#8221;.

Read more of this post

Introduction to CouchDB with .NET part 19: Mango query operators

Introduction

In the previous post we continued our discussion about Mango queries in CouchDB. A large part of the post concentrated on indexing, what indexes are, the different types of indexes, how they are created and how they are invoked in a Mango query by the query planner. We saw how a warning was issued when we executed a query on a field that was not indexed. We don’t have to create an index on every property we want to query but the most frequently queried fields should really be indexed to speed up read operations. Mango indexes are translated into view design documents. Indexes come at a price as they need to be updated when the database is updated. Finally we looked at field selection, skipping, sorting and limiting in JSON queries.

In this post we’ll look at examples of Mango operators.

Read more of this post

Making variables mutable in F#

F# takes immutability of variables very seriously. If a variable is declared with the let keyword then it is also immutable, meaning we can’t change its value after the declaration. In many popular OOP languages immutability only concerns strings but in F# all types are covered.

Here’s an immutable integer:

let thisIsImmutable = 3

Trying to assign a new value will fail:

Read more of this post

Ignoring the return value of a function in F#

From time to time we need to call a function which has a return value which we don’t care about. E.g. a function can perform some action and then return true if it has succeeded but throw an exception otherwise. In that case it would be enough to call the function and ignore the return value assuming that the function succeeded in case no exception was thrown.

Here’s an extremely simple F# function which only returns true:

let booleanFunction someInput =
    true

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.