Monday, May 28, 2018

Invisible VFX: How to Add Composite Trees and Foliage in After Effects

Getting Started With Redux: Learn by Example

How to Create Vintage Photos With Faded Effect Photoshop Actions

How to Create Different Vector Textures Using Adobe Illustrator

16 Best Screen Recording & Capture Software for Mac (2018)

Introduction to API Calls With React and Axios

A Walkthrough of the Prototyping Tools in Sketch

Augmented Reality With ARKit: Feature Points and Horizontal Plane Detection

How to Draw a Cow

Friday, May 25, 2018

15+ Education PowerPoint Templates - For Great School Presentations

10 Cool Adobe Premiere Pro Text Effect Video Templates

How to Create a Glitch Effect Poster in Adobe Illustrator and Photoshop

How to Create a New Session in Pro Tools

A Beginner's Guide to Regular Expressions in JavaScript

A Beginner's Guide to Regular Expressions in JavaScript

Everyone working with JavaScript will have to deal with strings at one point or other. Sometimes, you will just have to store a string inside another variable and then pass it over. Other times, you will have to inspect it and see if it contains a particular substring.

However, things are not always this easy. There will be times when you will not be looking for a particular substring but a set of substrings which follow a certain pattern.

Let's say you have to replace all occurrences of "Apples" in a string with "apples". You could simply use theMainString.replace("Apples", "apples"). Nice and easy.

Now let's say you have to replace "appLes" with "apples" as well. Similarly, "appLES" should become "apples" too. Basically, all case variations of "Apple" need to be changed to "apple". Passing simple strings as an argument will no longer be practical or efficient in such cases.

This is where regular expressions come in—you could simply use the case-insensitive flag i and be done with it. With the flag in place, it doesn't matter if the original string contained "Apples", "APPles", "ApPlEs", or "Apples". Every instance of the word will be replaced with "apples".

Just like the case-insensitive flag, regular expressions offer a lot of other features which will be covered in this tutorial.

Using Regular Expressions in JavaScript

You have to use a slightly different syntax to indicate a regular expression inside different String methods. Unlike a simple string, which is enclosed in quotes, a regular expression consists of a pattern enclosed between slashes. Any flags that you use in a regular expression will be appended after the second slash.

Going back to the previous example, here is what the replace() method would look like with a regular expression and a simple string.

As you can see, the regular expression worked in both cases. We will now learn more about flags and special characters that make up the pattern inside a regular expression.

Backslash in Regular Expressions

You can turn normal characters into special characters by adding a backslash before them. Similarly, you can turn special characters into normal characters by adding a backslash before them.

For example, d is not a special character. However, \d is used to match a digit character in a string. Similarly, D is not a special character either, but \D is used to match non-digit characters in a string.

Digit characters include 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. When you use \d inside a regular expression, it will match any of these nine characters. When you use \D inside a regular expression, it will match all the non-digit characters.

The following example should make things clear.

You should note that only the first matched character is replaced in the third case. You can also use flags to replace all the matches. We will learn about such flags later.

Just like \d and \D, there are other special character sequences as well.

  1. You can use \w to match any "word" character in a string. Here, word character refers to A-Z, a-z, 0-9, and _. So, basically, it will match all digits, all lowercase and uppercase alphabets, and the underscore.
  2. You can use \W to match any non-word character in a string. It will match characters like %, $, #, ₹, etc.
  3. You can use \s to match a single white space character, which includes space, tab, form feed, and line feed. Similarly, you can use \S to match all other characters besides white space.
  4. You can also look for a specific white space character using \f, \n, \r, \t, and \v, which stand for form feed, line feed, carriage return, horizontal tab, and vertical tab.

Sometimes, you will face situations where you need to replace a word with its substitute, but only if it is not part of a larger word. For example, consider the following sentence:

"A lot of pineapple images were posted on the app".

In this case, we want to replace the word "app" with "board". However, using a simple regular expression pattern will turn "apple" into "boardle", and the final sentence would become:

"A lot of pineboardle images were posted on the app".

In such cases, you can use another special character sequence: \b. This checks for word boundaries. A word boundary is formed by use of any non-word characters like space, "$", "%", "#", etc. Watch out, though—it also includes accented characters like "ü".

Similarly, you can use \B to match a non-word boundary. For example, you could use \B to only match "app" when it is within another word, like "pineapple".

Matching a Pattern "n" Number of Times

You can use ^ to tell JavaScript to only look at the beginning of the string for a match. Similarly, you can use $ to only look at the end of the string for a match.

You can use * to match the preceding expression 0 or more times. For example, /Ap*/ will match A, Ap, App, Appp, and so on.

In a similar manner, you can use + to match the preceding expression 1 or more times. For example, /Ap+/ will match Ap, App, Appp, and so on. The expression will not match the single A this time.

Sometimes, you only want to match a specific number of occurrences of a given pattern. In such cases, you should use the {n} character sequence, where n is a number. For instance, /Ap{2}/ will match App but not Ap. It will also match the first two 'p's in Appp and leave the third one untouched.

