Performing queries in .Net with NEST

Web programming
First of all, I created a document model in C# named EsOrganisation with some basic fields: [csharp] [ElasticsearchType(Name = "organisation")] public class EsOrganisation { public Guid Id { get; set; } public DateTimeOffset CreatedDate { get; set; } public DateTimeOffset? UpdatedDate { get; set; } public int OrganisationTypeId { get; set; } public string OrganisationName { get; set; } public List<string> OrganisationAliases { get; set; } public List<string> OrganisationKeywords { get; set; } public List<int> Products { get; set; } } [/csharp] Then I also created a factory to retrieve the Nest.ElasticClient, to simplify just have in mind that when I call to client.SearchAsync() I have already instantiated and prepared it. Structured vs Unstructured Search Structured or Unstructured Search refers as to how are the filters applied, Structured search refers…
Read More

Some tips on C# Generics

Web programming
Defining interfaces You can define that a generic must implement an interface, which in essence allows you to know beforehand that a generic type will have a certain method (making it less generic) [csharp] public interface ISearchable { void Search(); } public class SomeClass<T> where T : ISearchable { public void DoSomething(T entity) { entity.Search(); // Can do this on a generic type because it's implementing ISearchable } } [/csharp] You can also use generics on the interfaces, in this case: [csharp] public interface ISearchable<TEntity> { TEntity Search(); } public class SomeClass<T> where T : ISearchable<T> { public T FindMe(T entity) { return entity.Search(); } } [/csharp] Now when referencing the interface we must set the generic type too. Warning!: If you set a constraint on a generic type any…
Read More

Implementing a basic Newtonsoft’s JsonConverter

Web programming
I was deserializing an object that requires to be a string at the client but it's actually a structure inside the database, a person's name, saved as a Name { FirstName:'', LastName: '', ... } type of object. By using Newtonsoft's deserializer into a model such model can't just have a string Name as Newtonsoft's deserializer won't know how to parse the object into a simple string, so instead I had to declare the property as the same type of object that the name is saved into the database: PersonName. Now I wanted to transform it into a string when re-serializing it to send it to the client, which could do with a mapper but decided to try Newtonsoft's JsonSerializer attribute to see if it works and to my amazement…
Read More

Node Sass could not find a binding for your current environment: Windows 32-bit with Node 0.10.x

Software Development
Node Sass could not find a binding for your current environment: Windows 32-bit with Node 0.10.x I ran into this error today and took a bit to find what the problem was. After triple-checking I did not have another version of Node installed, uninstalling, reinstalling, restarting Visual Studio, ... we finally found the issue: Visual Studio was using its own Node version, which was an older version and didn't really fit with what was set on the packages. Solution We just got into Visual Studio > Tools > Options > Projects and Solutions > External Web Tools and then moved the $(Path) variable upper in the chain so that it had more priority than Microsoft's Web Tools folder. This would make Visual Studio use my installed version of Node instead…
Read More

Some notes on DDD

Software Architecture, Software Development
Some Vocabulary Problem Domain/Domain The actual problem our software is going to solve, the purpose it is built for. Core Domain It's a subset of the previous ones. It's the essential part of the problem domain, the part which cannot be delegated and must be solved by us, software developers. Business Logic, Business Rules, Domain Logic, Domain Knowledge, Domain Model The business logic you enclose in your code represents the knowledge that you as a software developer have about the problem domain. The business logic of an application typically resides in the two innermost layers of the onion architecture. We refer to the notions of those two layers as domain classes, so a domain class might be a repository, an entity, aggregate, ... nut not an application service. Main concepts…
Read More

First steps into Angular 2 from Angular 1

Web programming
With the final version of Angular 2 just been released last month after the Release Candidate was released in May this year, we decided to get into it at our next project in my company and I decided to save some notes to myself in my blog as usual. First of: Angular's official Quick start guide. TypeScript? There are many changes in Angular2 compared with Angular1, one of those is the native possibility to use TypeScript, ES2015, Dart or plain javascript to code your app and transpile that later by just using Angular's config file to set so. This is part of the demo's config file at Angular's website where you can see how TypeScript has been configured to write the app: [js] (function (global) { System.config({ // DEMO ONLY!…
Read More

Setting up Selenium in C#

Software Development, Web programming
1. Download Selenium WebDriver for C# Go to SeleniumHG website and get into Downloads, scroll down until you see the different versions of the WebDriver and get the C# version. Extract the zip files into a folder. Create a project Create a Test Project using VS (File > New > Project > Test > Unit Test). Add the WebDriver libraries: References > Right click > Add Reference... > Browse > Take the right ones for your framework (35 or 40). Note: You can create a different type of project, like a Console App, but this other allows you to get test reports, config different suites of tests, etc. Start testing Now you can start testing, include the namespaces inside OpenQa. For example to test in Chrome: using OpenQA.Selenium; using OpenQA.Selenium.Chrome;…
Read More

Slipping images with AngularJS

Software Development
Lately there are many effects added to websites related to user's scroll down event. One of them consists on sliding elements across the page as if they were slipping up or down, Adidas did an awesome addition of such effect in their snowboarding section giving the effect that certain elements were slipping up and down only to return to their original place. I tried to copy part of that effect (without checking the scrolling speed) and this is what I got: First, let's add the listeners on our controller. One of these listeners is going to check for when does the scrolling happen and in which direction. By making use of Angular, we will add a flag the the scope to tell the element that we are scrolling in such…
Read More

Sublime is sublime!! :D

Software Development
I am a great fan of Visual Studio, but sometimes it lacks some of the lightness and flexibility you can get with other frameworks. It's too heavy on loading and has so many tools you aren't going to use just right now. And that's where Sublime seems to be doing it's best: it's light, very light, as it only comes with the basics for editing and you can then add plugins to it as need to customize it's features according to your needs. Just as a quick comparison, Visual usually takes around 200MB of memory, sometimes 400 or 500, Sublime seems to be fine with 50. Also, the opensource community seems to be quite into this project always adding new plugins for it with each new tool they make available.…
Read More

Mocking BackEnd with AngularJS

Web programming
I found myself on the need of isolating my FrontEnd AngularJS app from the backend so the app can continue working without Internet access or without access to the backend services. I did not want, though, to add anything too aggressive into the app, but a piece of code that can be attached or unattached very easily and without the app having to know about it at all, like an app extension. To do so, I found myself installing angular-mocks, creating a file that requests the library, attaches the $httpBackend to the app on run time, uses $httpBackend to mock the responses with some json files and forces the requests to be synchronous. Step 1. Installing angular-mocks First of all, to get access to $httpBackend we need to install angular-mocks,…
Read More

Including Google Maps into your AngularJS app

Web programming
I already did this in the past but things change and the plugin I was using has changed too. I use AngularJS with Angular-Bootstrap directives as to save me some time and make the best of Bootstrap stylesheets I'm already using. angular-google-maps is another directive int he same club of bootstrap friends and this is how to include it into your project: Installing packages I'm using bower to manage packages at the front end, so first of all let's install the required packages to make this work. I need the plugin angular-google-maps, which requires angular (obviously), lodash and angular-simple-logger to work. So just make sure you install all required packages using bower: [sourcecode language="js" wraplines="false"] bower install --save-dev angular bower install --save-dev angular-google-maps bower install --save-dev angular-simple-logger bower install --save-dev…
Read More

Upgrading WordPress blogs

Software Development
Once in a while you must do this and, if you end up lazy for years like me, may even feel nightmares about upgrading from version 2.x to version 4.x, luckily upgrading Wordpress is one of the easiest things you can do: Making a backup It's always wise to backup your site before you make such a change. Don't worry, you don't need to backup absolutely everything, but check which things you need to backup depending on your needs: 1. Your posts and comments: which is as easy as going to admin > Tools > Export and save an XML (maybe JSON in future?) file with all the relevant content. Whatever happens now, any wordpress version should be able to recover your most relevant data. 2. Your wp-content: usually you…
Read More

Managing packages with Bower

Web programming
Installing Bower Just do it globally so you can access it from anywhere. You need to have previously installed Node.js in order to install it, and Git in order to use it. npm install bower -g Have in mind you will also need to install it in your TeamCity server as you'll probably want to get the packages from there too. Installing packages Installing a package with bower is as easy as moving to the root folder of your project using the console and executing something like this: bower install angularjs You can also install a concrete version using # bower install angularjs#1.4.9 Or install more than one package with one command: bower install angularjs jquery bootstrap angular-ui Saving installed packages The main idea of bower is to keep track…
Read More

HTML5 caching: Cache API

Web standards
We can manage the browser's cache to save our website as an app in it. App cache file - To config the cache we use something similar to the robots: a txt file listing the urls to cache with some options. - The file must be served as "text/cache-manifest" mime type. To config it on the server use this extension: .appcache - We tell the browser where the file is at the <html> tag of our page using a new attribute: manifest="" <html manifest="myCache.appcache"> - You must include the manifest on each page you want to cache resources. - Without the cache manifest attribute the browser will use the default caching system. How the file is organized CACHE MANIFEST true/false This navigator property allows us to know if the browser…
Read More

AngularJS : Service vs provider vs factory

Web programming
Just copy-pasting this answer from Ben Clinkinbeard: Services Syntax: module.service( 'serviceName', function ); Result: When declaring serviceName as an injectable argument you will be provided the actual function reference passed to module.service. Usage: Could be useful for sharing utility functions that are useful to invoke by simply appending () to the injected function reference. Could also be run with injectedArg.call( this ) or similar. Factories Syntax: module.factory( 'factoryName', function ); Result: When declaring factoryName as an injectable argument you will be provided the value that is returned by invoking the function reference passed to module.factory. Usage: Could be useful for returning a 'class' function that can then be new'ed to create instances. Providers Syntax: module.provider( 'providerName', function ); Result: When declaring providerName as an injectable argument you will be provided…
Read More