Managing Cronjobs with Laravel

There are times when your application needs to run administrative tasks periodically on the server. Whether you want to send out emails to your users or clean up the database tables at the end of the day, you will need a task scheduling mechanism to take care of the tasks, when it’s time.

Cron is a task scheduler software in unix-like systems, which runs shell commands at certain intervals. This article is not meant for introducing Cron, but since it is a key concept in our discussion, we’ll will describe how it works in short.

A clock

Cron basics

Cron is a task scheduler daemon which runs scheduled tasks at certain intervals. Cron uses a configuration file called crontab, also known as cron table, to manage the scheduling process.

Crontab contains cronjobs, each related to a specific task. Cron jobs are composed of two parts, the cron expression, and a shell command to be run:

* * * * * command/to/run

Each field in the above expression (* * * * *) is an option for setting the schedule frequency. It is composed of minute, hour, day of month, month and day of week in order of the placement. The asterisk symbol refers to all possible values for the respective field. As a result, the above cron job will be run every minute in the day.

The following cron job is executed at 12:30 every day:

30 12 * * * command/to/run

This is just the tip of the Cron iceberg; to learn more about it, you might want to visit the wikipedia page.

In PHP powered applications, administrative tasks are normally standalone PHP scripts which are run in CLI mode. These scripts are written for performing different jobs at certain times.

However, we can’t do much without the power of other PHP libraries and frameworks. In this article, you will learn how to use the Laravel framework to create robust PHP scripts for the command line and schedule them right from the source code.

Creating Commands in Laravel

Creating a command in PHP is as simple as creating a PHP script, then running it in the command line, using the php command:

php somefile.php

As you can see, the file is passed as an argument to the command php.

Whether your application has been developed in Laravel, or you just want to use its facades and helpers to create your scripts, you will need to bootstrap Laravel before using it. However, there’s a better alternative to this: creating a Laravel Artisan command.

When using Artisan commands, we will have access to all features of Laravel, including helpers, facades, and other Artisan commands, just to name a few.

We’re not going to go into the details of Artisan commands here, as they’re beyond the scope of this tutorial, but let’s discuss the basics, just to get started. We’ll will be using the latest version of Laravel, which is 5.1 at the time of writing this article.

We use the make:console Artisan command to generate a command class skeleton to work with. As an example, we’re going to create a command which sends a happy birthday SMS message to our users on their birthday.

Continue reading %Managing Cronjobs with Laravel%


Source: Sitepoint

How to Build an AR Android App with Vuforia and Unity

Virtual and Augmented Reality has been getting a lot of attention lately. Lots of really cool Head Mounted Devices (HMDs) like Oculus, Hololens, HTC Vive, FOVE, and Magic Leap have been coming up. The simplest and cheapest of all these HMDs is Google Cardboard, and it already has more than a million users worldwide.

Google Cardboard

Patrick has covered Building Google Cardboard VR Apps in Unity in his recent post. In the following two tutorials, we will be developing a basic Android Augmented Reality application for Google Cardboard using Unity3D. We will be using Qualcomm’s Augmented Reality SDK named “Vuforia” to make this app.

The following software and the corresponding versions will be used in the following two posts:

  • Vuforia 5
  • Unity 3D 5.x
  • Cardboard SDK version 0.5.x (needed for next tutorial)
  • Android Studio and SDK tools (these need to be installed and set up for Unity builds to work. More information about this can be found in the “Integrating with Unity” section.)

Brief Overview

There are several approaches to making Augmented Reality apps. We will be using a marker based approach for making our AR app for mobile devices. In the next tutorial, we will be adding cardboard support.

Marker/Image Target – this is an image which is recognized and tracked by a mobile device’s camera. This acts as an origin for augmentation. Once recognized, content can be displayed with respect to it.

This tutorial will broadly have three parts:

  1. Getting Started with Vuforia
  2. Integrating with Unity
  3. Demo (Fun part)

Continue reading %How to Build an AR Android App with Vuforia and Unity%


Source: Sitepoint

