Monday, January 16, 2017

Handle Password and Email Changes in Your Rails API

This is part two of our series about authentication from scratch using JWT. The first part of the series can be found here. In the previous tutorial, we saw a quick overview about JWT, different authentication mechanisms, and a set of basic authentication APIs, like registration, confirmation, and login. In this part, we will see the next set of APIs such as password (reset and change) and email update.

Continue reading %Handle Password and Email Changes in Your Rails API%


by Vinoth via SitePoint

Choco

Choco

'Choco' is a One Page HTML E-commerce template perfect for a shop selling between 1 and 10 products. The template comes with light or dark colors scheme options - the dark pictured here. The real win is this template already has a working cart that integrates right into PayPal. So all you need to start selling is edit the HTML template and upload to your hosting - no monthly costs for any hosted commerce services like Shopify. Other features include big image intro slider, product carousal, specials section (with countdown timer), testimonials to help those conversions, a history timeline, a contact form and of course a location map. I must give a final shout out to the responsive design that fills a big resolution really well.

by Rob Hope via One Page Love

Mathematical Modules in Python: Decimal and Fractions

Even the most basic mathematical operations can sometimes give an erroneous result. This happens due to limitations in storing the exact value of some numbers. You can overcome these limitations by using the decimal module in Python. Similarly, neither the math nor the cmath module that we learned about in our last tutorial can help us in doing fraction-based arithmetic. However, the fractions module in Python does exactly that.

In this tutorial, you will learn about both these modules and the different functions they make available. 

Why Do We Need a Decimal Module?

You are probably wondering why we need a module to do basic arithmetic with decimal numbers when we can already do the same using floats.

Before I answer this question, I want you to take a guess about the output value if you type 0.1 + 0.2 in the Python console. If you guessed that the output should be 0.3, you will be surprised when you check out the actual result, which is 0.30000000000000004. You can try some other calculation like 0.05 + 0.1 and you will get 0.15000000000000002. 

To understand what's going on here, try to represent 1/3 in decimal form, and you will notice that the number is actually non-terminating in base 10. Similarly, some numbers like 0.1 or 1/10 are non-terminating in base 2. Since these numbers still need to be represented somehow, a few approximations are made while storing them, which results in those errors.

The number 0.30000000000000004 is actually very close to 0.3, so we can get away with this approximation most of the time. Unfortunately, this approximation is not going to cut it when you are simulating a satellite launch or dealing with money. Another problem with these approximations is that the errors keep piling up. 

To get precise results like the ones we are used to dealing with when doing calculations by hand, we need something that supports fast, correctly rounded, decimal floating point arithmetic, and the decimal module does exactly that.

Using the Decimal Module

Before using the module, you need to import it first. After that, you can create decimals from integers, strings, floats, or tuples. When the decimal is constructed from an integer or a float, there is an exact conversion of the value of that number. Take a look at the examples below to see what I mean:

As you can see, the value of Decimal(0.05) is slightly different from Decimal('0.05'). This means that when you add 0.05 and 0.1, you should use decimal.Decimal('0.05') and decimal.Decimal('0.1') to construct the decimals.

Now that you can perform various operations on decimals, you might want to control the precision or rounding for those operations. This can be done by using the getcontext() function. This function allows you to get as well as set the value of the precision and rounding options, among other things. 

Please keep in mind that both rounding and precision come into play only during arithmetic operations and not while you are creating the decimals themselves.

You can also use some of the mathematical functions like sqrt(), exp(), and log() with decimals. Here are a few examples:

Using the Fractions Module

Sometimes, you might face situations where you need to perform various operations on fractions or the final result needs to be a fraction. The fractions module can be of great help in these cases. It allows you to create a Fraction instance from numbers, floats, decimals, and even strings. Just like the decimal module, there are a few issues with this module as well when it comes to creating fractions from floats. Here are a few examples:

You can also perform simple mathematical operations like addition and subtraction on fractions just like regular numbers.

The module also has a few important methods like limit_denominator(max_denominator) which will find and return a fraction closest in value to the given fraction whose denominator is at most max_denominator. You can also return the numerator of a given fraction in the lowest term by using the numerator property and the denominator by using the denominator property.

You can also use this module with various functions in the math module to perform fraction-based calculations.

Final Thoughts

These two modules should be sufficient to help you perform common operations on both decimals and fractions. As shown in the last section, you can use these modules along with the math module to calculate the value of all kinds of mathematical functions in the format you desire.

In the next tutorial of the series, you will learn about the random module in Python.


by Monty Shokeen via Envato Tuts+ Code

Ode

Ode Goods is a website that showcases and sells handcrafted sustainable jewels, created from waste material.
by via Awwwards - Sites of the day

4 Ways to Build Facebook Lookalike Audiences to Expand Your Targeting

Do you want to reach more consumers with your Facebook ads? Looking for creative ways to reach more people like your ideal customers? Lookalike audiences allow you to build new audiences using an established source audience such as people who have viewed your video or previously purchased from you. In this article, you’ll discover how [...]

This post 4 Ways to Build Facebook Lookalike Audiences to Expand Your Targeting first appeared on .
- Your Guide to the Social Media Jungle


by Charlie Lawrance via

Win Free Tickets to Social Media Marketing World 2017

Want to win a free ticket to the industry’s largest social media marketing conference of the year? Social Media Examiner has been working hard to bring you our fifth annual physical conference. And we’ve come up with a fun way for you to get involved. First, what is this event? Social Media Marketing World 2017 [...]

This post Win Free Tickets to Social Media Marketing World 2017 first appeared on .
- Your Guide to the Social Media Jungle


by Phil Mershon via

Andrea Grasso

Minimal text-only One Page portfolio for designer, Andrea Grasso. Nice little touch with the local Barcelona time in the section containing his phone number.

by Rob Hope via One Page Love