Typing Resistance

See the original posting on DZone Python

I assure you, this is a post about programming, it’ll just take a few paragraphs to get there.

There’s a biological mechanism known as resistance, and it plays out in many different systems. For example, as you habitually drink more alcohol, you gain a tolerance, which prevents you from getting drunk as easily. This can be called alcohol resistance. When you habitually run high levels of insulin, your body becomes less sensitive to insulin, making you insulin resistant. When you go into a loud room, your ears adjust down the sound, making you noise resistant. And when you change enough dirty diapers, you become smell resistant.

Conditionally Include Partial View in ASP.NET Core

See the original posting on DZone Python

I have an ASP.NET Core web application where I need to include a partial view only if it exists. The application uses areas and some areas may have their specific side menu. This blog post shows two ways to conditionally include a partial view in an ASP.NET Core layout page.

My goal is to do it the easiest way possible by using out-of-the-box things and making sure I don’t create an ugly looking mess. I wanted to avoid all kinds of additional classes to wrap dirty secrets away from controllers and views.

Create Location-Aware Ads in Android With the HERE Geofencing API

See the original posting on DZone Python

A few months ago you probably heard the story about Burger King giving out coupons for $0.01 burgers every time someone entered a McDonald’s with the Burger King mobile application installed. Whether or not you like either fast food chain, this was an ingenious marketing strategy and use of location in a mobile application.

So how does something like this work from a technical point of view?

Implementing INotifyPropertyChanged

See the original posting on DZone Python

This is a short post about how to implement INotifyPropertyChanged without using any advanced tooling. I have some small UWP applications where I’m using MVVM to separate presentation and logic. Here is how I use INotifyPropertyChanged with a base class for multiple view models.

First, one’s introduction to INotifyPropertyChanged comes usually through some existing view model. The interface is used to communicate to the view that some properties in the view model have changed. Take a look at thePropertyChanged event and theNotifyPropertyChanged method (this method is not part of the interface).

Geofencing Regions With JavaScript and HERE

See the original posting on DZone Python

When it comes to maps and location services, being able to see if a position is within a particular region is often an important business need. The regions being tracked are known as geofences and they’re not difficult to produce and use.

In this tutorial, we’re going to see how to create a geofence and then determine if a point falls within that geofence using JavaScript in combination with the HERE JavaScript SDK and HERE REST API.

PHP Traits for Interface Contract Testing

See the original posting on DZone Python

Interfaces, those neat artifacts created to represent contracts to be fulfilled by classes. When appropriately used, they’re a very powerful way to express the expectations a client class has on implementations. Yet, most languages lack the tools to express those aspects that you can’t see by looking at the method signatures.

What should a method return under certain circumstances? If condition X is met, should it throw an exception? If so, of what type? All those questions can be answered by writing good documentation, that’s true, but, what about enforcing those rules? And who writes good docs in a world where working code is more important than documented code? That’s where the documenting facet of unit tests come in handy.

Developer Tutorial: Making Your SPA Content Editable, Anywhere

See the original posting on DZone Python

Single Page Apps (SPA) have grown in popularity due to their ability to deliver dynamic user experiences, like those you would expect from a mobile or desktop application, quickly and easily. While SPAs are great from a user perspective, they can be a bit more challenging for your editors to make content changes and updates.

In Part 1 of this post, I showed you how to use a headless CMS and React to build a Single Page App. Today, I’ll show you how you can make your SPA content editable in a CMS.

Adding Google reCAPTCHA v3 to Your Laravel App

See the original posting on DZone Python

Hi there. I want to share with you how I implemented Google’s reCAPTCHA v3 in my Laravel app.

Securing HTML forms from bots is an essential part of the security of any web app these days. One common and easy solution to this is implementing a captcha system. And Google’s reCAPTCHA v3 makes it quite easy to both implement as a developer and use as a user (v3 users do not have to select images to verify).

JavaScript Generators and How They Work

See the original posting on DZone Python

What Are Generators?

  • Generators in ES6 are a new way of working with functions and iterators.
  • They appear to be a function but behaves like an iterator which simplifies the task of writing iterators.
  • They are different from a normal function, as they can stop mid-execution and then continue from where they stopped.
  • In layman’s terms, they are similar to the way we put a marker/bookmark in a page of the book we are reading. Then later we resume reading the book from that particular page instead of starting all over again. Here we acted as a generator function.
  • They can generate a series of results instead of a single value.

Generator Syntax

  • Creating a generator is similar to a normal function, with the difference that it requires a * between the function keyword and function name.
  • It allows any number of spaces or no spaces in between.
  • It uses the yield keyword to pause and resume execution.
  • Since it is just a function, we can use it anywhere just like we would with normal function, i.e. inside objects and class methods.
  • Basic syntax:
// All below formats are valid with spaces/no spaces in between function keyword, * and function name.
function * functionName() {
    // Your generator related codes here.
}

