Creating AWS Lambdas with Visual Studio

Uncategorized, Web programming
Fair warning AWS Services are in constant change and evolution. Check the date of this post as in the last 18 months there's been new stuff added to those services and I expect more to come in the next 18, so if the post is a bit out of date be careful it may not be accurate. Installing and using the AWS plugin Need to install "AWS Toolkit for Visual Studio 2017 and 2019" plugin into Visual Studio. Then, you should have an "AWS Explorer" tab on the sidebar next to the Solution Explorer and the rest where you can set up your credentials and log into Amazon. That panel will also show you all the lambdas and rest of stuff you already have in Amazon. You can also add…
Read More

Email templates

Software Development, Web design, Web standards
Creating email templates can be a tedious task, with so many rules between different email readers, most of CSS not really working and us devs now so used to SASS or LESS, just the idea that they still use tables terrifies me a bit. There's the possibility of buying a template there, but in my experience that may not be the best approach, as companies that sell templates as a busness model tend to obfuscate as much as possible their product, and being HTML+CSS means they will run some algorithm upon it to create wierd stylesheet keys and stuff just to make your editing life pain as hell. So the alternative, apart from creating a very simple and plain email, is to go opensource. Yes. There are some opensource email…
Read More

Adding an SVG with HTML5

Web programming
When it comes to add an SVG to the page, so display an small icon or a big image, there are different ways to do it with pros and cons: Using the "object" tag I believe this to be the most common approach, which just embeds an svg into the page by requesting it as a resource from the server and embedding it into the page as a document. This one allows to simplify the HTML a very lot while keeping all the SVG details. Example [html]<object type="image/svg+xml" data="images/logo.svg" id="logo"></object>[/html] Known issue On being a different document (like using an iframe) your styles won't reach it. That may not be an issue to you but if you are planning to adapt its size or filling colors contextually or reactively then…
Read More

Parallel threads with C#

Web programming
Example of some code where I decided to take the data from the DB in batches instead than all in one go, which was timing out. This could have been done one after the other, just waiting for the previous one to finish before requesting next batch, but I decided to give it a go and try to get them all at the same time by making separate calls and waiting for them all to finish to build the result in order. Important bits in commented lines. [csharp] using System.Text; using System.Threading.Tasks; public abstract class BaseExporterRepository : BaseDataRepository<DbContext> { private readonly IDbContextFactory _contextFactory; protected readonly int batchSize = 5000; protected virtual string GetHeader() => ""; protected virtual Task<StringBuilder> BuildBatchAsync(DbContext ctx, int skip) => null; protected virtual Task<int> CountAllAsync() => null;…
Read More

Reducing local SQL Server DBs Disk space usage

Software Development
First, you can check its Disk usage at: right click on database > Reports > Disk usage. Which also tells you how much space is used by data and how much for logging. 1. Remove full logging Right click on db > Properties > Options > Recovery model > Set to "Simple". 2. Clean up the database Right click on db > Tasks > Shrink > Database > Ok Now you can refresh the report and check how the log data is mostly gone. Shrinking the database also reduces the amount of space data uses a bit.
Read More

Updating Node and npm in Visual Studio

Software Development
Visual Studio comes now with its own default Node.js plus npm on first install (if chosen) which saves you time on first set up, but unfortunately it doesn't make it so easy to update due to its version of Node and npm being local. So how do you update them? First, a couple of useful tricks: How do I check which global Node/Npm version I have installed? Open a command line and write: "node -v" or "npm -v" depending on which one you want to check. How do I check which Node/Npm version Visual Studio is using? There's a Visual Studio plugin called "Visual Studio Command Prompt" that can help you with this so you can open a command line and do as before. If not, you can use the…
Read More

Performing Queries with Kibana

Web programming
Queries To get anything in the index: [csharp] GET /_search {"query": {"match_all": {}}} [/csharp] To get a document type inside the index (dragon-dev is the index name): [csharp] GET dragon-dev/organisation/_search {"query": {"match_all": {}}} GET dragon-dev/article/_search {"query": {"match_all": {}}} GET dragon-dev/person/_search {"query": {"match_all": {}}} [/csharp] Search by Guid (two different ways): [csharp] GET dragon-dev/person/_search { "query": { "match": { "id": "8dd0f391-ce67-41e6-bf68-374716a90bfe" } } } GET dragon-dev/associate/_search { "query": { "match": {"associatedWithId": "dbc8814d-9123-47d3-8dac-e31a7de5107e" } } } [/csharp] Sorting [csharp] // Sorting by a numeric or Date field is straight forward GET dragon-dev/organisation/_search { "sort": [{"websiteId": {"order" : "asc"}}], "query": {"match_all": {}} } // But a text field requires to make it a keyword type and search by keyword: GET dragon-dev/organisation/_search { "sort": [{"name.keyword": {"order" : "asc"}}], "query": {"match_all": {}} } [/csharp] Deleting…
Read More

Setting up Neo4j to work with a C#.Net project

Web programming
Just a quick guideline to refresh my mind: Installing Neo4j Server First, go to their website and download and install the latest version. If you are planning to use this installation for dev purposes only, you don't need the enterprise version, the individual works just fine. Installing it should take no time and be quite simple, but once it's done, run the program and click on Start to start the server, then click on the link to browse to it. Unless you edit the config file to set off the authentication it will ask you to login, the default user/pass was something like neo4j/neo4j or neo4j/admin, I can't remember right now. Once that's done it asks to change the default password to a new one, you can set your own…
Read More

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