You can use {n,} to match at least 'n' occurrences of a given expression. This means that /Ap{2,}/ will match App but not Ap. It will also match all the 'p's in Apppp and replace them with your replacement string.

You can also use {n,m} to specify a minimum and maximum number and limit the number of times the given expression should be matched. For example, /Ap{2,4}/ will match App, Appp, and Apppp. It will also match the first four 'p's in Apppppp and leave the rest of them untouched.

Using Parentheses to Remember Matches

So far, we have only replaced patterns with a constant string. For example, in the previous section, the replacement we used was always "Add". Sometimes, you will have to look for a pattern match inside the given string and then replace it with a part of the pattern.

Let's say you have to find a word with five or more letters in a string and then add an "s" at the end of the word. In such cases, you will not be able to use a constant string value as a replacement as the final value depends on the matching pattern itself.

This was a simple example, but you can use the same technique to keep more than one matching pattern in memory. The number of sub-patterns in the full match will be determined by the number of parentheses used.

Inside the replacement string, the first sub-match will be identified using $1, the second sub-match will be identified using $2, and so on. Here is another example to further clarify the usage of parentheses.

Using Flags With Regular Expressions

As I mentioned in the introduction, one more important feature of regular expressions is the use of special flags to modify how a search is performed. The flags are optional, but you can use them to do things like making a search global or case-insensitive.

These are the four commonly used flags to change how JavaScript searches or replaces a string.

  • g: This flag will perform a global search instead of stopping after the first match.
  • i: This flag will perform a search without checking for an exact case match. For instance, Apple, aPPLe, and apPLE are all treated the same during case-insensitive searches.
  • m: This flag will perform a multi-line search.
  • y: This flag will look for a match in the index indicated by the lastIndex property.

Here are some examples of regular expressions used with flags:

Final Thoughts

The purpose of this tutorial was to introduce you to regular expressions in JavaScript and their importance. We began with the basics and then covered backslash and other special characters. We also learned how to check for a repeating pattern in a string and how to remember partial matches in a pattern in order to use them later.

Finally, we learned about commonly used flags which make regular expressions even more powerful. You can learn more about regular expressions in this article on MDN.

If there is anything that you would like me to clarify in this tutorial, feel free to let me know in the comments.


How to Take Constructive Criticism Like a Professional

Introduction to Popmotion: Custom Animation Scrubber

How to Learn to Draw: Stage Three, Visual Database

12 Best Online Photo Editors for Filters and Effects (Free + Paid)

Wednesday, May 23, 2018

WordPress Gutenberg Block API: Creating Custom Blocks

5 Amazing Assets for Awesome Architectural Photographers

11+ Best Political WordPress Themes for Campaign & Party Websites

How to Insert a Check Mark Symbol in PowerPoint PPT (In 60 Seconds)

Introduction to Popmotion: Pointers and Physics

What Are the WordPress PHP Coding Standards?

How to Create a Quick Burnt Wood Text Effect in Adobe InDesign

How to Create a Sliced Mountain Effect Using Adobe Photoshop

Tuesday, May 22, 2018

Creating Your First App With Fuse

How to Create a Sci-Fi Scan-Line Text Effect in Adobe Photoshop

How to Make Your Website With a Premium WordPress Theme

How to Create a Vector T-Shirt Mockup Template in Adobe Illustrator

20 Cool & Colorful Resume Templates (To Stand Out Creatively)

The Basics of Design Thinking

New Course: Connect to a Database With Laravel's Eloquent ORM

How to Draw Ears

Monday, May 21, 2018

15 Free Premiere Pro Templates to Make Great Videos in 2018

20 Best WPBakery Page Builder Addons & Extensions of 2018

10 Best Premiere Pro Animated Title Templates for 2018

How to Animate an Explosion in Toon Boom

How to Draw & Paint a Starry Unicorn Portrait in Adobe Photoshop

How to Back Up All Your Microsoft Outlook Emails

Introduction to Popmotion: Tween

Introduction to Popmotion: Tween

Popmotion is a functional JavaScript animation library. Compared to other libraries like GreenSock or Anime.js, Popmotion is low-level and unopinionated.

It packs a ton of features, like spring physics and pointer tracking, into a very small filesize (11.5kb).

It allows developers to write their own features using simple functions, rather than waiting for the library author to add them.

It also means it's just as easy to animate 3D objects, charts or React components as it is to animate DOM or SVG elements.

This flexibility can make the initial learning curve steeper than for other libraries. So, in this tutorial series, we'll learn the basics of Popmotion's powerful animations. We'll start with the workhorse of the animation world, the tween.

Install

Popmotion supports a variety of installation methods. In production, I recommend installing via npm, as this allows you to import only the bits you need, saving space even further.

However, for this tutorial, you can follow along with this CodePen, which has been set up with the latest version of Popmotion.

Tween

For those unfamiliar, a tween transitions between one number and another over a predetermined length of time. If you've used a CSS transition, Popmotion's tween function works exactly the same.

We can import tween like so:

By default, tween animates between 0 and 1 over a duration of 300 milliseconds. If you open your console, you can test this yourself:

But we don't want to animate the console—we want to animate the ball. For this, Popmotion includes another function, styler.

Note: In this first example, we defined both the update and complete functions. But if you provide start with only a single function, it will automatically assign it to update.

Styler

styler is used to create get/set interfaces for HTML and SVG styles optimised for use with animations (from any library!).

In the above example, tween is outputting a number, so we could of course set the ball's opacity like this (try it):

However, styler has the following benefits:

  • Batches renders to prevent layout thrashing.
  • Renders, at most, once per frame.
  • Allows transform props to be set individually, allowing the independent animation of props like scale and translateX.
  • Unifies the CSS and SVG transform coordinate models.
  • Understands default value types, so you can set translateX (for instance) without appending 'px'.

You're also not limited to using it inside an animation. You could manually set an element's style while others are animating, and the change will be automatically scheduled and batched along with the others.

So let's import it:

Create the ball styler:

Now we can use ballStyler to set and animate any of the ball's properties. ballStyler.set is flexible. It can set a single property:

Or multiple properties:

We want to animate opacity for now, so let's change our animation:

set can also be curried. By providing it just a property name, it will return a setter function for that prop. So we can neaten the above by writing:

So far, we've only animated the ball using the default tween properties. Let's take a look at how versatile a tween can be.

Tween Props

tween accepts one optional argument, an object of tween properties. Let's take a look at some of the more commonly used props:

from/to

tween can be between any two states. We define these with from and to.

Let's animate translateX by rewriting 'opacity' to 'x'. Then, pass from and to props:

Your ball now moves from left to right by 300px.

However, I said that a tween can be between two states, not just numbers. If we provide from and to objects of numbers and/or colors, we can animate multiple properties at once.

Try this:

This is an easy way to animate multiple props simultaneously.

Duration

duration is defined in milliseconds. By default, a tween will take 300ms, but if we set duration to 1000, it'll take a second:

Easing

Easing functions are used in tweening to change the rate of movement throughout the animation.

In real life, objects don't start or stop at their target velocity. Depending on the object, they gradually speed up, or gradually slow down, or both.

An easing function simply works by taking the tween's progress, defined as a number between 0 and 1, and returning a new one.

You don't need to know how to make these functions because Popmotion provides a bunch for you.

Import them:

By default, ease is set to easing.easeOut. When a function eases out, it means it starts fast and ends slow.

This was chosen as default because it's my belief that most animation in user interfaces should initiate as a result of a user's action. By starting fast and ending slow, the user will feel as if they imparted their energy, via their tap or click, directly into the interface. It feels snappy, alive, and responsive.

For many animations away from the user's input, or on their own, it can feel a little less jarring to use an animation that eases in, like easing.easeInOut or easing.anticipate, which does a playful tug before animating.

Finally, there's the easing.cubicBezier function, which creates a new easing function based on an easing curve, just like CSS transitions. This provides a massive degree of control and flexibility over your motion.

Try applying some of these to your animation while playing around with duration to see how it affects the feel and character of it.

Repeating

Animations can be repeated in three different ways: loopyoyo, and flip.

Loop starts the animation from the start. Yoyo mirrors the tween by running it backwards. And flip runs it backwards and flips the easing function.

One of these can be set per tween, and each is set as a number that denotes the number of times to repeat the animation. To repeat forever, simply pass Infinity:

Playback 

When a tween is started, it returns playback controls that we can use to control that animation.

In the above example, controls will have access to all of these playback methods, like stoppause, and resume:

We can use these playback controls to pause and then seek through the tween:

With this, we can create a scrubbable animation! In a later tutorial, we'll explore how to use Popmotion's pointer function to create a scrub bar, but for now you can scrub one tween with a second tween, to see this in action:

Keyframes

For simple, a-to-b transitions, tween is excellent. For more complicated sequences of tweens, Popmotion provides another function called keyframes.

Let's import it now:

keyframes tweens through a linear series of states. We provide these states to its values property:

Like tween, we can also define these states as objects. So to move the ball around in a square, we can write:

By default, keyframes will allocate each of these tweens an equal share of the overall duration.

By providing a times array, we can mark each of these states with a number between 0 and 10 represents the start of the animation, and 1 represents the end:

This way, we can adjust the length of the animation without having to remark each individual segment.

It also allows each animation to be given an individual easing with the easings property:

Because keyframes is just a tween, we can adjust its overall playback with all the same properties like ease and loop, and control it with all the same methods that we learned earlier.

Conclusion

The tween and keyframes functions allow you to create both simple and complex animations.

styler brings its own benefits, like usage outside of animations, standardisation of CSS and SVG transform models, and render batching for high animation performance.

In this tutorial, we've covered just a couple of the animations that Popmotion offers. In the next installment, we're going to explore pointer tracking and velocity-based animations like physics and spring.

Velocity-based animations can be used to create natural-feeling UIs that react realistically to a user's input. See you there!


Your First Wireframe With Adobe XD

Illustrator in 60 Seconds: The Perspective Grid

