Friday, November 9, 2018

Link Hover Style 48

The post Link Hover Style 48 appeared first on Best jQuery.


by Admin via Best jQuery

Pagination Style 27

The post Pagination Style 27 appeared first on Best jQuery.


by Admin via Best jQuery

PHP Integers, Floats and Number Strings

Working with numbers in PHP seems to be a trivial concept but it can be quite confusing. It looks easy at first because PHP provides automatic type conversion. For example, you can assign an integer value to a variable and the type of that variable will be an integer. On the next line, you can assign a string to the same variable and the type will change to a string. Unfortunately, this automatic conversion can sometimes break your code.

There are a lot of types for numeric values as well. In this tutorial, you'll learn about  integers and floats in PHP, as well as the functions which can be used to determine the type of numbers that we are dealing with and convert between them. You'll also learn how to convert integers and floats to and from numerical strings.

Different Types of Numbers in PHP

Integers

The most basic type of number in PHP is the integer. As you might already know, integers are numbers without any decimal part. For example, 2 is an integer and so is 235298 or -235298. On the other hand, 2.0 and 3.58 are floats. We will discuss them in more detail later.

One important thing to remember is that it is not necessary that a number be of type int if it does not have a decimal part. For example, 16 * 2.5 is exactly 40 but the type of this result will still be a float. When you are multiplying numbers, the final result will be of type float if at least one of the operands was a float. It doesn't matter if the final number has a decimal part or not.

Also, the maximum possible value an integer can have in PHP on your system can be obtained using the constant PHP_INT_MAX. A value greater in magnitude than the value returned by PHP_INT_MAX will be stored as a float even if it looks like an integer.

Generally, you would expect the result of multiplication of two variables of type int to be of type int. However, it is not true in case of overflow. Multiplication of five or six different numbers can easily take you outside the bounds of int type. For example, the result of 128*309*32*43*309 is a float on my system because it exceeds the value of PHP_INT_MAX which is 2147483647.

You can use the is_int($value) function to check if a number is of type integer. There are two aliases of this function called is_integer($value) and is_long($value). Both of them will give the same result.

Floats

The next most common type of number that you will deal with is a float. Unlike integers,  which were simply numbers without decimal points in most cases, a number of type float can be represented in a variety of ways. The values 3.14, 12.0, 5.87E+10 and 3.56E-5 are all floats.

PHP will automatically convert a number to type float whenever decimals or very large numbers are involved. The float type can commonly store numbers with magnitude approximately equal to 1.7976931348623E+308. However, this is platform dependent.

The value 1.7976931348623E+308 may seem like a very large value—and it is!—but floats have a maximum precision of only about 14 digits. Any number with more digits than that will lose its precision. That means you can store a very large number, but you won't be able to keep the information about its exact value—in many cases, a float is only an approximation.

There are two functions which can be used to determine if the value you are dealing with is a float. These functions are is_float() and is_double(). Actually, is_double() is just an alias of is_float() so you can use any one of them and get the same result.

Infinity and NaN

There are two more kinds of numerical values that you might have to deal with when writing programs related to Mathematics. These values of infinity and NaN (not a number). Both these values require a little explanation because they are different from what you might expect.

Infinity in PHP is different from infinity in real life. In PHP, any numerical value above approximately PHP_FLOAT_MAX on a platform is considered infinity. So, 1.8e308 will give you float(INF) on var_dump(). You can check if a numerical value is finite or infinite using the is_finite() and is_infinite() functions.

Similarly, NaN stands for Not a Number but it doesn't check if a value is numerical or not. The value NaN is used for result of mathematical operations which are not possible in mathematics. For example, log(-1) will be NaN. Similarly, acos(5) will also be NaN. You can check if the value returned by a mathematical operation is not number by using the function is_nan().

Numerical Strings in PHP

Just like PHP dynamically change the type of different numbers based on how their values are used or assigned, it can also infer the value of different numerical strings for you to convert them to numbers.

The function is_numeric() can help you determine if a string or variable is indeed numeric or not. This function will return true for numbers written in octal, binary or hexadecimal notation. It will also return true if the numbers are written in exponential notation like +16.52e39.

Starting from PHP 7.0.0, when you pass a string to is_numeric(), it only returns true if the string consists of an optional sign, some digits, an optional decimal and an optional exponential part. This means that a numerical string written in hexadecimal or binary format will return false from PHP 7.0.0 onward.

PHP will implicitly cast any valid numerical string to a number when need arises. The following examples should help you understand this process better.

As you can see, all valid numerical string were converted to their respective values before addition or other operations were performed. The type of $num in the end depends on its final value.

In the last case, the hexadecimal string "0xfedd24" is not converted to its decimal value because PHP 7 does not consider it to be a valid numerical string.

Casting Strings and Floats to Integers

Every now and then, you will need to cast one type of numerical values into another. PHP has a variety of functions and techniques to do so. Most of the time, the conversion will be implicit and you won't have to worry about it. However, if you have to do the conversion explicitly techniques mentioned here will definitely help.

