Javascript News

Syndicate content
Pipes Output
Updated: 48 weeks 6 days ago

WordPress Categories Explained

Mo, 2015-06-22 19:00

Organizing WordPress posts into different categories is essential if you have many posts. That way, your visitors (and you!) can easily search and sort your posts and only see what they want.

In this article we will look at how we can manage WordPress categories. We will begin with the description of some basic things about adding, editing or deleting a category.

Then, we will look at how to display a list of our categories, and how to customize this list, with the default widget that WordPress provides us.

Continue reading %WordPress Categories Explained%

Displaying Images on a Dot Matrix LED Display with Node.js

Mo, 2015-06-22 18:00

Dot matrix LED displays are fun. What developer wouldn't love a blank canvas of lights to play with? I recently paired up a 32 x 16 Dot Matrix Display from Freetronics with Node.js and got it to display black and white PNG images. In this article, I'll explain how it all works.

A dot matrix LED display (otherwise known just as a dot matrix display or DMD) is a display with a grid of LED lights that you can turn on and off to display text and shapes. Some of them have multiple colors, whilst others are just one single color. The one we'll use in this demo has just one color, so we're limited to black and white images. It is important to note - an LED display is quite different to an LCD display. LCDs use fancy light crystals and are used for displays on VCRs, clocks, calculators and so on. I wrote an article a few weeks ago on Displaying Web APIs on an Arduino LCD Using Node.js. Take a look at that if you'd like to compare the two.

This particular demo requires a Freetronics 32x16 Dot Matrix Display, as it relies on the Freetronics DMD library.

Demo code

If you're keen to grab the code and give it a try yourself, you can find it here on GitHub.

The Freetronics DMD Library

Drawing lines, shapes and text onto our LED dot matrix display is all done via the Freetronics DMD Library. To use it, complete the following steps:

  1. Download the DMD library from their GitHub repository.
  2. Copy those files into your /Arduino/libraries/ folder under their own folder name. For me on my Mac, I placed it inside a folder at /Users/username/Documents/Arduino/libraries/DMD-master.
  3. Download the TimerOne library and place it into your /Arduino/libraries/ folder too. e.g. For Mac users, /Users/username/Documents/Arduino/libraries/TimerOne-r11.
Our Arduino Sketch

Most of the functionality for displaying elements on our DMD will happen within our Arduino sketch code. The sketch code will keep an eye out for messages over the serial port and change the display shown based upon those messages.

The sketch begins with our includes and constants. We include SoftwareSerial.h to allow us to access the serial port and define the width and height of our DMD (32x16 in our case). BUFLENGTH stores the number of lights we've got, as this is the max size of the message we want to send our Arduino. In our case, it is 32 multiplied by 16 which is 512.

[code language="c"]
#include
#define SCREEN_WIDTH 32
#define SCREEN_HEIGHT 16
#define BUFLENGTH 512
[/code]

Next, we have our includes specific to the Freetronics DMD. These should all be available from the files we copied into our Arduino libraries folder earlier.

[code language="c"]
#include
#include
#include
[/code]

Then, we have two constants DISPLAYS_ACROSS and DISPLAYS_DOWN which are used to define how many LED displays we have joined together. I'm going to assume you are in the same situation as me and just have one display, therefore both of these are equal to one. We then pass that into our DMD library, getting it running using DMD dmd().

[code language="c"]
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
[/code]

The next bit of code is included in the DMD samples. This is the function we call to get the DMD library to refresh the display on a set interval. We define that interval a little bit further down.

[code language="c"]
void ScanDMD() {
dmd.scanDisplayBySPI();
}
[/code]

Continue reading %Displaying Images on a Dot Matrix LED Display with Node.js%

People’s Choice: Pick Your Top Books For Our #CodeTrip

Mo, 2015-06-22 17:31

Grab your favorite slurpee and get into our car, we’re heading on a #CodeTrip. We’re hitting the open road, the wind in our hair, our dog looking out the window. Endless road, bright summer sun and warm nights means the air is full of endless possibility. Web devs, it’s our time to shine. We’re feeling […]

Continue reading %People’s Choice: Pick Your Top Books For Our #CodeTrip%

Nette Framework: First Impressions

Mo, 2015-06-22 16:00

SitePoint’s PHP channel conducted its annual survey on the most popular framework of 2015 and the results were discussed here.

We saw some familiar names: Laravel, Symfony2, Phalcon, Silex, Slim, etc. But wait, what is this: Nette?

