Front-End

Uploading File from Browser to S3 with JavaScript

Uploading a file from a browser to S3 for only authorised users is a pretty cool trick. It is even cooler if we can build it in a serverless way. Here is the entire solution for a simple serverless app to authenticate with AWS Cognito and upload a file to …

Front-End

Serverless Authentication with AWS Cognito and JavaScript

In a traditional web application, authentication is handled by server-side code and users are managed in the database layer. In the world of serverless apps, we can offload the heavy-lifting to a managed authentication service like AWS Cognito to simplify it. This post focuses on JavaScript code to authenticate users …

Front-End

Using setInterval() and setTimeout() with JavaScript

setInterval() and setTimeout() functions are the quickest solutions to loop functions with JavaScript, often used for a simple animation effects. For example, setInterval(function(){functionA()}, 1000) executes functionA() every second. On the other hand, setTimeout(function(){functionA()}, 1000) executes functionA() once after waiting for 1 seconds. Both can be stopped by clearInterval() and clearTimeout() …

Front-End

React Unit Test Code Snippets with Jest and Enzyme

Sometimes all I need is to see a snippet of code without much explanation when I try to find a solution online. This is because I am familiar enough with the language and framework and need a quick reminder. So, here it is. I created a post with a few …

Front-End

Unit Testing React Form with Jest and Enzyme

Jest is a JavaScript unit testing framework created by Facebook. I usually use mocha for unit testing Node.js code, but when it comes to testing React, Jest combined with Enzyme is pretty much the best. Enzyme is a JavaScript utility library created by Airbnb. It lets you simulate DOM rendering …

.NET

Quickest Way to Enable CORS for ASP.NET Core Web API application

Browser security does not allow other domain to make AJAX requests.This is called same-origin policy which prevents malicious attack from other sites. When you need to allow other sites to make cross-origin requests, we can enable Cross-origin resource sharing (CORS). There is a pretty good documentation about enabling CORS for …

.NET

Unit Testing Entity Framework Database Update logic with NSubstitute

In the previous post (UnitTesting ASP.NET Web API by Mocking DbContext with NSubstitute), we explored how to create a unit test for getting data from database with Entity Framework by mocking DbContext and DbSet.  We are going to build upon the API we created previously and add PUT logic where …

.NET

Unit Testing ASP.NET Web API by Mocking DbContext with NSubstitute

In the previous post, we created a simpleWeb API in 5 minutes. Now, let’s refactor the code so that it is unit testable with xUnit. The API we build previously was sourcing the data from MySQL database through DbContext. This is an external dependency that we need to replace in …

.NET

Creating Web APIs using ASP.NET and MySQL in 5 minutes

Creating a web API that interact with a database with C# is quite easy thanks to ASP.NET and Entity Framework. Building API with ASP.NET is essentially creating a MVC application without View. If you learn how to create a website with ASP.NET, you can apply the skills directly to API …

Node.js

Using EditorConfig and ESLint in Node.js Project

There are a few tools available to help you to write quality code. In this post, we will show you how to set up Node.js project with EditorConfig and ESLint. EditorConfig is currently one of the most popular tools to maintain consistent coding styles between different editors or IDEs (for …