// OR below format.
function *functionName() {
    // Your generator related codes here.
}

// OR below format.
function* functionName() {
    // Your generator related codes here.
}

// OR below format.
function  *  functionName() {
    // Your generator related codes here.
}

// OR below format.

function*functionName() {
    // Your generator related codes here.
}

// Inside Class method.
class testClass {
    *functionName() {}
}

// Inside object
var testObject = {
    *functionName() {}
}

Yield Keyword

  • The yield keyword is used to return data and pause the execution of the generator.
  • Every time the generator encounters yield, it halts the execution at that point and returns the specified value. It then resumes the execution upon calling the next() method on the Generator object until it finds the next yield.
  • In the context of generators, we do not say that it returned a value. We say that it has yielded the value.
  • Using return inside a generator will set the done property to true, after which it cannot generate any more values. All the code after the return statement will not execute.
  • Syntax:
// Generator with yield. 
function * generator() {
    console.log('First execution.');
    yield 'Yield First execution, saved the state and exit';
    console.log('Second execution will be on next() call.');  
    yield 'Yield second execution, saved the state and exit';
}

const generatorObj = generator();

next() in Generators

  • The generator returns an object on which we can call next().
  • Every invocation of next() will return an object containing the returned value and the status of the generator’s execution.
  • The value property will contain the value and the done property will return true or false for the generator’s execution status.
  • When done becomes true, the generator stops and won’t generate any more values.
{
    value: Any,
    done: true|false
}
function * generator() {
    console.log('First execution.');
    yield 'Yield First execution, saved the state and exit';
    console.log('Second execution will be on next() call.');  
    yield 'Yield second execution, saved the state and exit';
}

const generatorObj = generator();

// After below execution, generator will yield value, return below object and pause execution.
// {value: 'Yield First execution, saved the state and exit', done: false}
setTimeout(() => console.log(generatorObj.next()), 1000);

// After below execution, generator will yield value, return below object and pause execution.
// {value: 'Yield First execution, saved the state and exit', done: false} 
setTimeout(() => console.log(generatorObj.next()), 3000);