According to the survey result, it ranked number 3 in both “at Work” and “in Personal Projects”, just tailing the two giants: Laravel and Symfony2.

I had never heard of this framework before the survey results got published. A framework so popular is worth looking into. Thus, in this article, we will take a look at Nette, see what it can do and discuss some of the features.

NOTE: We will base our review on the official Getting Started tutorial.

Installation and bootstrapping

Nette uses a self-bootstrap approach (similar to Laravel) with the support of composer:

composer create-project nette/sandbox demo

This will create a demo directory in the current one, and a sandbox project will be loaded into said folder.

Nette’s Getting Started tutorial guides us through building a simple blog app which features basic blog functions like: list all posts, view an individual post, create/edit a post, comments, security etc.

Continue reading %Nette Framework: First Impressions%

How to Combine ‘Gut Feel’ & Science in Multivariate Testing

Mo, 2015-06-22 15:00

As site owners, designers, and developers we often underestimate the value of our intuition.

We prioritize data-driven decisions over instinct when it comes to virtually everything: from optimizing our monetization strategies to styling buttons on our websites. However, we often achieve better results if we learn to complement, rather than substitute our gut feeling with tests and data.

The ability to combine intuition and data-driven thinking is crucial for multivariate testing (MVT). Although site testing is viewed as a “mechanical” process, we often come up with purely intuitive ideas when choosing the features and design elements for further tests.

A typical MVT procedure includes the core stages of the scientific method: question, research, hypothesis, experiment and troubleshooting, data analysis, and implementation. You can increase the value of your ideas by using these stages as a framework for your experiment.

Running Usability Tests to Ask the Right Questions

Start your MVT experiment with the right question. In most cases, asking yourself what exactly you can improve is a good starting point.

As a rule, our intuition makes us visualize dozens of useful tweaks, but we need to concentrate on features which lead to substantial improvements. Running a usability test prior to an MVT experiment is a viable way of reinforcing intuition with concrete data. Depending on your budget you have several options to choose from:

Let’s take a look at an example:

When launching native advertising on their websites, publishers often choose full-sized ad units that mimic the structure of their posts. This way the ad gets more prominence.

However, sometimes the ad feels too large, and it is more than just an aesthetic issue. Oversized adverts of this type can erode user experience leading to a decrease of click-through rates (CTR).

Conducting a usability study will most probably confirm our guess — oversized in-feed ads tend to be the first UX-related problem users notice. An obvious solution for this problem would be to test smaller native ad units.

Using Competitor Analysis for Background Research

Conduct background research to ensure a meaningful outcome for your tests. There is a valid reason for you to use competitor analysis at this stage. This type of research often comes down to a brief review of competitor websites with top search rankings, which doesn't take much time.

Studying your competitors will help you better understand what UX solutions work for similar websites. Later on, you will determine if your own ideas work better than these solutions.

If this is the case, you will gain a competitive edge over similar online resources. If not, you will still get to understand what works best for similar websites.

Competitor analysis will add clarity to the example above as well. It's easy to see that the most widespread alternative for an in-feed ad is a compact preview of the same branded post. These previews typically appear alongside recommended content, and are styled similarly, except for minor differences. This is what an average native ad of this type would look like in the “recent articles” section:

In a number of cases, publishers mention the advertiser in an explicit manner:

Constructing a Valid Hypothesis

The hypothesis is the idea you will be testing. In fact, it is likely that your gut feeling will provide you with several worthy ideas.

In this case, you will need to find out which of them have the most practical advantages over your competitors’ features. To select the right items, give proper consideration to these three points:

  • Try to predict how your audience will react to your solution. There is plenty of information on the psychology behind different color patterns, shapes, and layouts to help you make precise forecasts.
  • Find out if you ideas correspond to the current trends and/or enable you to make use of new technologies.
  • Make sure the options you test are suitable for your site in terms of design.

Let’s see, how these points align with the above example. Background color helps the ad stand out, but it may lead some users to mistake the branded post for a banner. To avoid confusion, it will prove worthy to either opt for a less contrasting background or to completely remove it:

Continue reading %How to Combine ‘Gut Feel’ & Science in Multivariate Testing%

License to SIGKILL

Mo, 2015-06-22 14:00

[caption id="attachment_108499" align="alignleft" width="225"] Schneeman, Richard Schneeman.[/caption]

Every program wants to live forever. What happens when a program is forced to exit before it's done running, and why would we want to do that?

Unix Signals

Feel free to skip if you are familiar with signals.