Creating a Magnum Mecha Character in Maya: Part 4

Thursday, May 17, 2018

How to Create a Llama Illustration in Adobe Illustrator

5 Amazing Visual Assets for Better News Video Broadcasts

How to Create a Quick, Wobbly, Warped Text Effect in Adobe Photoshop

20 Awesome Google Sheets (Spreadsheet) Tips & Tricks

21 Medical PowerPoint Templates: For Amazing Health Presentations

How to Prepare Your Site for WordPress Gutenberg

How to Prepare Your Site for WordPress Gutenberg

Gutenberg is coming to WordPress soon. Is your website ready? While we still don't know exactly what form it will take, this new content system will be added to WordPress core in the future. Let's take a look at the potential impacts this could have on your site, and ways that you can determine, and fix, problem areas ahead of time.

What Is Gutenberg?

Gutenberg is a WordPress project that aims to give users more flexibility in the design of their content. Essentially, the project aims to replace the current editor, which performs mostly as a word processor, with a more visual and structured interface. Currently, Gutenberg is a plugin, and it grants users the ability to modify their content similarly to how Visual Composer or other drag-and-drop editors do—albeit in a simplified and highly intuitive way.

If you would like to  learn more about what Gutenberg is specifically, take a look at my earlier post "What Is WordPress Gutenberg?"

  • WordPress
    What Is WordPress Gutenberg?
    Kyle Speaker

The Pieces of Your Site

Gutenberg is a massive undertaking and will likely touch a large number of endpoints within your website. These are the three areas we'll be scouring for issues:

  • Your Theme: Gutenberg comes with its own set of styles for content. Is your theme compatible? What will it look like with Gutenberg active?

  • Your Plugins: It's possible that Gutenberg might interact with your other plugins in unexpected ways. We'll look at what those might be, and what to do about any issues that arise.

  • Your Content: Gutenberg will affect how your content itself is displayed. We'll examine how that might change what your pages look like, and go over some potential fixes if you're having problems.

Setting Up a Testing Area

Before we get started, it's a good idea to set up a testing area where you can experiment with Gutenberg without breaking your live site. Ideally, you should set up your own testing area or create a local copy of your site. For more on how to perform either of those tasks, see the following tutorial:

  • WordPress
    Moving WordPress: Moving Your Site Manually
    Rachel McCollin

If neither of these is possible, you can do the testing directly on your site. Note that this can be risky, however, as we'll be activating and deactivating a number of pieces of your site. If you are doing the testing live, please make sure to create a backup of your site before beginning.

Once you know where you'll be testing, head to the plugins directory and find Gutenberg. Once it's installed and activated, read on.

Put Your Theme Through Its Paces

Now that you have Gutenberg installed, let's take a look at the first section of your site that might be affected: its theme. If there are already major problems at this point, such as database errors or problems with the WordPress admin, skip down to the What to Do When There Are Too Many Issues section.

Since Gutenberg interacts mainly with the content of the site, we only need to test a narrow set of things—luckily for us.

The first is that Gutenberg comes with its own style sheet and set of styles. Check each of the different page types and templates used on your site to make sure that they still appear appropriately. The main focus here is going to be elements within the main content area of your pages—especially content and image blocks. If you see any issues, it's likely that Gutenberg's styles are taking precedence over your site's.

To correct this, you'll need to identify where the problem is coming from. Typically, it will be a CSS selector focused on an HTML element, or it could be a priority of Gutenberg styles over your own classes. Whatever the case may be, try to identify where the error is occurring. Next, determine why the Gutenberg styles are overriding yours, and correct your code to allow it to take precedence.

Try to make any corrections within your own theme (or better yet, in a child theme or specified area for CSS in your theme), rather than altering Gutenberg. If you alter any of the files in Gutenberg directly, it's likely to be overwritten when the plugin is updated.

In a similar fashion, you'll want to give your admin area a once-over for any styling issues. Theme options and other custom-implemented sections generated by your theme appear to be the biggest culprits so far. Once you've identified styling issues in these areas, you can typically correct them by changing or creating a child theme and adjusting the CSS there.

Do Your Plugins Work?

After your theme is squared away, next up are your site's plugins. Specifically, keep an eye on any plugins that provide shortcodes that you use in your content (e.g. Gravity Forms), plugins that affect the appearance of your content (e.g. accessibility plugins that affect text size), and plugins that directly insert elements into your page (such as Advanced Custom Fields).

Looking at Shortcodes

To audit this area, first gather a list of any shortcodes that you may be using, along with what pages they exist on. With your list in hand, visit each of these pages to see if they are performing as intended. If you encounter any styling issues, then it’s likely that you're experiencing the same problem as above and need to readjust your styles.

However, if you're getting the dreaded rendered shortcode—that is to say that your page is displaying the [shortcode] instead of doing what it should—there is another solution. In this case, you can look at the block where the shortcode is and confirm that it’s not considered text (looking for and removing unwanted tags around the shortcode). If the problem still persists, moving the shortcode to a more appropriate block type should get everything back up and running.

Content Appearance

