Wednesday, February 24, 2016

Get a Year of FlipHTML5 to Create Interactive Magazines

Get a year of FlipHTML5 to create interactive magazines without coding

Nike, Staples, Xerox, IBM, Dell, Pfizer, and Pepsico are just some of the major names that trust their content with the FlipHTML5 publishing platform. Join their ranks and turn your PDFs and documents into interactive experiences. One year of access to the FlipHTML5 Platinum plan is just $9.99.

Turn your PDFs, images, and MS Office documents into digital publications, home pages, and flip books. There’s no limit to what you can do with your content—take advantage of the unlimited storage and unlimited uploads to add animations, video, audio, text, and links that create a truly immersive experience. Your readers can subscribe to get updates and share your content on social media—while you track stats like visits.

All that, without learning a single line of code. Get one year of FlipHTML5 for $9.99 at SitePoint Shop.

Continue reading %Get a Year of FlipHTML5 to Create Interactive Magazines%


by SitePoint Offers via SitePoint

How to Use Code Snippets in Atom

Snippets are regularly-used chunks of code you can quickly insert into program files. They're useful and a core feature of the Atom text editor. That said, you can use the editor for many months without realising snippets are available or appreciating their power!

Atom packages and language grammars are often supplied with pre-defined snippets. For example, start or open a new HTML file then type img and hit the Tab key. The following code appears:

[code language="html"]
<img src="" alt="" />
[/code]

and the cursor will be between the src attribute quotes. Hit Tab again and the cursor will move to the alt attribute. Hit Tab a final time to move to the end of the tag.

Continue reading %How to Use Code Snippets in Atom%


by Craig Buckler via SitePoint

The Ultimate CSS Survey: Standards and Learning

Our CSS Survey is still going strong, with nearly 6000 entries between the three parts. Last week I featured part two of the survey and provided a sneak preview into the results gleaned from part one. So let’s look at some quick tidbits from part two, which focused on CSS tools and workflow: 74% of […]

Continue reading %The Ultimate CSS Survey: Standards and Learning%


by Louis Lazaris via SitePoint

Quick Tip: How to Create and Manipulate Arrays in JavaScript

This article was peer reviewed by Chris Perry and Marcello La Rocca. Thanks to all of SitePoint's peer reviewers for making SitePoint content the best it can be!

The length property of Array objects is one that many who are relatively new to JavaScript do not understand. Many mistakenly believe that the length tells you exactly how many entries there are in an array whereas this is only true of some arrays. Some beginners do not even realize that length is a writable property of arrays. To clarify just exactly how the length property works, let's take a look at what happens when we either change its value ourselves or run something that updates the array that also results in the length changing.

[author_more]

Let's start at the beginning. A JavaScript array has a property called length and optionally has numbered properties with names between 0 and 4294967294 inclusive. It also has a number of methods for manipulating the properties some of which we will look at as a part of our examination of how the length property works. Note that JavaScript does not support associative arrays and so while you can add named properties to an array, they do not form a part of the array and will be ignored by all the array methods. They also will not affect the length.

To make it easier to show exactly what happens to the array properties as we process various statements, we will run the following function after each piece of code. This will log the length of the array and all of the numbered properties to the browser's console.

var test = function(array) {
  console.log('length:'+ array.length);
  array.forEach(function(element, index, array) {
    console.log(index + ':' + element);
  });
};

Creating an Array

We will begin by looking at different ways to create an array in JavaScript. The first two of these examples create arrays where only the length is set and there are no numbered entries at all. The second two create numbered entries from 0 to one less than the length.

An array where the length is greater than the amount of numbered properties is known as a sparse array while one with the length equal to the number of numbered properties is a dense array.

//Creates an array with no numbered entries

var arr = new Array(5);
test(arr);
// length: 5

var arr = [];
arr.length = 5;
test(arr);
// length: 5

Note that the array literal notation (where you define a new array using just empty brackets) is preferred when creating new arrays.

var arr = ['a', 'b', 'c', 'd', 'e'];
test(arr);
// length:5, 0:a, 1:b, 2:c, 3:d, 4:e