In Unix, processes can communicate to each other with pre-defined signals. You can see a list of unix signals here. This ability to communicate is extremely important in a process oriented program. For example, the Puma webserver can add concurrency by spawning child "worker" processes. It accepts requests into a master process and then hands them off to the next available child. If the system that is running the Puma master process needs to shut down or restart, we don't simply want all current requests to be stopped in their tracks. Instead, we want the child workers to finish processing the request if they can, clean up any external connections or temporary files they may have generated, then exit. The system can safely do this by sending a signal to the parent "master" process which is then, in turn, sent to the child processes.

Continue reading %License to SIGKILL%

Deploying PHP apps to DigitalOcean with Dploy.io

So, 2015-06-21 16:00

In this tutorial, we’ll take a look at how to deploy a PHP application with [Dploy](http://dploy.io), a tool that’s free (and full-featured) for a single application, which makes for a perfect test case on whether or not it’s worth paying for. Before continuing, go ahead and sign up for a free account.

Specifically, we’ll deploy a simple app I made on DigitalOcean.

Configuring the Droplet

Before proceeding, we should make sure we have a DigitalOcean droplet created and configured (here’s my DigitalOcean referral link if you’d like a head start with some credits). You should also have the API key at the ready (can be obtained here).

Continue reading %Deploying PHP apps to DigitalOcean with Dploy.io%

Using MySQL with Node.js & the node-mysql JavaScript Client

Fr, 2015-06-19 18:00

NoSQL databases are all the rage these days and probably the preferred back-end for Node.js applications. But you shouldn’t architect your next project based on what’s hip and trendy, rather the type of database to be used should depend on the project’s requirements. If your project involves dynamic table creation, real time inserts etc. then NoSQL is the way to go, but on the other hand, if your project deals with complex queries and transactions, then a SQL make much more sense.

In this tutorial, we’ll have a look at getting started with the node-mysql module — a Node.js driver for MySQL, written in JavaScript. I’ll explain how to use the module to connect to a MySQL database, perform the usual CRUD operations, before examining stored procedures and escaping user input.

Installing node-mysql

node-mysql can be installed via npm. We can get up and running like so:

[code language="bash"]
mkdir sp-node-mysql
cd sp-node-mysql
npm install mysql
[/code]

If you need help using npm, then be sure to check out this article, or ask in our forums.

Getting Started

Once you are done installing node-mysql module, you are good to go. For this demo I’ll be using a database called sitepoint and a table called employees. Here’s a dump of the database, so that you can get up and running quickly, if you wish to follow along:

[code language="sql"]
CREATE TABLE employees (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(50),
location varchar(50),
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

INSERT INTO employees (id, name, location) VALUES
(1, 'Jasmine', 'Australia'),
(2, 'Jay', 'India'),
(3, 'Jim', 'Germany'),
(4, 'Lesley', 'Scotland');
[/code]

Now, let’s create a file called app.js in our sp-node-mysql directory and see how to connect to MySQL from Node.js.

app.js

[code language="js"]
var mysql = require("mysql");

// First you need to create a connection to the db
var con = mysql.createConnection({
host: "localhost",
user: "jay",
password: "jay"
});

con.connect(function(err){
if(err){
console.log('Error connecting to Db');
return;
}
console.log('Connection established');
});

con.end(function(err) {
// The connection is terminated gracefully
// Ensures all previously enqueued queries are still
// before sending a COM_QUIT packet to the MySQL server.
});
[/code]

Now open up a terminal and enter node app.js. Once the connection is successfully established you should be able to see the “Connection established” message in the console. If something goes wrong (for example you enter the wrong password), a callback is fired, which is passed an instance of the JavaScript Error object (err). Try logging this to the console to see what additional useful information it contains.

Pro Tip

If JavaScript task runners are your thing, you can watch the file app.js for changes and have the task runner execute it every time a change is detected.

Here’s how you might do that with Grunt.

package.json

[code language="js"]
{
"name": "sp-node-mysql",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-execute": "^0.2.2",
}
}
[/code]

Gruntfile.js

[code language="js"]
module.exports = function (grunt) {
grunt.initConfig({
execute: {
target: {
src: ['app.js']
}
},
watch: {
scripts: {
files: ['app.js'],
tasks: ['execute'],
},
}
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-execute');
};
[/code]

Then run npm install, followed by grunt watch.

Executing Queries Reading

Now that you know how to establish a connection to MySQL from Node.js, let’s see how to execute SQL queries. We'll start by specifying the database name (sitepoint) in the createConnection command.

[code language="js"]
var con = mysql.createConnection({
host: "localhost",
user: "jay",
password: "jay",
database: "sitepoint"
});
[/code]

Once the connection is established we’ll use the connection variable to execute a query against the database table employees.

[code language="js"]
con.query('SELECT * FROM employees',function(err,rows){
if(err) throw err;

console.log('Data received from Db:\n');
console.log(rows);
});
[/code]

When you run app.js (either using grunt-watch or by typing node app.js into your terminal), you should be able to see the data returned from database logged to the terminal.

[code language="js"]
[ { id: 1, name: 'Jasmine', location: 'Australia' },
{ id: 2, name: 'Jay', location: 'India' },
{ id: 3, name: 'Jim', location: 'Germany' },
{ id: 4, name: 'Lesley', location: 'Scotland' } ]
[/code]

Data returned from the MySQL database can be parsed by simply lopping over the rows object.

[code language="js"]
for (var i = 0; i < rows.length; i++) {
console.log(rows[i].name);
};
[/code]

Continue reading %Using MySQL with Node.js & the node-mysql JavaScript Client%

On Our Radar: Search, CSS Sliders, Reusable Code, and Responsive Sites

Fr, 2015-06-19 17:00

*knock knock* who’s there? (long pause) “Java” ;) On Our Radar SitePoint editor, writer, ambassador and all-round PHP expert Bruno finally showed us his coolest pet project yet, our very own Google, SitePoint Search. We also talk about how we feel using Discourse’s native search. What are your thoughts? The meta guys are looking into […]

Continue reading %On Our Radar: Search, CSS Sliders, Reusable Code, and Responsive Sites%

SitePoint News: We’ve partnered with UX Mastery

Do, 2015-06-18 00:58

We’re thrilled to announce our partnership with UX Mastery. This enterprising group have been educating developers worldwide about the importance of building great user experiences, and we’re pleased to welcome them as our latest publisher partner.

At SitePoint, we’re all about building incredible — and beautiful — Internet things, which should by definition be free of awkward interfaces and confusing interactions. We’ve been supportive for a long time of UX Mastery’s message that people are more important than technology, and we're proud to offer their insightful ebook range to our members.

From today, UX Mastery’s three ebooks will be available on Learnable, our online learning platform. All Learnable members will be able to access the ebooks online, and annual members will also given the option to download them. If you’re not a member yet, we suggest you join to access these great titles, as well as the extensive SitePoint library. The UX Mastery titles are also available for individual purchase through Learnable.

Developers of all backgrounds and levels of experience can gain invaluable insight into the importance of UX with these brilliant books. Welcome to the SitePoint family, UX Mastery!

Find Out More

Continue reading %SitePoint News: We’ve partnered with UX Mastery%

Why Cross-platform Literacy Matters

Mi, 2015-06-17 22:00

Users increasingly expect application experiences that take full advantage of their chosen platforms. That means developers and designers have to be as familiar with the devices they target as their users.

This article explains why cross-platform literacy matters, and describes several techniques to make switching between platforms as easy as possible.

Harnessing Platform Capabilities

When applications are created by designers and developers who aren't intimately familiar with their target platforms, it tends to show. I've spent most of my career working with cross-platform technologies, and one of the most important things I've learned is that details matter.

End users might choose their platforms based on things like social trends, financial considerations, and ecosystem investment, but they often come to love the little shortcuts, conveniences, and idiosyncrasies that make up that platform's overall experience.

An application doesn't have to take full advantage of every platform capability—especially early on; but since it's safe to assume your competition will eventually provide the best and most native-feeling user experience possible, your standards should be equally high.

Cross-platform Fluency Matters

Designing and developing for multiple platforms is tricky. It's logistically difficult since it usually requires varying skill sets, and it's expensive since it sometimes requires investment in multiple sets of hardware.

Additionally, designers and developers are every bit as passionate about their chosen platforms as their end users—frequently even more so—which can introduce both biases and blind spots into their work. But I believe that the best user experiences come from designers and developers who are completely fluent in the platforms for which they build, and that being fluent in a platform means going beyond just testing: it means spending time using that platform for real-world tasks, and genuinely learning to appreciate it despite personal preferences.

This article describes several ways in which you can make working with multiple desktop and mobile platforms on a regular basis much easier and much more efficient. While it's true that becoming intimately familiar with all the relevant platforms out there is a significant investment, it's also true that the easier you make it, the more likely you will be to maintain that experience over time—and most importantly, the more you'll learn to think like your users.

The Bad News First

Remaining digitally ambidextrous is not easy (or cheap), and in fact has proven to be a constant struggle for me over the years. That's the bad news. But the good news is that several factors have made moving back and forth between devices and operating systems easier than ever:

  • Advances in emulation technology.
  • Extremely affordable cloud services.
  • Increasingly capable and popular web-based applications.
  • And finally, the continued popularity of both iOS and Android—as well as the resurgence of Macs—requiring many software vendors to support multiple platforms in order to reach all their customers.
Even Microsoft is embracing multiple platforms with tools like OneNote. (Microsoft OneNote)

To maintain technological fluency, it's essential to spend time with the various devices and operating systems. Not only should you use them for testing, but it's also important that you be familiar with the likely applications, tasks, and workflows of your end users.

The rest of this article describes several ways you can organize and configure your digital life to this end. The aim is to incorporate as many different platforms, workflows, and design languages as possible into your applications. If you succeed, all your customers will be well served, regardless of their platform.

Hardware

The first requirement for engaging with multiple platforms is either the hardware to run them, or software solutions that provide effective emulation. The following section describes several approaches to making both mobile and desktop platforms as accessible as your budget allows.

The Computer

Let's get this out of the way from the outset: the first thing you need is a Mac. There are plenty of options for accessing Windows (which I'll cover in more detail below), but unless you want to build a Hackintosh, there's really no way around buying an iMac, Mac mini, or a MacBook. Fortunately, as a developer or a designer, there's a very good chance you already own at least one Mac, and if not, Apple has plenty of affordable low-end (but still very capable) Macs available.

Fortunately, accessing a Windows environment is much cheaper and easier. The simplest solution is to use a cloud service like Amazon WorkSpaces, Microsoft Azure RemoteApp, or VMware Horizon Air. But since performance is a critical component of a platform's overall experience, I've never been a big fan of the latency typically seen with remote desktop environments. Therefore, I would recommend running Windows as natively as possible.

It's been about a decade since Steve Jobs announced Apple's plans to migrate from PowerPC processors to Intel's x86 architecture, and not only have Macs gotten significantly faster, but running both OS X and Windows has also gotten much easier. The simplest way to have access to both operating systems is to install Windows on your Mac under emulation using tools like Parallels, VMWare's Fusion, or the freely available VirtualBox. In general, I've found that these tools have gotten easier to use, faster, and much more capable over the years.


Running Windows on a Mac with Parallels.

For a more native experience, there's always Boot Camp, which enables you to install Windows—along with a set of Windows drivers for Apple hardware—directly on a separate partition of your Mac's hard drive. The advantage of Boot Camp is you typically get excellent performance, since Windows has access to all your Mac's resources (in fact, there was a time when MacBooks were considered by many to be the best Windows laptops). However, the disadvantage is that you have to reboot into Windows, which makes rapidly testing or experimenting across environments much more time consuming.

My personal preference is to use two separate computers. In my opinion, Apple makes the best laptops, and I think the best Windows experiences are on desktop configurations. Therefore, I use a MacBook Pro for OS X, and a custom-built PC for Windows.

Mobile Devices

Mobile is where things really start getting tricky. I've learned the hard way that the established system of manufacturers, retailers, carriers, and service providers is not optimized for customers who want to own and operate multiple devices simultaneously. But with a little work (and a few good tips) it is possible.

My personal rule is to always buy my phones outright and never sign contracts or accept subsidies. Although it's very tempting to have to come up with less cash upfront, having the flexibility to swap phones or upgrade whenever you want (selling old phones to offset the cost) is critical to having access to the most recent and popular iOS and Android experiences.

But the problem with having two phones is getting them both working at the same time. The easiest thing to do is to have a single phone plan that you use with one phone, and only use the second phone when Wi-Fi is available (which is almost everywhere now). If you want to make a more permanent switch, all you have to do is transfer the SIM card. Though somewhat inconvenient, it's better than paying for two separate phone plans and trying to manage multiple phone numbers.

If you want both phones active on mobile networks at the same time, I would recommend some type of shared family plan. For example, I have an AT&T plan which allows me to share voice (which I seldom use) and data (which I use a lot) across as many devices as I want. Though I have to pay an additional $15 each month per device, it's much cheaper than having entirely separate mobile phone plans.

The biggest problem with having multiple phones active at the same time is having multiple phone numbers. The best way around this problem that I've found is to use Google Voice (a technology that appears to be one of the underpinnings of Project Fi). Google Voice enables you to have a single phone number which forwards to as many different phone numbers as you want. Additionally, you can use Hangouts on iOS and Android (and in the browser) for texting and instant messaging. However, if you want to use native messaging services like Apple's Messages app, then you're probably better off just swapping SIM cards occasionally.


Google Voice allows you to have one phone number associated with multiple phones.

Continue reading %Why Cross-platform Literacy Matters%

An Introduction to Verlet.js

Mi, 2015-06-17 20:00

verlet-js is a light-weight physics engine, authored by Sub Protocol, which you can use in your web-based games. If you are into science and engineering, you can use it in your simulations as well. As the name suggests, verlet-js is based on an iterative technique called Verlet integration used to calculate the behavior of objects in its two-dimensional world.

In this tutorial, I am going to teach you everything you need to know how to use this physics engine effectively in your projects.

Setup

To start, download the latest version of verlet-js from GitHub and include it in your web page using a script tag:

Continue reading %An Introduction to Verlet.js%

VersionPress – WordPress Meets Version Control

Mi, 2015-06-17 19:15

With the increasing popularity of version control, most developers are now accustomed to its capabilities. We have tried to extend the use of version control beyond the management of source code — like managing database dumps and designs. Therefore, it is not a surprise that the last few years have seen the application of version control to WordPress too.

Earlier this year, I published a post on Revisr, a Git plugin for WordPress. Revisr enabled you to initialize a Git repository within your WordPress source code, and also include database dumps in your backups.

Revisr is a great tool, but it’s not fit for everyone. You need to have the basic understanding of Git to be able to use the plugin seamlessly. Also, I believe that it would be difficult for beginners to handle remotes to move their backups to the cloud.

This article focuses on VersionPress, another plugin that we've previously touched on that tries to apply version control to a WordPress project. Although VersionPress uses Git, there is no mention of Git, as long as you have installed the requirements. It tracks every action that you perform on the WordPress admin panel, enabling you to undo every change, or roll back to the state of that change. One thing that struck me the most was the simplicity of the plugin — there are no unnecessary settings to divide your attention.

In my examples, I'll be using the 1.0-RC3 version of the plugin. Download the plugin, install and activate it. After activation, a new item appears on the left panel. Clicking it takes you to the second step of activation, where the plugin needs to perform a few actions before tracking changes in your WordPress site.

Continue reading %VersionPress – WordPress Meets Version Control%

Accessible Footnotes with CSS

Mi, 2015-06-17 18:00

I was playing with CSS counters the other day and thought about using them to deal with footnotes. According to Plagiarism which has a surprisingly long entry on the matter, footnotes are:

[…] notes placed at the bottom of a page. They cite references or comment on a designated part of the text above it.

You often see them in papers when the author wants to add a piece of information or cite a reference without doing it in the middle of the content or using parentheses. Usually, footnotes are represented with a number according to the position of the footnote in the document, then the same numbers are present at the bottom of the document, adding extra content.

The problem with footnotes on the web is that they can be a pain to maintain. If you happen to work on the same document often, changing the order of sections, adding references along the way, it might be tedious to have to re-number all existing footnotes. For example, if you have 3 existing references to footnotes in a document, and you want to add another one, but on a piece of content that occurs before all the others, you have to re-number them all. Not great…

We could use CSS counters to make this whole thing much easier. What if we did not have to maintain the numbering by hand and it could be done automatically? The only thing we would have to pay attention to, is that the order of the actual notes in the footer respect the order of appearance of the references in the text.

Creating a sample document

Let’s create a sample document so we can get started.

[code language="html"]

CSS-Powered Footnotes

Maintaining footnotes manually can be a pain.
By using CSS counters to add
the numbered references in the text and an ordered list to display the actual
footnotes in the footer, it becomes extremely easy.

  1. Footnotes are notes placed at the bottom of a page. They
    cite references or comment on a designated part of the text above it.
  2. Cascading Style Sheets
  3. CSS counters are, in essence, variables maintained by
    CSS whose values may be incremented by CSS rules to track how many times
    they're used.

[/code]

Our example is lightweight: we have some content in an <article> element, which contains some links (<a>) pointed at in-document IDs, mapped to the notes in the <footer> of the article.

With a few styles, it might look like this:

Making it accessible

Before actually getting onto the counters thing, we should make sure our markup is fully accessible for screen-readers. The first thing we want to do is add a title to our footer that will serve as a description or our footnote references. We’ll hide this title with CSS so it doesn’t show up visually.

[code language="html"]

Footnotes
    ...

[/code]

Then, we want to describe all our references with this title, using the aria-describedby attribute:

[code language="html"]

Maintaining footnotes
manually can be a pain. By using CSS
counters to add the
numbered references in the text and an ordered list to display the actual footnotes
in the footer, it becomes extremely easy.

[/code]

Now screen reader users will understand when links are references to footnotes.

Adding the references

I know what you’re thinking: He said there would be CSS counters. Where are the CSS counters? Well worry not, my friend, they are coming.

What we are going to do is increment a counter for every link in the document that has an aria-describedby attribute set to footnote-label. Then we’ll display the counter using the ::after pseudo-element. From there, it’s all about applying CSS styles.

Continue reading %Accessible Footnotes with CSS%

Popular Users per Language and Region with Silex and Github

Mi, 2015-06-17 16:00

The Github API V3 is a very powerful set of API endpoints that you can use to retrieve useful information about your repositories, activities, and events. Not only that, it allows you to access public information on others. The fact that it has libraries in many languages and platforms is also a big plus; it allows you to get down to writing code very fast.

The data you can get through the GitHub API V3 is mostly what you can see on the GitHub web interface, except you can use the data in your application to come to interesting conclusions. That is what we are going to do in this article.

Younes Rafie has written an article titled How to Use Github’s API with PHP, in which he introduces a lot of what we are talking about here, although in a different fashion. If you haven’t read that article, though, do not fear! We have you covered.

The Concept

As Brandon Savage notes in his article, The definitive guide to contributing to open source:

There are millions of PHP developers, but only a (large) handful of contributors, authors and maintainers of open source software. Packagist reports a little under 50,000 packages in the PHP ecosystem. This is a huge number of open source packages, but is a small number compared to the PHP developers in the world.

Now, what if there was a web service in which we could specify a location and a language (e.g. PHP) and get a sorted list of contributors to open-source? It would certainly make Brandon very happy.

Continue reading %Popular Users per Language and Region with Silex and Github%

Shelly Cloud: Deploy a Rails App in Less Than 5 Minutes

Mi, 2015-06-17 14:00

2 weeks gone, 1 app ready for production. What now? It's time to deploy the app on a server. But you're a developer, you can't be expected to know everything about managing a VPS for a Rails app. Shelly Cloud is here to help. Shelly Cloud is a hosted developer platform for deploying Ruby or Ruby on Rails apps. If you've used Heroku before, it's the same concept; just git push and you have a deployed app.

This concept is called Platform as a Service (a.k.a PaaS). In contrast to Virtual Private Server (VPS) hosting, PaaS configures the hardware and a deployment platform for you, whereas you must configure your own with a VPS. With a VPS, you must scale the application yourself. But with PaaS, this scaling is done for you as your traffic grows.

Shelly Cloud is a PaaS that does a lot for you; git-based deployment and various forms of scaling are the main ones. Shelly also includes various services (like databases) that are setup for you automatically. Sound awesome? Let's deploy an app to Shelly Cloud.

Continue reading %Shelly Cloud: Deploy a Rails App in Less Than 5 Minutes%

Build a Media Player with HTML

Di, 2015-06-16 22:00

The possibilities for media in HTML have taken off with the introduction of the video and audio elements in HTML5. Now we can embed video and audio in websites without the need for proprietary technologies like Flash or Silverlight.

With browser support better than ever, and new technologies like WebVTT starting to arrive, now is a great time to get to know (or to revisit) these new HTML elements.

Learnable has just launched Getting Started with HTML Media, a course that gets you up to speed with HTML's new media elements and how to take them to the next level with CSS and JavaScript.

Here's a video from the course that gets the ball rolling, showing you how to structure the HTML code for a custom media player. (Later videos demonstrate how to build on this with CSS and JavaScript to create a fully functioning, custom media player.)

Loading the player...

You can download the source files for this demo on GitHub.

If you found this useful, check out the full course at Learnable—which takes you from the basics right up to developing a fully functioning, custom media player, playing both audio and video.

Continue reading %Build a Media Player with HTML%

Bringing Sanity and Order to Device Testing

Di, 2015-06-16 20:00

This article is part of a web dev series from Microsoft. Thank you for supporting the partners who make SitePoint possible.

It seems like every other day the public is granted some new means of accessing the web. Some days it’s a new browser. Others it’s a new smartphone. Or a tablet. Or an e-reader. Or a video game console. Or a smartwatch. Or a TV. Or a heads-up display. Or a car. Or a refrigerator.

I worked on one project where the client provided me with a spreadsheet detailing 1,400 different user agents that accessed the login screen for the m-dot site. In two days!

As further evidence, consider the enlightening details of this post from Jason Samuels of the National Council on Family relations, a non-profit organization:

  • In 2008, visits from “mobile” devices accounted for only about 0.1% of their traffic. In 2014, that number had skyrocketed to 14.4%.
  • In 2008, they detected 71 different screen resolutions, which is already a lot to consider. By 2014, however, they were seeing 1,000 unique screen resolutions each and every quarter (with over 200 of those recording 10+ visits per quarter).

That last stat blows my mind every time I read it. You can’t design for 200 different screens, let alone 1,000. It’s a fool’s errand. And don’t even think of trying to test on that many devices.

And yet, here we are designing websites that can (and will) go anywhere. We need to thoroughly test because we can’t make any assumptions about the browsers and devices being used to access our content.

Testing can be tedious, time consuming, and costly. Surely there’s a way to make it easier. There sure is: Instead of getting hung up on creating one experience that needs to be nearly identical on every browser, we can be smarter about how we build things and treat experience as a continuum.

We can build websites that are both nimble enough to work on low powered devices over slow networks and smart enough to take advantage of advanced features and sensors when opportunity knocks.

Wha?! We can have our cake and eat it too? Yes. Yes we can.

Continue reading %Bringing Sanity and Order to Device Testing%

How 3 Modern Tools are Using Flexbox Grids

Di, 2015-06-16 18:00

There are plenty of valuable resources (articles, tutorials, and online tools) discussing the flexbox layout module. Flexbox has gained so much traction that more and more grids and frameworks are supporting this powerful layout feature.

In this article, we’ll examine how 3 tools are incorporating flexbox-based grids and I’ll show you some demos that will illustrate the features.

Note: This article expects that you have some knowledge of flexbox.

Flexbox Grid

Flexbox Grid is a grid system built on top of flexbox. If you’re familiar with Bootstrap, this grid uses the same predefined grid classes and media query breakpoints. The following table summarizes how the grid works:

Screens Viewport Size Container Width Class Prefix Extra small screens <30em (768px) auto .col-xs-* Small screens ≥48em (768px) 46rem (736px) .col-sm-* Medium screens ≥62em (992px) 61rem (976px) .col-md-* Large screens ≥75em (1200px) 71rem (1136px) .col-lg-*

To get started with Flexbox Grid, you have to install and include the required CSS file (i.e. flexboxgrid.css) in your projects. More information about this process is available on the project’s GitHub page.

Let’s now create a responsive navigation menu based on this grid. Here’s what we’re going to build:

First, we define the ul element as a flex container by assigning the row class to it. Then we use the col-xs-2 class to specify the width of the flex items. This class ensures that the list items will have a maximum width equal to 16.667% for all devices. Finally, we horizontally and vertically center our items by adding the center-xs and middle-xs classes to the flex wrapper.

Below is the required HTML:

[code language="html"]

[/code]

And here are some CSS styles to enhance the appearance of our menu:

[code language="css"]
.row {
height: 80px;
}

ul a:before {
font-family: FontAwesome;
font-size: 22px;
}

ul li:nth-child(1) a:before {
content: '\f015';
}

@media screen and (max-width: 800px) {
ul a {
font-size: 0;
}

ul a:before {
font-size: 32px;
}
}
[/code]

Note: To keep things simple, I’ve only included some of the rules from the corresponding CSS file.

See the Pen A flexible menu based on the Flexbox Grid framework. by SitePoint (@SitePoint) on CodePen.

At this point we have a new requirement. We have to add our logo to the main menu. The following screenshot shows what we want to create:

To make that work, we’ll add a bit of extra markup.

Here’s the new version of our HTML:

Continue reading %How 3 Modern Tools are Using Flexbox Grids%

Can Apps Help Prevent Violence?

Di, 2015-06-16 17:00

The notion of using a mobile phone in an emergency situation is nothing new. With an increase in technology adoption, developers have begun creating mobile phone apps which aim to target particular types of crime. This includes street based harassment of women and domestic violence. In the first of a series about apps that help in the fight against crime, this installment takes a critical look at some of the apps targeting violence against women across the world.

Apps targeting personal safety

There are many apps which are targeted at women in situations where they are feeling threatened or unsafe, particularly at night.

Continue reading %Can Apps Help Prevent Violence?%