4 Expert Tips for Getting the Most Out of Google Fonts

Google fonts has been with us for almost five years now. If you work with web front-ends, there is every chance that you have used the service in at least one of the websites that you developed.

While the licensing costs have remained zero, the font library has steadily grown in both number and quality, with Google handling both the copyright and infrastructure issues at once. What’s more, implementing Google fonts requires minimal work on your part as Google’s magic servers handle many of the trickier issues we used to have to manage ourselves.

We probably take it for granted, but it’s easy to forget how difficult, hacky and expensive it used to be to use custom typography on your site. Read up on ‘sIFR‘ if you want a quick reminder of what we used to go through.

Having access to such a useful resource, it makes sense to get the most out of it. In this article, I’d like to discuss four tips that you can follow to use Google fonts like a pro.

Tip #1: Request Multiple Fonts in a Single Request

Using different fonts in heading and paragraph text can often improve readability. However, we also know that requesting many small files from a server is significantly slower that requesting one large file.

So, instead of requesting each font separately, it’s advantageous to combine those multiple font requests into one. As an example, let’s say you wish to load two fonts — Lato and Raleway. The proper way to load the fonts would be:

<link href='https://fonts.googleapis.com/css?family=Lato|Raleway' rel='stylesheet' type='text/css'>

Though this does not reduce the total bits requested, the number of HTTP requests is reduced, which can significantly improve page load time. The more fonts you have, the bigger the saving – though there are good aesthetic reasons for limiting the number you use.

Additionally, the code is more concise and readable. You only need to look at one line to understand all the fonts that your webpage is requesting.

Specifying Font Styles and Script Subsets

There are times when you may want the italic or bold version of a font. In situations like these you can specify the font style using i and b respectively after the font name separated by a :. Here is an example:

<link href='https://fonts.googleapis.com/css?family=Lato:i|Raleway:b' rel='stylesheet' type='text/css'>

You can also use bi to load a bold italic font style if available.

If you want a different variation of a bold font you can use a numerical weight. Raleway, for example, has four versions of bold with weight 600,700,800 and 900. To request the ultra bold font you need to write:

<link href='https://fonts.googleapis.com/css?family=Raleway:900' rel='stylesheet' type='text/css'>

If you are not comfortable with the abbreviations you can also specify the full name for a font style, as I’ve done in the next example:

<link href='https://fonts.googleapis.com/css?family=Lato:300italic' rel='stylesheet' type='text/css'>

In this case, instead of loading a normal italic font, we are loading the light version.

Some fonts in the directory support multiple scripts like Latin and Greek. One example of such a font is Roboto Mono. To request the Greek subset of the font you can use the following URL:

<link href='https://fonts.googleapis.com/css?family=Roboto+Mono&subset=greek' rel='stylesheet' type='text/css'>

Optimizations

In specific situations, you might need to use only a strictly limited set of characters from a given font. This may also be the case when you only require the digits from a given font.

In cases like this, it’s simple to reduce the request size by cherry-picking the specific characters we need by using thetext= value in your font URL. This way Google will return the version of the font file you requested optimized for your specific needs. This can dramatically reduce the file-size of the font that is supplied.

Consider the following example:

<link href='https://fonts.googleapis.com/css?family=Raleway&text=SitePoint' rel='stylesheet' type='text/css'>

Instead of loading the complete Raleway font file, we only load the characters we need for ‘SitePoint’. This reduces the request size and, as a result, the webpage loads a little more quickly. These optimizations can add up and have a significant impact on the overall load time of a webpage. Keep in mind that you need to URL-encode the value of text.

Continue reading %4 Expert Tips for Getting the Most Out of Google Fonts%


Source: Sitepoint

What’s in Your Wallet? Handling iOS Passbook with Ruby

Passbook (called “Wallet” starting in iOS 9) is an built-in iOS application that provides a way for users to store and access “passes”. Consider a pass as a digital token for something, such as event tickets, membership cards, discount coupons, boarding passes, etc. Passes can be added to passbook by mail, messages, an app, etc.