var arr = [undefined, undefined, undefined, undefined, undefined];
test(arr);
// length:5, 0:undefined, 1:undefined, 2:undefined, 3:undefined, 4:undefined

The array methods that process the numbered properties (forEach in our case) will only process those that exist. If you instead process the array using a for or while loop then the loop will also attempt to process those properties that don't exist and the array will identify those entries that don't exist as being undefined. Your code would then be unable to distinguish between the last of the above examples and the first two. You should always use the array methods for processing an array where you are not certain that you are dealing with a dense array.

Changing the Length

The following examples look at what happens if we set a new length for the array that is less than the current length.

var arr = ['a', 'b', 'c', 'd', 'e', 'f'];
test(arr);
// length:6, 0:a, 1:b, 2:c, 3:d, 4:e, 5:f

var arr.length = 5;
test(arr);
// length:5, 0:a, 1:b, 2:c, 3:d, 4:e

var arr = ['a','b','c','d','e','f',,,];
test(arr);
// length:8, 0:a, 1:b, 2:c, 3:d, 4:e, 5:f

var arr.length = 7;
test(arr);
// length:7, 0:a, 1:b, 2:c, 3:d, 4:e, 5:f

Note that when creating an array using [] notation each entry consists of a value followed by a comma. Where the value is omitted then no property is created for that position. The last comma may only be omitted if there is a value supplied for that property as otherwise the length will be reduced by one.

Continue reading %Quick Tip: How to Create and Manipulate Arrays in JavaScript%


by Stephen Chapman via SitePoint

This Week's HTML5 and Browser Technology News (Issue 228)


Read this e-mail on the Web
HTML 5 Weekly
Issue 228 — February 24, 2016
Geoff Graham
Did you know you can link to telephone numbers from HTML? You can, but the behavior varies depending on the context.


A Book Apart
One of the most significant books in the HTML5 space has been majorly updated after five years. Jeffrey Zeldman’s foreword explains more.


GitHub
GitHub.com no longer delivers its icons via an icon font - it has switched to SVG. Here’s a look at the why and how.


Imgix  Sponsored
Imgix is a real-time image processing service and CDN. Our new libraries enable you to implement lightboxes and zoom viewers without having to create multiple copies of the image, while also delivering it at high quality and speed, to every device or browser.

Imgix

Robin Rendle
A beautifully presented essay that makes some proposals for typography’s role on the modern Web.


Tommy Hodgins and Maxime Euzière
A plugin that lets you write element queries inside CSS. These let you define CSS against the state of individual elements rather than the browser viewport.


Google Design
An interactive viewer to see and test how digital products respond to material design breakpoints across desktop, mobile, and tablet.


Joshua Jenkins
See how each HTML5 form element natively looks on your OS and browser.


Smashing Magazine
Links to several articles and tools you should check out if you want to get started with learning about the flexible box layout module.


SitePoint
Now that Microsoft has ended support for old versions of IE, maybe it’s time to give your tools, code and processes a spring clean?


Jobs

In brief

Curated by Peter Cooper and published by Cooper Press.
Want to post a job? E-mail us or use our self-serve system.

Unsubscribe : Change email address : Read this issue on the Web

Published by Cooper Press Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via HTML5 Weekly

Websockets in Your Synchronous Site

I’m always yammering on about writing asynchronous PHP code, and for a reason. I think it’s healthy to get fresh perspectives - to be exposed to new programming paradigms.

Asynchronous architecture is common in other programming languages, but it’s only just finding its feet in PHP. The trouble is that this new architecture comes with a cost.

I don’t talk about that cost enough.

When I recommend frameworks like Icicle, ReactPHP, and AMPHP, the obvious place to start with them is to create something new. If you have an existing site (perhaps running through Apache or Nginx), adding daemonised PHP services to your app is probably not as easy as just starting over.

Abstract image of data streaming in parallel

It takes a lot of work to integrate new, asynchronous features into existing applications. Often there are good reasons and great benefits, but a rewrite is always a hard-sell. Perhaps you can get some of the benefits of parallel execution without using an event loop. Perhaps you can get some of the benefits of web sockets without a new architecture.