This issue arises from the same problem we've covered previously: style overrides. Identify the elements that are being affected and correct the CSS.

Element Creation

The final area that we'll be looking at for conflicting issues concerns element creation.  Any plugin that inserts HTML elements into a page without using shortcodes is suspect here—for example, when PHP pulls in custom fields from the Advanced Custom Fields plugin.

The most common slip-up with element creation revolves around blocks being mismatched. Since Gutenberg provides its own styles, there is a chance that if your elements are created inside an unintended block, they may render incorrectly. The fix for this is making sure your code adds elements to the block where you want them to be.

Is Your Content Appearing as Necessary?

This is not quite as urgent as the other problems we've discussed, but there might be some complications with how your content is rendered. Most of these problems will be from minor styling changes or how blocks are organized. To correct this, you'll have to play around with the block system until you get your page how you want it.

What to Do When There Are Too Many Issues

Did you run into a problem that you couldn't solve with the suggestions in this article? Don't panic! There’s still some time before Gutenberg hits WordPress Core.

First, record what the error is and what steps led to the error. The more information that you can gather, the better. Pass all of this information along to the Gutenberg team. With luck, they'll be able to determine the issue and fix it in a future release.

If you were working on a staging site, then at this point, that's all you can do for now. Continue to check the release notes to see if your problem is solved, or possibly work on solving it yourself.

If you were working on your live site, deactivating Gutenberg should put everything back to normal. If not, then now is the time to revert to that backup you made!

Good Luck on Your Install!

Gutenberg aims to be a massive change to the WordPress environment, one that looks to change content for the better. Before it hits the main branch, make sure to check that your site will function with the new changes. If you have problems other than what's listed here, better solutions, or corrections for anything in this article, please leave a comment below!


How to Draw All Crystal Shapes

30 Best Photoshop Collage Templates

How to Use Systems Thinking to Enhance UX Design

Wednesday, May 16, 2018

How to Email & Share Keynote Presentations in 60 Seconds

Introduction to Machine Learning in Python

Introduction to Machine Learning in Python

Machine learning is the act of giving computers the ability to learn without explicitly programming them. This is done by giving data to computers and having them transform the data into decision models which are then used for future predictions.

In this tutorial, we will talk about machine learning and some of the fundamental concepts that are required in order to get started with machine learning. We will also devise a few Python examples to predict certain elements or events.

Introduction to Machine Learning

Machine learning is a type of technology that aims to learn from experience. For example, as a human, you can learn how to play chess simply by observing other people playing chess. In the same way, computers are programmed by providing them with data from which they learn and are then able to predict future elements or conditions.

Let's say, for instance, that you want to write a program that can tell whether a certain type of fruit is an orange or a lemon. You might find it easy to write such a program and it will give the required results, but you might also find that the program doesn't work effectively for large datasets. This is where machine learning comes into play.

There are various steps involved in machine learning:

  1. collection of data
  2. filtering of data
  3. analysis of data
  4. algorithm training
  5. testing of the algorithm
  6. using the algorithm for future predictions

Machine learning uses different kinds of algorithms to find patterns, and these algorithms are classified into two groups:

  • supervised learning
  • unsupervised learning

Supervised Learning

Supervised learning is the science of training a computer to recognize elements by giving it sample data. The computer then learns from it and is able to predict future datasets based on the learned data.

For example, you can train a computer to filter out spam messages based on past information.

Supervised learning has been used in many applications, e.g. Facebook, to search images based on a certain description. You can now search images on Facebook with words that describe the contents of the photo. Since the social networking site already has a database of captioned images, it is able to search and match the description to features from photos with some degree of accuracy.

There are only two steps involved in supervised learning:

  • training
  • testing

Some of the supervised learning algorithms include:

  • decision trees
  • support vector machines
  • naive Bayes
  • k-nearest neighbor
  • linear regression

Example

We are going to write a simple program to demonstrate how supervised learning works using the Sklearn library and the Python language. Sklearn is a machine learning library for the Python programming language with a range of features such as multiple analysis, regression, and clustering algorithms.

Sklearn also interoperates well with the NumPy and SciPy libraries.

Install Sklearn

The Sklearn installation guide offers a very simple way of installing it for multiple platforms. It requires several dependencies:

  • Python (>= 2.7 or >= 3.3),
  • NumPy (>=1.82)
  • SciPy (>=0.13.3)

If you already have these dependencies, you can install Sklearn as simply as:

An easier way is to simply install Anaconda. This takes care of all the dependencies so you don't have to worry about installing them one by one.

To test if Sklearn is running properly, simply import it from a Python interpreter as follows:

If no error occurs, then you are good to go.

Now that we are done with the installation, let's get back to our problem. We want to able to differentiate between different animals. So we will design an algorithm that can tell specifically whether a given animal is either a horse or a chicken.

We first need to collect some sample data from each type of animal. Some sample data is shown in the table below.

Height (inches) Weight (kg)
Temperature (Celsius)
Label
7
0.6
40 Chicken (0)
7
0.6 41
Chicken (0)
37
0.8 37
Horse (1)
37
0.8 38
Horse (1)