You can use (int) or (integer) to convert any value to an integer. In case of floats, the values will always be rounded towards zero. Another way to cast strings and floats to integers is with the help of intval() function. Both (int) and intval() work in exactly the same manner.

You should note that casting overflowing strings to integers will set the final value to the maximum permissible integer value. However, casting a float whose value is more than the maximum permissible integer value will result in the value oscillating between -2147483648 and 2147483647!

In certain situations, you might need to deal with very large numbers without loosing any precision. For example, it is impossible to get accurate result of multiplication of 987233498349834828 and 3487197512 using the * operator. It will give you 3.4426781992086E+27 after float conversion. Calculating the actual answer, which is 3442678199208600117812547936, will require use of libraries like BCMath. BCMath works by storing numbers as strings and doing arithmetic operations on them manually. Just remember that if you use BCMath, you will be dealing with strings instead of integers and floats.

Certain libraries will want you to only pass numbers of type int to their methods but you might unknowingly supply them a float value. This might happen because the value seems like an int because it doesn't have a decimal part. This would almost certainly result in an error if the library uses a function like is_int() to check if the passed number is of integer type. In such cases, it is always wise to first cast that number to int using either (int) or intval() and then pass it to any functions or methods of the library.

One example of when such a situation could come up would be when you are dealing with Mathematical functions like floor() and ceil() etc. floor() and ceil() will always return a float, even if you pass them an int!

One problem with casting floats to integers is that you will lose the decimal part of the numbers. This may or may not be desirable. In such cases, you can use functions like floor() and only cast the number to int type if its actual value is equal to the value returned by floor().

Let's say you have a library which allows you to do fractional arithmetic and it throws exceptions when you pass a number to its setNumerator() method that is not of type int. A variety of operations might turn a number in type float even if it is still an integer within the minimum and maximum bounds of type int. Using something like the code above will help you deal with such cases easily.

Final Thoughts

This tutorial has covered different ways in which PHP stores numbers and how you can determine if a number of a particular type. For example, you can use functions like is_int() and is_float() to determine the type of a number and proceed accordingly.

As you saw in the tutorial, PHP supports automatic type conversion. This means that sometimes smaller integers like 5 or 476 could have been stored as floats without you realizing it. Using these numbers in functions which only accept int values might result in exceptions or errors. We learned that a simple solution to this problem is be to explicitly cast such numbers to int if they don't have a decimal part and their values don't change upon casting.

After reading this tutorial, you should be able to determine the type of a number or the final type of a result after using a variety of operations using predefined functions and also explicitly cast them to a specific type after doing some checks.

As always, if you have any questions or additional tips, you are welcome to comment.


by Monty Shokeen via Envato Tuts+ Code

File Upload With Multer in Node.js and Express

Spaces: The New Quora Feature Everyone is Talking About

For the longest time, Quora has been a platform where people asked questions and got answers from a wide variety of people. The platform has slowly been making headway towards a more social media based approach, and the launch of their latest feature shows that this is the case. The new feature is...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Zia Zaidi via Digital Information World

Going beyond console.log()

#411 — November 9, 2018

Read on the Web

JavaScript Weekly

Test262 Report: An Up-to-Date Status Report of JS Feature SupportTest262.report is a new site that shows up to date level of support and information on how different JavaScript engines support various language features based on the results of more than 68000 tests.

Rick Waldron and Boaz Sender

Going Beyond console.log() — While console.log() may form the basis of many people’s debugging strategies, the console object has a lot more to offer, as covered here. If you don’t know about console.assert or console.count, step in.

Matt Burgess

Webinar: Reducing the Cost of Enterprise-Grade Mobile Apps — Resourcing problems and changing requirements impact your cost and speed of app delivery. Newer techniques drastically reduce costs and time. Learn more about how enterprises are accelerating development, cutting expenses, and reducing IT app backlog.

Progress Kinvey sponsor

A Netflix Web Performance Case Study — Netflix boosted performance on their frontend by switching from React and other client-side libraries to vanilla JS.

Addy Osmani

JSBI: A Pure-JS Implementation of the ECMAScript BigInt Proposal — The BigInt proposal (essentially arbitrary-precision integers) is due to become an official part of ECMAScript in the near future - this lets you play with it now.

Google Chrome Labs

Glider.js: A Fast, Lightweight Carousel/Scrolling List — Small and sweet, mobile friendly, and the homepage has lots of good demos. Plus, I just noticed it mentions this newsletter 😆.

Nick Piscitelli

Aurelia's 2018 Q3 Report and New Features — Aurelia is a modern front-end framework and it has gained many enhancements recently including a new single-file build you can pull into a page with a single script tag which makes it even easier to try out.

Rob Eisenberg

💻 Jobs

JavaScript Developer at X-Team (Remote) — We help our developers keep learning and growing every day. Unleash your potential. Work from anywhere. Join X-Team.

x-team

Sr. Fullstack Engineer (Remote) — Sticker Mule is looking for passionate developers to join our remote team. Come help us become the Internet’s best place to shop and work.

Sticker Mule

Join Our Career Marketplace & Get Matched With A Job You Love — Through Hired, software engineers have transparency into salary offers, competing opportunities, and job details.

Hired

