Asynchronous JavaScript

See the original posting on DZone Python

In this article, we are going to discuss asynchronous tasks in significant depth. We will be discussing what exactly asynchronous tasks are, what the hack callbacks are, closures, promises, and much more in the context of JavaScript.

Table of Contents

  • 1. Prerequisites
  • 2. Overview
  • 3. Callbacks in JavaScript
  • 4. Hitting HTTP Requests in JavaScript
  • 5. Callback Abstraction
  • 6. Closures
    • Method Currying
  • 7. Promises
    • Short-Hand Syntax for Promises
    • Promise Chaining
    • Fetch API
    • Async-Await

Prerequisites to Understand Asynchronous Concepts

Overview: What Exactly Does it Mean to Perform Tasks Asynchronously?

As Google says, asynchronous is ‘not existing or occurring at the same time.’ When we execute something synchronously, we start some sort of task like fetching a weather report from some third-party server and then we have to wait for it to finish before we move on to the next thing. When we execute something asynchronously, we can start some task, then we can actually get other work done before the task completesand that’s the beauty of performing tasks asynchronously. 

We All Deserve This Brief Reprieve From the Dumpster Fire That is the Internet

See the original posting on DZone Python

The Internet can certainly feel like a cold, dark place, especially for those of us who can’t help but stay mired in it day in and day out. I’m one of those people, and while I’d like to think I do a pretty good job keeping above the fray, it can be really hard when you just happen to stumble across pieces like this horrifying (and incredibly important) revelation in The Verge. (It turns out, being a professional Facebook moderator and having to witness the worst of the worst things people do to each other on a daily basis is extremely caustic for your health.)

But thankfully, we also have journalists like The Ringer’s Victor Luckerson, who did some work to uncover those times over the last decade when we weren’t trying to kill each other – times when we were actually able to put aside our differences and celebrate the things that connect us. And this isn’t just some dude sharing his favorite viral memes; it’s actually backed by UVM research.   

Serving Pre-Compressed Static Files in ASP.NET Core

See the original posting on DZone Python

Optimizing web applications is important because more economic web applications consume fewer CPU cycles and need less bandwidth — resources we have to pay for. It’s easy to turn on response compression on ASP.NET Core, but serving pre-compressed files needs more work. This blog post shows how to do it.

Why Pre-compressed Files?

Although it’s possible to compress files dynamically, when files are requested from a server it means additional work for the web server. Files to be compressed are changed only when a new deployment of the application is made. And the better compression we want the more work has CPU to do.

Angular 7 + Spring Boot Application: Hello World Example

See the original posting on DZone Python

In this tutorial, we will create a full-stack application where we expose an endpoint using Spring Boot and consume this endpoint using Angular 7 and display the data. In the next tutorial, we will be further enhancing this application and performing CRUD operations.

Previously, we have seen what a PCF is and how to deploy an application to PCF. I have deployed this application we are developing to PCF. The demo application is as follows-

How to Run Jython on Tomcat

See the original posting on DZone Python

A little something different this post, something a little closer to my day job, which is as a developer.

Here I will go through how to configure Jython to run under Tomcat. I have done this on an AWS instance, but because it is Java-based, it can be done on Windows and Mac just as easily. In fact, at work, I did this on Windows.

Create a Simple Shopping Cart Using React and Node

See the original posting on DZone Python

Web development has never been more exciting than now, with the introduction of new technologies and techniques, thanks to the dynamism and evolution of JavaScript. Now a web application can be configured using only JavaScript. This is made possible through the introduction of Node.js, which can be used on the server-side to manage data, and also the creation of several JavaScript frameworks, such as React.js, Angular, and Vue.js, which manage and control the client-side of the application.

In this article, we will be learning how to build a simple shopping cart app, using React.js as the front-end framework, and a backend server built using Node.js and Express.js.

Developer Tutorial on Using a Headless CMS and React to Build Single Page Apps

See the original posting on DZone Python

A headless CMS system allows users to control all the content, with strict separation from the display or front-end layers. This allows content creators to focus on what they do best: create high-quality content. A headless CMS architecture empowers marketers and developers to work together to deliver engaging customers experiences. One notable use case for headless CMSs today is creating Single Page Applications (SPA). SPAs deliver more dynamic user experiences, similar to what you might expect from a native mobile application or desktop application, making them very popular with today’s customers.