A pass has many benefits for the user. For example, say a user has added a pass for a movie ticket that starts at 10.00 A.M.. That pass will be displayed on the home screen when the even draws near the user to access it directly. If a membership pass with some discount for Store X has been added, it would be displayed whenever the user walks in to Store X.

Passes are also beneficial to pass providers. For one, a pass can be used as a means of notification whenever there is some change regarding the information. Examples are a movie is canceled or boarding pass is changed, or the providers wants to give an extra discount for pass holders. All of this is possible with the use of passes.

Today, we’re going to see how to build an iOS passbook backend that handles pass generation and push notifications. I am going to use Ruby and Sinatra for it. Let’s get started.

Continue reading %What’s in Your Wallet? Handling iOS Passbook with Ruby%


Source: Sitepoint

Dealing With Loud And Silent Burnout


  

Many of us struggle silently with mental health problems and many more are affected by them, either directly or indirectly. It’s {Geek} Mental Help Week and we would like to help raise awareness with a couple of articles exploring these issues. – Ed.

We’ve all experienced that burnout moment. It’s that moment when we’ve got nothing left to give but keep trying anyway, when we’re left without much more than a shell to live in and motions to go through.

Dealing With Loud And Silent Burnout

We’re fried and broken and wish desperately for our work to make sense, for our energy to come back, for things to be fun and as they were. In such moments all we want is for our work to feel like our work and not like torture.

The post Dealing With Loud And Silent Burnout appeared first on Smashing Magazine.


Source: Smashing Magazine

Guide To Using WebP Images Today: A Case Study


  

They say a picture is worth a thousand words. But online, a picture can be worth a thousand kilobytes or more! HTTP Archive shows that images make up 64% of a web page’s total size on average. Given this, image optimization is key, especially considering that many users will abandon a request if it doesn’t load within a few seconds.

WebP Images And Performance

The problem with image optimization is that we want to keep file sizes small without sacrificing quality. Past attempts to create file types that optimize images better than the standard JPEG, PNG and GIF formats have been unsuccessful.

The post Guide To Using WebP Images Today: A Case Study appeared first on Smashing Magazine.


Source: Smashing Magazine

Freebie: Halloween Icon Set (19 Icons, AI, EPS, PDF, SVG, PNG)


  

Halloween is just around the corner, and it’s time to add a few scary and fun icons to your projects. Today, we’re happy to release the Halloween Icon Set, a set of 19 icons that are all available in AI, EPS, PDF, SVG and PNG formats. This icon set was designed and created by Manuela Langella and is free to be used in private as well as commercial projects.

Freebie: Halloween Icon Set (19 Icons, AI, EPS, PDF, SVG, PNG)

You may modify the size, color or shape of the icons. No attribution is required, however, reselling of bundles or individual pictograms isn’t cool. Please note that this icon set is available under a Creative Commons Attribution 3.0 Unported license. We’d kindly like to ask you to provide credits to the creator and link to this article if you would like to spread the word about the freebie.

The post Freebie: Halloween Icon Set (19 Icons, AI, EPS, PDF, SVG, PNG) appeared first on Smashing Magazine.


Source: Smashing Magazine

Make a Voice-Controlled Audio Player with the Web Speech API

The Web Speech API is a JavaScript API that enables web developers to incorporate speech recognition and synthesis into their web pages.

There are many reasons to do this. For example, to enhance the experience of people with disabilities (particularly users with sight problems, or users with limited ability to move their hands), or to allows users to interact with a web app while performing a different task (such as driving).

If you have never heard of the Web Speech API, or you would like a quick primer, then it might be a good idea to read Aurelio De Rosa’s articles Introducing the Web Speech API, Speech Sythesis API and the Talking Form .

Browser Support

[author_more]

Browsers vendors have only recently started implementing both the Speech Recognition API and the Speech Synthesis API. As you can see, support for these is still far from perfect, so if you are following along with this tutorial, please use an appropriate browser.