The sample data we have obtained gives some of the common features of the two animals and data from two of the animals. The larger the sample data, the more accurate and less biased the results will be.

With this type of data, we can code an algorithm and train it to recognize an animal based on the trained values and classify it either as a horse or a chicken. Now we will go ahead and write the algorithm that will get the job done.

First, import the tree module from Sklearn.

Define the features you want to use to classify the animals.

Define the output each classifier will give. A chicken will be represented by 0, while a horse will be represented by 1.

We then define the classifier which will be based on a decision tree.

Feed or fit your data to the classifier.

The complete code for the algorithm is shown below.

We can now predict a given set of data. Here's how to predict an animal with a height of 7 inches, a weight of 0.6 kg, and a temperature of 41:

Here's how to predict an animal with a height of 38 inches, a weight of 600 kg, and a temperature of 37.5:

As you can see above, you have trained the algorithm to learn all the features and names of the animals, and the knowledge of this data is used for testing new animals.

Unsupervised Learning

Unsupervised learning is when you train your machine with only a set of inputs. The machine will then be able to find a relationship between the input data and any other you might want to predict. Unlike in supervised learning, where you present a machine with some data to train on, unsupervised learning is meant to make the computer find patterns or relationships between different datasets.

Unsupervised learning can be further subdivided into:

  • clustering
  • association

Clustering: Clustering means grouping data inherently. For example, you can classify the shopping habits of consumers and use it for advertising by targeting the consumers based on their purchases and shopping habits.

Association: Association is where you identify rules that describe large sets of your data. This type of learning can be applicable in associating books based on author or category, whether motivational, fictional, or educational books.

Some of the popular unsupervised learning algorithms include:

  • k-means clustering
  • hierarchical clustering

Unsupervised learning will be an important technology in the near future. This is due to the fact that there is a lot of unfiltered data which has not yet been digitized.

Conclusion

I hope this tutorial has helped you get started with machine learning. This is just an introduction—machine learning has a lot to cover, and this is just a fraction of what machine learning can do.

Additionally, don’t hesitate to see what we have available for sale and for study in the Envato Market, and don't hesitate to ask any questions and provide your valuable feedback using the feed below.

Your decision to use either a supervised or unsupervised machine learning algorithm will depend on various factors, such as the structure and size of the data.

Machine learning can be applied in almost all areas of our lives, e.g. in fraud prevention, personalizing news feed in social media sites to fit users' preferences, email and malware filtering, weather predictions, and even in the e-commerce sector to predict consumer shopping habits.


Introducing Fuse for Cross-Platform App Development

The Top 7 Corporate Intranet & Extranet WordPress Themes

How to Learn to Draw: Stage Two, Precision

How to Create an Instagram Story Cover: Photoshop in 60 Seconds

Monday, May 14, 2018

10 Awesome Premiere Pro Lower Thirds Video Templates

How to Draw Vanilla Flowers With Mesh in Adobe Illustrator

How to Create a Layered Floral Typography Text Effect in Adobe Photoshop

20+ Best Law Firm Website Designs: Inspiration for Lawyers & Attorneys

Creating a Unity Game With PlayMaker

How to Build a Sticky Sidebar on Page Scroll With ScrollMagic.js

How to Draw a Diamond

New Course: Convert a jQuery App to Vue.js

Wednesday, May 9, 2018

What Is Diversity & Inclusion Training? (+Why It’s Important)

WordPress Gutenberg Block API: Block Look and Feel

How to Create a Scary Back Alley Scene in Adobe Illustrator

Create a Library Finder App in Angular: LibraryListComponent and LibraryDetailsComponent

Create a Library Finder App in Angular: LibraryListComponent and LibraryDetailsComponent

In the previous tutorial of our series, we completed the creation of our HomeComponent and started working on the LibraryListComponent. While the HomeComponent allowed the users to enter the name of any library and search for it, the LibraryListComponent provided a list of libraries which matched the given search term.

  • Angular
    Create a Library Finder App in Angular: HomeComponent and LibraryListComponent
    Monty Shokeen

So far, we have only written the logic of our LibraryListComponent—we still need to update the HTML template and CSS files to make this component useful. In this tutorial, we will update the remaining files of our LibraryListComponent and also create the LibraryDetailsComponent in its entirety.

Creating the LibraryListComponent Template

If you read the previous tutorial, you might remember that we stored the data of individual libraries as objects in separate array elements. Since we plan to show all these results to our users, we need to use the *ngFor repeater directive to go over the whole list and render them inside the LibraryListComponent.

Each library will have its own containing div block with the name of the library rendered inside h4 tags. At the bottom of each library, there is a link which takes users to the details page of that library. All these elements are wrapped inside a container div with a fixed width of 800 px.

Here is the CSS that I have used to style the elements inside the LibraryListComponent template. I have added a top border on each library unit so that they look separate from each other. You can use another technique to separate them:

Creating the LibraryDetailsComponent