In this piece, I’ll walk you through how to use a headless CMS and React to build a SPA, using the headless capabilities of dotCMS, an enterprise, open source Java CMS. If you want to jump right into the code, here is the repo: https://github.com/fmontes/dotcms-page

Hacking JavaScript Games: Accessing Private JS Variables at Runtime via Debugging

See the original posting on DZone Python

I like to write little bots from the console to help with application and game automation. But when the variables and objects I need are created from within anonymous functions I can’t get access. In this post, I will explain how to access them.

I’ve tried writing helper code to access the methods within objects and trawl through the DOM to find specifically named objects, and that can help with a large application where the objects are all public.

How to Exclude Code From Code Coverage

See the original posting on DZone Python

Recently I blogged about how to generate nice code coverage reports for ASP.NET Core and .NET Core applications. This blog post focuses on how to leave out all code that will not be covered with unit tests from code coverage and get numbers shown on code coverage reports correct.

What to Exclude From Code Coverage?

I think almost all applications have some classes we don’t want to test. The usual candidates are primitive models and Data Transfer Objects (DTO). One example is given below: 

How to Set Up Django With Postgres, Nginx, and Gunicorn on Ubuntu 16.04

See the original posting on DZone Python

Introduction

Django is a free, open source, and high-level Python web framework that encourages rapid development and clean, pragmatic design. Django’s MVC (Model-View-Controller) architecture is maintained by the Django Software Foundation. Django is a strong web framework that can assist you to get your application online as quickly as possible. The primary goal of Django is to ease the creation of complex, database-driven websites. Django supports four major database backends including, PostgreSQL, MySQL, SQLite, and Oracle.

You can run Django in conjunction with Apache, Nginx using WSGI, Gunicorn, or Cherokee using a Python module.

Introduction: Espresso Testing for Android

See the original posting on DZone Python

As mobile developers, we spend most of our time creating new screens or changing screens that already exist and we need to know that the code works. That is why in our development process we must use tools to verify that our application continues to work as expected and that our development meets the quality expectation of the user story. So, in this article, we will talk about Espresso Testing.

We need to ensure that:

JavaScript Promises: The Definitive Guide, Part 1

See the original posting on DZone Python

The single-threaded, event-loop based concurrency model of JavaScript deals with processing of events using so-called “asynchronous non-blocking I/O model.” Unlike computer languages such as Java, where events are handled using additional threads and processed in parallel with the main execution thread, JavaScript code is executed sequentially. In order to prevent blocking the main thread on I/O-bound operations, JavaScript uses a callback mechanism where asynchronous operations specify a callback – the function to be executed when the result of an asynchronous operation is ready; while the code control flow continues executing.

Whenever we want to use the result of a callback to make another asynchronous call, we need to nest callbacks. Since I/O operations can result in errors, we need to handle errors for each callback before processing the success result. This necessity to do error handling and having to embed callbacks makes the callback code difficult to read. Sometimes this is referred to as “JavaScript callback hell.”

Binary Pattern Matching in Elixir

See the original posting on DZone Python

I’ve been working on a web client for my side project Grapevine, and part of that includes parsing a telnet stream. Before you ask, "A telnet stream!?", the web client connects to text-based games called MUDs that primarily used telnet as that’s how they started in the late 1980s.

Telnet is mostly a TCP stream that contains only text that should be output to the screen. Hidden inside the otherwise plain TCP stream is a series of bytes called IAC (Interpret as Command). This is the byte 255 followed by at least one other byte that describes what the command is.

Blazor CRUD Using Google Cloud Firestore

See the original posting on DZone Python

Introduction

In this article, we will create a Blazor application using Google Firestore as a database provider. We will create a Single Page Application (SPA) and perform CRUD operations on it. We will use Bootstrap 4 to display a modal popup for handling user inputs. The form also has a dropdown list, which will bind to a collection in our database. We will also implement a client-side search functionality to search the employee list by employee name.

Take a look at the final application.

Code Coverage Reports for ASP.NET Core

See the original posting on DZone Python

Code coverage reports for ASP.NET Core projects are not provided out-of-the-box, but by using the right tools we can build decent code coverage reports. I needed code coverage reports in some of my projects and here is how I made things work using different free libraries and packages.

Getting Started

To get started, we need a test project and some NuGet packages. Test project can be a regular .NET Core library project. Adda reference to web application project and write some unit tests if you start with a new test project. We also need some NuGet packages to make things work:

1 2 3 4 148