I’m going to show you a Sockets-as-a-Service service, called Socketize. Try saying that a few times, out loud…

Note: Web sockets involve a fair amount of JavaScript. Fortunately, we don’t need to set up any complicated build chains. You can find the example code for this tutorial here.

Setup!

Let’s set up a simple CRUD example. Download the SQL script, and import it to a local database. Then let’s create a JSON endpoint:

$action = "/get";
$actions = ["/get"];

if (isset($_SERVER["PATH_INFO"])) {
    if (in_array($_SERVER["PATH_INFO"], $actions)) {
        $action = $_SERVER["PATH_INFO"];
    }
}

$db = new PDO(
    "mysql:host=localhost;dbname=[your_database_name];charset=utf8",
    "[your_database_username]",
    "[your_database_password]"
);

function respond($data) {
    header("Content-type: application/json");
    print json_encode($data) and exit;
}

This code will decide whether a request is being made against a valid endpoint (currently only supporting /get). We also establish a connection to the database, and define a method for allowing us to respond to the browser with minimal effort.

Continue reading %Websockets in Your Synchronous Site%


by Christopher Pitt via SitePoint

Popular Open Source Projects for Swift Developments

On December 3 2015, Apple officially open sourced the Swift programming language. By open sourcing the entire programming language, Apple has now allowed developers from all over the world to contribute to the language and assist in its development and evolution. In addition to this, the Swift programming language can now be used in environments outside of Apple's platforms, such as Linux.

In this article, I am going to be telling you about some of the most popular and interesting projects that utilize Swift and will, over time, evolve alongside the language itself.

1. Foundation

If you have done any iOS programming before, especially using Objective-C, you are probably familiar with classes such as NSDate, NSArray, NSString, and NSURL. These classes are all part of the Foundation framework, which is available on every Apple platform (iOS, OS X, tvOS, and watchOS).

The basic functionality the Foundation APIs provide, however, is also being reimplemented as a Swift Core Library by Apple in order to be portable across platforms. This project can be found at Apple's swift-corelibs-foundation repository at GitHub.

Numerous other developers are actively working to bring the Foundation APIs to Swift in a portable cross-platform way. The most popular of these projects is SwiftFoundation which, at the time of writing this article, has many key differentiators from Apple's implementation.

More Functionality

It provides more functionality. As the project's README notes, many methods in Apple's Foundation project are marked with NSUnimplemented(), meaning that only basic functionality is currently available.

Portability

From the very beginning, it has been designed with portability in mind. Unlike Apple's Foundation core library, SwiftFoundation doesn't rely on the CoreFoundation APIs written in C. This allows for SwiftFoundation to more easily support a wider range of platforms in the future.

Protocol-Oriented

SwiftFoundation has been entirely designed and developed using a protocol-oriented structure rather than the more traditional object-oriented programming style. Doing so offers a range of benefits, which you can learn more about in this tutorial.

More importantly, it completely modernizes the 20+ year old Foundation APIs. Apple could eventually do something like this with their Foundation core library but the README of their repository states the following.

In our first year, we are not looking to make major API changes to the library. We feel that this will hamper the primary goal [of portability outside of Apple platforms].

Both of these projects are actively being updated and will definitely become crucial in the future of Swift development as they allow for basic functions, such as networking, getting/manipulating dates/times, and persistent local storage on any platform supported by the Swift language.

2. Other Core Libraries

In addition to Foundation, Apple is also redeveloping from the ground up two other major libraries to be used with Swift on other platforms: XCTest and libdispatch (also known as Grand Central Dispatch). While these projects aren't quite as popular or have the same scale as Foundation, they are still very important when it comes to Swift development.

The XCTest project is designed to allow developers to create unit tests for their Swift code. If you aren't familiar with unit tests, then take a look at this article to learn more about them. While in its very early stages with only basic tests being supported, the XCTest project will, over time, become very important to all Swift developers when testing and debugging their code.

The libdispatch project allows for concurrent (multithreaded) workflows when running on supported hardware. This is particularly important for actions, such as network requests, so that the main thread doesn't get blocked by other operations.