The LibraryDetailsComponent is the last component of our app. To quickly generate all the necessary files, move to your project directory and run the following command from the console.

This will create a folder called library-details in the root directory of your app with four files in it. We only need to be concerned with the three files named library-details.component.ts, library-details.component.html, and library-details.component.css.

Let's begin editing the library-details.component.ts file first. It will contain all the logic of our component. Just like LibraryListComponent, we begin by importing different dependencies.

One additional dependency that we will import is Location. It allows us to interact with the browser's URL. We will be using it to allow our readers to go back to the previous page by clicking on the back button inside our LibraryDetailsComponent. If they arrived here through the LibraryListComponent, they will be taken back to the list of libraries. If they arrived here by clicking on any of the popular libraries on the HomeComponent, they will be taken back to HomeComponent.

Inside the LibraryDetailsComponent class definition, we declare a bunch of properties to store information like the latest version, description, homepage, license, etc. All these have been initialized with a value of "Loading...". This value will be updated as soon as we get back the data about a particular library.

We call the getLibrary() method of our LibraryDetailsComponent upon initialization so that the relevant values can be populated as quickly as possible. Here is the complete code of our library-details.component.ts file:

Creating the LibraryDetailsComponent Template and Stylesheet

We have already stored all the information about a library in different variables, so displaying it to users will be easy now. I have used additional span tags in the template to show the information to users. This allowed me to properly align these values with ease. Here is the code for the library-details.component.html file:

Just like other components, I have wrapped all the elements inside a container div this time as well.

We will set the width of all span elements with the title class to have a fixed width of 250 px. This way, the details of the library will be aligned properly. Here is the CSS that needs to go inside our library-details.component.css file:

Final Thoughts

We began this tutorial by updating the template and CSS file of our LibraryListComponent. After that, we moved on to the LibraryDetailsComponent and learned how to display all the information about a particular library to our users. After completing all the four tutorials in this series, you should now have a working library finder app. 

The fastest way to learn Angular is to do something all by yourself. Keeping this in mind, you should try making some changes to this app. For instance, you could limit LibraryListComponent to only showing the first 20 or so results, or sort those results based on the name of the library, etc. We did something similar in our first Angular app series. Combining the knowledge of both these series should help you make these changes with ease.

I hope this series improved your understanding of Angular. If there is anything that you would like me to clarify in this tutorial, let me know in the comments.


How to Use Instant Alpha in Keynote in 60 Seconds

How to Retrieve Your Deleted or Archived MS Outlook Emails

Tips for Building an Enticing Getaway Website

Introduction to Apollo Client With React for GraphQL

How to Make Cool Photoshop Text Effects Fast With Actions

Tuesday, May 8, 2018

How to Choose the Best Lens to Use for Portrait Photography

REST vs. gRPC: Battle of the APIs

REST vs. gRPC: Battle of the APIs

The REST API has been a pillar of web programming for a long time. But recently gRPC has started encroaching on its territory. It turns out there are some very good reasons for that. In this tutorial, you'll learn about the ins and outs of gRPC and how it compares to REST.

Protobuf vs. JSON

One of the biggest differences between REST and gRPC is the format of the payload. REST messages typically contain JSON. This is not a strict requirement, and in theory you can send anything as a response, but in practice the whole REST ecosystem—including tooling, best practices, and tutorials—is focused on JSON. It is safe to say that, with very few exceptions, REST APIs accept and return JSON. 

gRPC, on the other hand, accepts and returns Protobuf messages. I will discuss the strong typing later, but just from a performance point of view, Protobuf is a very efficient and packed format. JSON, on the other hand, is a textual format. You can compress JSON, but then you lose the benefit of a textual format that you can easily expect.

HTTP/2 vs. HTTP 1.1

Let's compare the transfer protocols that REST and gRPC use. REST, as mentioned earlier, depends heavily on HTTP (usually HTTP 1.1) and the request-response model. On the other hand, gRPC uses the newer HTTP/2 protocol. 

There are several problems that plague HTTP 1.1 that HTTP/2 fixes. Here are the major ones.

HTTP 1.1 Is Too Big and Complicated

HTTP 1.0 RFC 1945 is a 60-page RFC. HTTP 1.1 was originally described in RFC 2616, which ballooned up to 176 pages. However, later the IETF split it up into six different documents—RFC 7230, 7231, 7232, 7233, 7234, and 7235—with an even higher combined page count. HTTP 1.1 allows for many optional parts that contribute to its size and complexity.

The Growth of Page Size and Number of Objects

The trend of web pages is to increase both the total size of the page (1.9MB on average) and the number of objects on the page that require individual requests. Since each object requires a separate HTTP request, this multiplication of separate objects increases the load on web servers significantly and slows down page load times for users.

Latency Issues

HTTP 1.1 is sensitive to latency. A TCP handshake is required for each individual request, and larger numbers of requests take a significant toll on the time needed to load a page. The ongoing improvement in available bandwidth doesn't solve these latency issues in most cases.

Head of Line Blocking

The restriction on the number of connections to the same domain (used to be just 2, today 6-8) significantly reduces the ability to send multiple requests in parallel. 

