Using HTML5 dialog element in Angular 2

Software Development
With Firefox giving the HTML5 dialog element support since early 2022, we can now make use of this HTML 5.2 element to simplify our websites and make our life easier. It's usage is very simple, we can add the dialog tags to our page and put some content inside them. <dialog> <p>Testing dialogs</p> <button>Ok</button> </dialog> Opening and closing the dialog The dialog won't display itself by default unless you set the open attribute: <dialog open> <p>Testing dialogs</p> <button>Ok</button> </dialog> Alternatively, the HTMLDialogElement comes with 3 methods you can call using JavaScript: var dialog = document.getElementsByTagName("dialog")[0]; // Show() will display it same way as the "open" attribute does, allowing you to still interact // with the rest of HTML elements in the page not behind the dialog. dialog.show(); // This one…
Read More

The new C# Record type

Software Development, Web programming
Introduced with C#9 (.Net 5) in November 2020, the new record type adds yet another way of declaring types in C#. By default record acts as reference type, like classes, but since C#10 you can also create a record struct (value type). You can also declare them using record class, but as that’s the default, you can omit the class type when doing so and declare them as just record. Record types are compiler-generated classes/structs with some predefined methods, they can be declared very lightly on coding but will then gain their features when compiled. They all follow the IEquatable interface. IEquatable : this interface ensures that they have value-based equality. This means that when comparing two of them, C# automatically compares their properties and the values inside them to…
Read More

appSettings.json file not found on AWS lambda

Software Development
While you don't necessarily need to actually have a json config file when using lambdas, we like to have them to add some additional settings more easily than configuring that many env variables, and while releasing a new lambda I found it wasn't releasing the file alongside the lambda itself when using Amazon's Sam Client, though I think this can also happen when releasing using the AWS Wizard. To solve this issue, simply right click on the json file you want to be added to the compiled code and select Properties, then set the "Copy to output directory" property to "Always". Alternatively, just add this to the .csproj xml file: <ItemGroup> <None Update="appsettings.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup>
Read More

AWS Step Functions Input/Result/Output Paths

Software Development
Quick reminder: By default, a Step Function will take the output from previous task/lambda and give it to the next, so unless you want to specify how to handle the model in a particular way you don't need to use these properties. But if you need to, you've got: InputPath Will set what part of the current model should be given to the current Task. By default the entire model is given to the Task/Lambda. ResultPath In case you want to keep the model you had but still include the just finished tasks' result in it, you can use this to set where inside that object the result will be set. By default the result of the Task/Lambda replaces the model. If set as null the task's result will be…
Read More

Request local endpoint from one .Net project to another skipping certificates

Software Development, Web programming
Just add this bit of code to the httpClientHandler: // Return `true` to allow certificates that are untrusted/invalid httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; Full code example: var myPostObj = new {prop1 = 1, porp2 = 2}; using (var httpClientHandler = new HttpClientHandler()) { // Return `true` to allow certificates that are untrusted/invalid httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; using (var client = new HttpClient(httpClientHandler)) { var reqAsJson = JsonConvert.SerializeObject(myPostObj); var content = new StringContent(reqAsJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); return response; } }
Read More

Adding highlighted blocks to wordpress 5+ posts

Software Development
This has become so annoying I need to write it down in case I forget about it in the future (what's the point of the HTML editor if the HTML gets modified by wordpress?). When adding a piece of code you want to highlight with Syntax highlighter, best approach is: Click on the "+" of the block on the side, and search for "Custom HTML", select it.Now you can add your "csharp" "js" or "html" tags as you wish with the already tabbed lines of code inside.If you click on preview that little block (there's a button to do this) it won't make it, but ignore, it actually works once you preview the entire post or publish it. Some examples Html (sourcecode language="html") or (html) [sourcecode language="html"] <h2>Here goes a…
Read More

Connecting to localhost using HttpClient in C#

Software Development, Web programming
When getting error message: The SSL connection could not be established, see inner exception. Inner exception: The remote certificate is invalid according to the validation procedure. We need to add a client handler that will simply accept all certificates no matter what. [csharp highlight="6,7"] private static async Task<HttpResponseMessage> Request(object request, string url, string headerKey, string secret) { using (var httpClientHandler = new HttpClientHandler()) { // Return `true` to allow certificates that are untrusted/invalid httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; using (var client = new HttpClient(httpClientHandler)) { client.DefaultRequestHeaders.Add(headerKey, secret); var reqJson = JsonConvert.SerializeObject(request); var content = new StringContent(reqJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); return response; } } } [/csharp]
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 and LESS, just the idea that they still use tables terrifies me a bit. There's the possibility of buying a template, but in my experience that may not be the best approach; companies that sell templates as a business model tend to obfuscate as much as possible of their product, and being HTML+CSS this means they will run some algorithm on it creating weird stylesheet keys and stuff just to make your editing life a painful hell. So the alternative, apart from creating a very simple and plain email, is to go opensource. Yes. There are some opensource email templates…
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

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

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