While both of these repos are owned and maintained by Apple, like Swift, they have been open sourced to encourage developer input. I encourage you to have a look at them, even if it's only out of interest to look at the implementation of the APIs. There's a lot you can learn from browsing the source code.

3. Web Servers & Websites

One of the most exciting possibilities of open sourcing Swift is the ability to use it as the primary programming language for server backends and websites. While HTML and CSS will remain the standards for the web in terms of presenting content to the user, once Swift and its libraries are mature and functional enough, Swift could be used in almost any situation where currently other languages, such as PHP and JavaScript, are used.

This is particularly exciting for Cocoa developers because the skills and knowledge they have already gained by using Swift for frontend development will then greatly assist them if they want to do backend development.

There are many projects that are all working to bring Swift to the web, including Vapor, Zewo, and Caramel. The most advanced and feature-packed of these projects, however, is Perfect.

Perfect encompasses many different Swift components, which each have their own unique purpose.

  • PerfectLib contains the networking APIs and utilities needed by both the client and server, including simplified HTTP request handling, JSON parsing, and other data management.
  • Perfect Server runs on server-side and handles accepting connections, processing requests, and returning responses. A server utilizing Perfect Server can use either FastCGI or stand-alone HTTP.
  • Various connectors that allow a server to extend its functionality and work with other APIs, including mod_perfect for FastCGI connectivity with Apache 2.4 and MySQL, PostgreSQL, and MongoDB for working with these types of databases.

When combined, these components allow for a fully functional web server, which would work exactly the same as a traditional server powered by PHP or JavaScript would. The possibilities of web servers running Swift is very exciting and projects, such as Perfect, are paving the way for the day Swift can be used for virtually every component of a project.

4. Swift Package Manager

If you take a look at the repositories mentioned earlier in this article, you will notice that some of them, in their root directory, have a file called Package.swift. Projects that contain this file do so in order to be used with the Swift Package Manager.

The Swift Package Manager is a dependency management system that is similar to CocoaPods and Carthage, enabling developers to link to third party libraries and use them in their own projects.

This package manager is being developed so that any platform using Swift can link to and import code in the exact same manner, rather than relying on a platform-specific solution. The Swift Package Manager is still in it's early development stages with many specifications subject to change. But it is aimed to be finalized and released alongside Swift 3.

If you'd like to take a closer look at this project and learn how to utilize it in your own code, then I recommend visiting the project's page on Swift.org or the repository on GitHub.

5. Miscellaneous Utilities

In addition to the aforementioned open source Swift projects, there are also many others that are very interesting and unique.

XCGlogger

This project is aimed at logging. It enables developers to print a lot more detail to the system console without having to write a whole bunch of extra code. This logging utility allows you to automatically log a variety of attributes, including thread name, source code file name, line number, and current scope method.

Swiftline

The goal of this project is to create command line applications with Swift. These applications support user interaction in the form of both regular keyboard input as well as multiple choice.

Swiftline would be particularly useful in an educational environment as students could use it to develop a fully functional and interactive application without needing to worry about any sort of user interface.

Swift Algorithm Club

This repository contains a wide array of useful algorithms all for use in Swift code. This includes things, such as fixed size arrays, hash tables, and shuffling. The repository contains a full list of all the currently supported algorithms.

Swift AI

Swift AI is an artificial intelligence project focussing on machine learning. The example project included in the repository shows how the AI system can learn to replicate a basic sine function.

Note that this project is currently only supported on iOS and OS X due to its dependency on Apple's Accelerate framework, which allows for improved performance when executing large calculations.

Conclusion

There are so many new and exciting open source Swift projects out there, which, over time, will develop and influence the careers of many developers. As you can see, by open sourcing Swift, Apple has not only allowed the language to become better through community contributions, but also to become useful when developing for platforms other than Apple's.

I encourage you to check out some of the projects mentioned in this article and look at what they are trying to achieve. If you want to look at even more projects, then I recommend browsing GitHub for the most popular and currently trending Swift repositories.

As always, leave your comments and feedback in the comments below.


by Davis Allie via Envato Tuts+ Code