With HTTP pipelining, you can send a request while waiting for the response to a previous request, effectively creating a queue. But that introduces other problems. If your request gets stuck behind a slow request then your response time will suffer. 

There are other concerns like performance and resource penalties when switching lines. At the moment, HTTP pipelining is not widely enabled.

How HTTP/2 Addresses the Problems

HTTP/2, which came out of Google's SPDY, maintains the basic premises and paradigms of HTTP:

  • request-response model over TCP
  • resources and verbs
  • http:// and https:// URL schemas

But the optional parts of HTTP 1.1 were removed.

To address the negotiating protocol due to the shared URL schema, there is an upgrade header. Also, here is a shocker for you: the HTTP/2 protocol is binary! If you've been around internet protocols then you know that textual protocols are considered king because they are easier for humans to troubleshoot and construct requests manually. But, in practice, most servers today use encryption and compression anyway. The binary framing goes a long way towards reducing the complexity of handling frames in HTTP 1.1.

However, the major improvement of HTTP/2 is that it uses multiplexed streams. A single HTTP/2 TCP connection can support many bidirectional streams. These streams can be interleaved (no queuing), and multiple requests can be sent at the same time without a need to establish new TCP connections for each one. In addition, servers can now push notifications to clients via the established connection (HTTP/2 push).

Messages vs. Resources and Verbs

REST is an interesting API. It is built very tightly on top of HTTP. It doesn't just use HTTP as a transport, but embraces all its features and builds a consistent conceptual framework on top of it. In theory, it sounds great. In practice, it's been very difficult to implement REST properly. 

Don't get me wrong—REST has been and is very successful, but most implementations don't fully adhere to the REST philosophy and use only a subset of its principles. The reason is that it's actually quite challenging to map business logic and operations into the strict REST world.

The conceptual model used by gRPC is to have services with clear interfaces and structured messages for requests and responses. This model translates directly from programming language concepts like interfaces, functions, methods, and data structures. It also allows gRPC to automatically generate client libraries for you. 

Streaming vs. Request-Response

REST supports only the request-response model available in HTTP 1.x. But gRPC takes full advantage of the capabilities of HTTP/2 and lets you stream information constantly. There are several types of streaming.

Server-Side Streaming

The server sends back a stream of responses after getting a client request message. After sending back all its responses, the server’s status details and optional trailing metadata are sent back to complete on the server side. The client completes once it has all the server’s responses.

Client-Side Streaming

The client sends a stream of multiple requests to the server. The server sends back a single response, typically but not necessarily after it has received all the client’s requests, along with its status details and optional trailing metadata.

Bidirectional Streaming

In this scenario, the client and the server send information to each other in pretty much free form (except the client initiates the sequence). Eventually, the client closes the connection.

Strong Typing vs. Serialization

The REST paradigm doesn't mandate any structure for the exchanged payload. It is typically JSON. Consumers don't have a formal mechanism to coordinate the format of requests and responses. The JSON must be serialized and converted into the target programming language both on the server side and client side. The serialization is another step in the chain that introduces the possibility of errors as well as performance overhead. 

The gRPC service contract has strongly typed messages that are converted automatically from their Protobuf representation to your programming language of choice both on the server and on the client.

JSON, on the other hand, is theoretically more flexible because you can send dynamic data and don't have to adhere to a rigid structure. 

The gRPC Gateway

Support for gRPC in the browser is not as mature. Today, gRPC is used primarily for internal services which are not exposed directly to the world. 

If you want to consume a gRPC service from a web application or from a language not supported by gRPC then gRPC offers a REST API gateway to expose your service. The gRPC gateway plugin generates a full-fledged REST API server with a reverse proxy and Swagger documentation. 

With this approach, you do lose most of the benefits of gRPC, but if you need to provide access to an existing service, you can do so without implementing your service twice.

Conclusion

In the world of microservices, gRPC will become dominant very soon. The performance benefits and ease of development are just too good to pass up. However, make no mistake, REST will still be around for a long time. It still excels for publicly exposed APIs and for backward compatibility reasons. 


Why WordPress Uses PHP

How to Draw & Paint a Galaxy Afro Portrait in Adobe Photoshop

10+ Top Public Speaking Tips (To Help You Improve Quickly)

10 Side Gig Ideas for Designers to Make Extra Income

How to Create a Set of Organic, Hand-Drawn, Retro Patterns in Adobe Illustrator

How to Learn to Draw: Stage One, Manual Skills

Thursday, May 3, 2018

20 Useful PHP Scripts Available on CodeCanyon

10 Best Photoshop Actions With Cool Art Effects for Portraits

15+ Creative Powerpoint Templates - For Presenting Your Innovative Ideas

20 Glitch & VHS Photo Effects With Digital Photoshop Art Styles

What Is Google Sheets? (Free Online Spreadsheets Tool)

Learn the Fundamentals of Angular in Our Comprehensive New Course

Tips and Tricks For a Responsive Design Process in Sketch

How to Vector Hands Holding a Plant in Adobe Illustrator