📘 Tutorials and Opinions

Static Properties in JavaScript Classes with Inheritance — A look at a pattern for implementing static properties in ES6.

Valeri Karpov

Bending Jest to Our Will: Caching Modules Across Tests

Pete Corey

ES6 Proxies Now Supported in Nearly All Mainstream Browsers — Proxies (elegantly explained here) have been one of the last ES6 features to see widespread support in browsers.

Can I Use

A Code-Driven Guide to the HTML5 Canvas — A guide to the Canvas API, one of the best ways to draw graphics dynamically in the browser.

Flavio Copes

▶  Azure Tips and Tricks Video Series — Collection of short videos on using the Azure platform. New videos are released weekly. Subscribe now.

Azure sponsor

▶  How to Package a Polymer 3 App with Webpack

Daniel Persson

A Basic Guide to Getting Started with Angular Material

Rob Ferguson

Building a Donut Chart with Vue and SVG

Salomone Baquis

Patching the Vue.js Virtual DOM: The Need, the Explanation and the Solution — Your first question might well be, why would it be necessary to interfere with the Virtual DOM? Well…

Michael Gallagher

Git Aliases I Can't Live Without — A list of handy Git aliases inspired by the oh-my-zsh suite.

Michal Konarski

How Do Top Developers Deliver Video? - Download the 2018 Video Report

Bitmovin sponsor

5 Things I Didn't Know About Create React App

Blanca Mendizábal Perelló

Advanced CSS Theming with Custom Properties and JavaScript

SitePoint

🔧 Code and Tools

Webpack Bundle Optimization Helper — This online tool will analyze your bundle and give you actionable suggestions on how to reduce its size.

Jakob Lind

A Proof-of-Concept Babel Plugin to Compile React Components Into Native DOM Instructions — Very much an experiment/POC but interesting nonetheless.

Tobias Koppers

Detect JS Production Errors in Real-Time, Then Debug Them in Minutes — Practice proactive error monitoring: stop outsourcing bug discovery to users, or using logs for debugging.

Rollbar sponsor

Culori: A General-Purpose Color Manipulation Library — Supports most color spaces and formats defined in the CSS Colors Level 4 spec and can parse, convert, mix, create color differences, and more.

Moqups

vue-inter: Simple 1KB Internationalization library for Vue.js

EGOIST

Day.js: A 2KB Immutable Date Library Alternative to Moment.js — A minimalist library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.

iamkun


by via JavaScript Weekly

6 Ways to Bring Your Development Team Together with Technology

Are you looking for better ways of bringing the team together? Would you benefit from an arsenal of tools that facilitate team working, while boosting productivity and creativity?

Project managers in development teams have to be leaders of balance, progress, decision, and business need.

Exhausting!

Maybe you need to consider the workplace of the future: the potential for virtual teams to collaborate in new ways using interactive technologies.

If you're developing software and applications for the web and touchscreen devices, you need the cutting-edge of interactive technologies to help you communicate, test, display, and tweak your work in ways that push creative possibilities.

Read on for 6 ways to incorporate interactive technology into your development team.

The Needs of the Software Development Team

Software is only ever as good as its user interface. Web technologies are inherently interactive, so it makes absolute sense that the tools that you use to develop them have interactivity built into their core.

1. Interactive displays

The web is a visual medium. Sure, it's made up of billions and billions of words, but - at its core - successful web apps have user-interactivity at their heart.

But when you're working as a team to develop applications that might look good on a mobile phone screen, you can't cram everyone around a single 10-inch screen.

Interactive displays deliver 4K definition, with an interactive touchscreen that replicates the mobile experience.

They add tactility to the development process; offering fingertip control during every stage of the design, testing, and implementation processes.

Interactive displays offer teams the ability to work collaboratively, using a central portal: designing and developing individual elements of an app in unison, while individual workstations connect wirelessly to a primary display.

2. Communication Hubs

Email has become a stalwart of communication within organisations.

But does it suit your mode of operation?

Most of us multi-task - there are few of us who have the privilege of working on just one project at a time. And if you're receiving emails from all angles, it can be almost impossible to track individual workstreams.

There's an ever-growing collection of virtual messaging services that can help keep each workstream separate and more manageable.

These are our favourite messaging services:

  • Slack is a messenger service that allows you to compartmentalise conversations into channels; giving you message threads, rather than a sporadic trail of emails. Slack integrates natively with Dropbox, Google Drive, Trello, Google Calendar, Google+ Hangouts, MS OneDrive and many other useful services that make work more efficient and collaboration more natural.
  • Microsoft Teamsintegrates with Office 365 and specialises in bringing large teams together. Consolidating video messaging, email, document creation suites, and project monitoring applications, MS Teams offers one central platform so that everyone can see what each other is doing. Projects become viewable from a single portal, facilitating transparent tracking of objectives and milestones. In combination with interactive displays, MS Teams really does come to life: bringing genuine and reliable flexibility to the workplace.

3. File Sharing

In web development teams, you're working with large amounts of data.

The post 6 Ways to Bring Your Development Team Together with Technology appeared first on SitePoint.


by Natalie Harris-Briggs via SitePoint