// After below execution, generator will yield value, return below object and close execution.
// {value: undefined, done: true}
setTimeout(() => console.log(generatorObj.next()), 5000);
  • The below screenshot shows the different states of a generator during its execution of how it gets "suspended" when it encounters the yield keyword, resumes when next() is called, and then gets closed after the execution is complete:JavaScript generators
  • If we use return then it will not execute any code present after the return statement. Sample code (JSFiddle link: generator with return statement):
  • function * generator() {
        console.log('First execution.');
        yield 'Yield First execution, saved the state and exit';
        return 'Execution ends here due to return and will not execute rest of the codes.';  
        // All below codes will not get executed.
        yield 'Yield second execution, saved the state and exit';
    }
    
    const generatorObj = generator();
    
    // After below execution, generator will yield value, return below object and pause execution.
    // {value: 'Yield First execution, saved the state and exit', done: false}
    setTimeout(() => console.log(generatorObj.next()), 1000);
    
    // After below execution, generator will yield value, return below object and completes the execution.
    // {value: 'Execution ends here due to return and will not execute rest of the codes.', done: true}
    setTimeout(() => console.log(generatorObj.next()), 3000);
    
    // generator execution is already completed so it will just return value as undefined and done as true.
    // {value: undefined, done: true}
    setTimeout(() => console.log(generatorObj.next()), 5000);
  • We can also pass values to next().
    Sample code (JSFiddle link: next() with value passed):
  • function * generator() {
    console.log('First execution.');
    yield 'Yield First execution, saved the state and exit';
    console.log('Second execution will be on next() call.');
    let passedArgument = yield 'Yield second execution, saved the state and exit';
    yield passedArgument;
    }

    const generatorObj = generator();

    // After below execution, generator will yield value, return below object and pause

    How to Build an iMessage Extension for a React Native App (Part 2)

    See the original posting on DZone Python

    In this post, I will show you how we built an iMessage extension by writing a bridge for our React Native-based mobile app. This approach took our team around two weeks to explore and might save you significant time if you have a similar intention. This is part two out of two (you can find Part 1 here). 

    Project Recap

    When we set out to build an iMessage extension for Lisk Mobile using React Native, we immediately hit an exciting challenge. As it turns out, when it comes to third-party applications, Apple likes developers to play by its own rules. If a company wants to benefit from the features of the tech giant’s operational systems and rich user base, it needs to be built using Apple’s own tools and programming language. iPhone’s iMessage is definitely worth this hassle. It has proven to be a big hit since its release in 2016. Within the first six months, iMessage has generated thousands of innovative in-messenger extensions including those created by Airbnb and Dropbox. Late in 2018, Mark Zuckerberg admitted this feature is one of Facebook’s ‘biggest competitors by far.’ Since the release of Lisk Mobile during Lisk’s Berlin meetup in October 2018, our team has been busy implementing features such as Face ID Authentication, as well as developing blockchain-specific solutions. Identifying the opportunity to extend the iMessage option for our users, we got to work on our own integration.

    Client-Side vs. Cloud-Side Execution for Mobile Test Automation

    See the original posting on DZone Python

    One of the requirements of using Appium for mobile test automation is to start the Appium server in the background so that it can listen to the requests from the mobile app under test. And there are multiple ways that we can install and start the Appium server in the background.

    While running Appium tests from a local machine, we have to launch the Appium server on a specific port and update the desired capabilities to point to the server running locally. But there should be a better way to handle these and avoid extra work on desired capabilities. Fortunately, cloud-based app testing platforms like Bitbar provide the ways to run Appium client-side as well as cloud-side. In this post, we will compare the client-side and cloud-side Appium and see both sides of the coin.

    Pure Components in React

    See the original posting on DZone Python

    Pure components were introduced in React 15.3. React.Component and React.PureComponent differ in implementing the shouldComponentUpdate() lifecycle method. The shouldComponentUpdate() method decides the re-rendering of the component by returning a boolean. In React.Component, it returns true by default. But in pure components, shouldComponentUpdate() compares if there are any changes in state or props to re-render the component.

    Here I am sharing my observations about how unnecessary renders are reduced by the pure component.

    How to Build an iMessage Extension for a React Native App (Part 1)

    See the original posting on DZone Python


    I will show you how we built an iMessage extension by writing a bridge for our React Native-based mobile app. This approach took our team around two weeks to explore and might save you significant time if you have a similar intention. This is part one out of two of the walkthrough.

    When we set out to build an iMessage extension for Lisk Mobile using React Native, we immediately hit an exciting challenge. As it turns out, when it comes to third-party applications, Apple likes developers to play by their own rules. If a company wants to benefit from the tech giant’s operational systems and rich user base, it needs to be built using Apple’s own tools and programming language. iPhone’s iMessage is definitely worth this hassle. It has proven to be a big hit since its release in 2016. Within the first six months, iMessage has generated thousands of innovative in-messenger extensions, including those created by Airbnb and Dropbox. Late in 2018, Mark Zuckerberg admitted this feature is one of Facebook’s ‘biggest competitor by far.’ Since the release of Lisk Mobile during Lisk’s Berlin meetup in October 2018, our team has been busy implementing features such as Face ID Authentication, as well as developing blockchain-specific solutions. Identifying the opportunity to extend the iMessage option for our users, we got to work on our own integration.

    The iMessage extension was included in Lisk Mobile 0.10.0, which was released in February 2019. Our users can now request and send LSK tokens straight from the iOS-based messenger without opening our app. However, the journey to implement this feature wasn’t straightforward. Lisk Mobile is written in JavaScript using React Native, while iMessage requires development in native iOS. During our research, we have found there is just a handful of resources available to help with using React Native to build iOS extensions available out there. There was no clear way to proceed. After thorough deliberation, we have decided to try a different approach by building our own bridge implementation. We found it a very educational and motivational journey for our team to develop the feature in this way. We will show you how, by breaking the solution down into native and React Native parts, and describing how to bind these separated parts together.

    Exporting/Importing Angular Components Using the BitSrc Framework

    See the original posting on DZone Python

    This article is useful for experienced Angular developers. This article explains how to export Angular components from your project to bit and importing existing components from bit to your new project.

    Angular is a component-based framework. Components are the main building blocks of the Angular framework. Using bit export/import we can avoid writing code for components, again and again, thus following DRY (Don’t Repeat Yourself) principles.

    Telerik UI for Blazor Data Grid Component Basics

    See the original posting on DZone Python

    Telerik UI for Blazor is a brand new library of UI components for the Razor Components and Blazor frameworks. Even though Telerik UI for Blazor is in an "Early Preview" stage it ships with one of the most popular and versatile UI components, the data grid. The data grid features out-of-the-box functionality like paging, sorting, templates, and themes. In this article, we will focus on how to get started with the grid’s basic features.

    Prerequisites

    Since the ASP.NET Preview is are moving at a rapid pace, it’s best to update your bits. Make sure you’re on the current version of Razor Components (server-side) and Blazor (client-side) since we’ll be working with both. Detailed installation instructions for both frameworks can be found on the Blazor getting started page.

    Getting Started With React.js, Babel 7, Webpack 4, and MobX 5

    See the original posting on DZone Python

    I used to use Redux for application state management, but due to complex code patterns and a lot of boilerplate code, it was not friendly to me at all. Recently, I’ve started exploring MobX. MobX is a clean and handy framework for state management. All my recent development efforts have been with MobX.

    Getting my first project set up with the latest versions of MobX 5, I found some difficulties in packaging and wiring everything together with MobX decorators or annotations. Finally, I was able to resolve the issues and thought of sharing my experience in a blog post.

    1 2 3 4 5 152