In addition, the speech recognition API currently requires an Internet connection, as the speech gets passed through the wire and the results are returned to the browser. If the connection uses HTTP, the user has to permit a site to use their microphone on every request. If the connection uses HTTPS, then this is only necessary once.

Speech Recognition Libraries

Libraries can help us manage complexity and can ensure we stay forward compatible. For example when another browser starts supporting the Speech Recognition API, we would not have to worry about adding vendor prefixes.

One such library is Annyang, which is incredibly easy to work with. Tell me more.

To initialize Annyang, we add their script to our website:

<script src="https//dvcs.w3.org//cdnjs.cloudflare.com/ajax/libs/annyang/1.6.0/annyang.min.js"></script>

We can check if the API is supported like so:

if (annyang) { /*logic */ }

And add commands using an object with the command names as keys and the callbacks as methods. :

var commands = {
  'show divs': function() {
    $('div').show();
  },
  'show forms': function() {
    $("form").show();
  }
};

Finally, we just add them and start the speech recognition using:

annyang.addCommands(commands);
annyang.start();

Voice-controlled Audio Player

In this article, we will be building a voice-controlled audio player. We will be using both the Speech Synthesis API (to inform users which song is beginning, or that a command was not recognized) and the Speech Recognition API (to convert voice commands to strings which will trigger different app logic).

The great thing about an audio player that uses the Web Speech API is that users will be able to surf to other pages in their browser or minimize the browser and do something else while still being able to switch between songs. If we have a lot of songs in the playlist, we could even request a particular song without searching for it manually (if we know its name or singer, of course).

We will not be relying on a third-party library for the speech recognition as we want to show how to work with the API without adding extra dependencies in our projects. The voice-controlled audio player will only be supporting browsers that support the interimResults attribute. The latest version of Chrome should be a safe bet.

As ever, you can find the complete code on GitHub, and a demo on CodePen.

Getting Started — a Playlist

Let’s start with a static playlist. It consists of an object with different songs in an array. Each song is a new object containing the path to the file, the singer’s name and the name of the song:

var data = {
  "songs": [
    {
      "fileName": "https://www.ruse-problem.org/songs/RunningWaters.mp3",
      "singer" : "Jason Shaw",
      "songName" : "Running Waters"
    },
    ...

We should be able to add a new objects to the songs array and have the new song automatically included into our audio player.

The Audio Player

Now we come to the player itself. This will be an object containing the following things:

  • some setup data
  • methods pertaining to the UI (e.g. populating the list of songs)
  • methods pertaining to the Speech API (e.g. recognizing and processing commands)
  • methods pertaining to the manipulation of audio (e.g. play, pause, stop, prev, next)

Setup Data

This is relatively straight forward.

var audioPlayer = {
  audioData: {
    currentSong: -1,
    songs: []
  },

The currentSong property refers to the index of the song that the user is currently on. This is useful, for example, when we have to play the next/previous song, or stop/pause the song.

The songs array contains all the songs that the user has listened to. This means that the next time the user listens to the same song, we can load it from the array and not have to download it.

You can see the full code here.

Continue reading %Make a Voice-Controlled Audio Player with the Web Speech API%


Source: Sitepoint

HTTP/2: the Pros, the Cons, and What You Need to Know

Every time you visit a web page, your browser fetches it by requesting all the assets of the page from a web server. Since the birth of the web, this has mostly been done via HTTP/1.1.

As time has passed, and technology has evolved, and websites have become ever more complex and asset-heavy, the HTTP/1.1 protocol has increasingly come under strain, with a lot of workarounds needed for dealing with performance issues.

developers at work

Web pages, as we know them today, are often stuffed with resources—such as images, text, fonts, etc.—which make them much heavier than those of the 1990s or even 2000s. Accordingly, it takes more time for them to load, so web designers and developers have come up with nifty workarounds to duck the issue. Still, it has become obvious that there’s a need for an update to the HTTP protocol itself.

HTTP/2 will bring some changes to the way pages are delivered to the browser. While ordinary Internet users might not see a big difference, designers and web developers will notice quite some. This article will look at what those changes are, and how they will affect you as a proficient tech user.

How HTTP/1 Works

To fetch the web page you’d like to visit, your browser communicates with the server. They interchange messages—the browser requesting the images, fonts and other resources needed with separate requests, and the server, in its turn, sending them as responses.

As a result, the flood of data through many connections causes congestion, and the page load speed slows down. To overcome the problem of too many requests being sent, and to make the best use of HTTP/1, inventive developers have used inlining, concatenation and image spriting. Fortunately for them, puzzling over the speed of performance will largely be a thing of the past when HTTP/2 comes.

developers at work

How HTTP/2 Will Work

Your browser will still send requests to a server and get responses with the assets needed for the web page to look as it should, but some nuances in between will change. HTTP/2 brings new features such as multiplexed streams, server push, header compression and binary format—each of which I’ll examine in turn.

Multiplexed Streams

Remember the congestions caused by many connections passing the resources such as text, fonts and pictures from the server to your browser? Multiplexing eliminates this problem by making those assets into smaller parts, passing them all via one connection, and then reassembling the resources after they’ve reached the final destination, the browser.

Server Push

Server push represents a more efficient way to deliver assets to a browser. In an HTTP/1 environment, the HTML page is sent to the browser, the browser has to parse it and decide what assets it might need, then request those assets from the server.

HTTP/2 is more proactive in this regard, sending assets that the browser is likely to need without it having to ask. These assets go to the browser’s cache, and are available immediately if and when they’re needed, which is a plus for performance.

Header Compression

In HTTP/1, every request sent has a small piece of additional data attached—HTTP headers—that describe how a browser or a server behaves. On average, browsers are able to make about six connections at once, but given that the number of connections needed to load a typical web page can be up around 100, this leaves a lot of data to be retrieved, which takes time and bandwidth.

When an HTTP/2 connection is established, all the headers are packed into one compressed block to be sent as a unity. It gets across faster, and when the transmission is finished, the header block is decoded.

Binary Instead of Textual Format

The textual format has some extra overhead and needs to be refined, while the binary one does not need any parsing. It’s also a lot more compact. Additional work of a server means additional time to wait for the web page to be loaded. That is why the binary format, with its being easier to process, is a justified enhancement.

Continue reading %HTTP/2: the Pros, the Cons, and What You Need to Know%


Source: Sitepoint

Watch: Understanding Android and Java

Android development uses the popular Java programming language. In this video we look at the basics of Java and the additions that Android brings to it.

Loading the player…

jwplayer(“video-5822”).setup({
image: “https://d3rj1gznkm47xj.cloudfront.net/c8fd927c-a6a0-4582-a2ac-c5ff94ac7805.png”,
sources: [
{
file: “https://d3rj1gznkm47xj.cloudfront.net/6a9714e9460a8ec47c4216f11198a150.mp4”,
label: “SD”
},
{
file: “https://d3rj1gznkm47xj.cloudfront.net/545fbb75d8b639c1003e4ecab585480c.mp4”,
label: “HD”
},
],
tracks: [
{
file: “http://djdvv9xnh2mt5.cloudfront.net/78e2aee2-ca2a-4f08-9210-95567c451c03.srt”,
“default”: true
}
],
aspectratio: “16:9”,
width: “100%”,
height: “480px”,
fallback: true,
primary: “flash”,
streaming: false,
analytics: {
enabled: false,
cookies: false
},
captions: {
back: false,
fontsize: 12
},
advertising: {
client: “googima”,
schedule: {
“myAds”: {
“offset”: “pre”,
“tag”: “https://pubads.g.doubleclick.net/gampad/ads?sz=855x483u0026iu=/7448792/Videou0026cust_params=[post_id]%3Dstaging%26channel%3D[channel]u0026impl=su0026gdfp_req=1u0026env=vpu0026output=xml_vast2u0026unviewed_position_start=1u0026url=[url]/u0026description_url=[description_url]u0026correlator=[timestamp]”
}
}
}
});

Continue reading %Watch: Understanding Android and Java%


Source: Sitepoint