Javascript News

Syndicate content
Pipes Output
Updated: 15 hours 11 min ago

LevelDB in Ruby

Mi, 2014-10-22 14:00

Typically when you set out with a Rails application, your data lives inside a MySQL (or PostgreSQL, or SQLite, or Oracle) database. But, it turns out that the traditional relational database is not a great fit for all types of data. For example, if you want very fast access to data that isn't flushed to disk all that often, you could hold that information in RAM. In this case, you might want Redis or Memcached. If your data can be represented as a graph, you'll want to check out Neo4j or OrientDB. But sometimes, you don't want or need a full-blown database server; instead, you can make do with a simple library that can be packaged along with your app. This is where LevelDB fits in: it is a key-value storage library that's meant to be fast.

In this article, we'll cover how to use LevelDB with a Ruby wrapper and also discuss where you should and shouldn't use LevelDB by presenting common usecases.

Continue reading %LevelDB in Ruby%

Debugging Sass Maps

Di, 2014-10-21 18:30

Maps are great, but maps are not that easy to debug. When you have simple maps, it's usually quite easy to understand what's going on, but when you work with huge and/or nested, possibly dynamically updated maps, it can get difficult to keep track of what happens.

...and then, all of a sudden, a bug appears somewhere in your code. Breaking the site you're developing somehow.

However, fear not my friends, I have a possible solution.

What about inspect() or @debug?

The other day, web developer Stuart Trann asked how we could debug a map to see what it looks like.

The first thing that came to my mind was the inspect() function. This function was added at pretty much the same time when maps came out, in order to inspect the content of a map.

You may have noticed that if you try to display a map as a CSS value, you get this message:

(sass: map) isn't a valid CSS value.

Dang. So that's why the inspect() function has been implemented to Sass core. So you can see something like:

[code language="sass"] test { inspect: (sass: map); } [/code]

A problem with inspect() is that it displays the map as a single line, which is far from convenient, especially when you have loads of keys in there. One could think of @debug, which intends to print some content in the console but that really doesn't help much since it also keeps it to one line.

Time to build something that helps us folks.

Continue reading %Debugging Sass Maps%

Building a Pull-Quote Custom Element with Polymer

Di, 2014-10-21 18:00

Custom elements allow developers to define their own HTML elements with custom tag names that closely resemble their design components. The W3C defines custom elements as the specification that:

Enables authors to define and use new types of DOM elements in a document.

The definition looks quite simple in theory, but in practice the process of creating and using a custom element involves:

  1. A decent amount of JavaScript
  2. Knowledge of the JavaScript API(s) to create the custom element
  3. Handling cross-browser inconsistencies.

If you manage to survive through these challenges, then you still have to worry about those browsers that do not support custom elements. Thankfully, Polymer saves the day by providing an easy-to-use framework to create and use custom elements.

If you need a quick refresher on Polymer and Web components then I would strongly recommend reading my previous article on Sitepoint that introduces these concepts in depth.

In this article, we will take a very basic example of creating a custom element with Polymer to render pull quotes. The idea originated from this article by Louis Lazaris where he sparked a debate on the semantic value of using blockquote vs aside to create pull quotes in your markup.

It’s fairly common to see blockquote, aside, or even a plain div element being used to mark up pull quotes. It’s time we put an end to this conundrum by creating a new custom element called <pull-quote> that can accurately represent our content. By the end of this article you will be able to create something like this:

Setting Up the Custom Element

Before we begin with our custom element, we will quickly set up the project folder by installing Polymer and all the dependencies via Bower.

[code language="bash"] $ bower install --save Polymer/polymer [/code]

Typically, creating a new custom element involves the following steps:

  1. Create an HTML file with the name of the custom element.
  2. Import the polymer.html file from the bower_components folder using <link>.
  3. Declare your custom element using <polymer-element>.
  4. Add the styles and the markup needed to define your custom element using the <template> tag.
  5. If your custom element involves JavaScript, call the Polymer() constructor to register the element in the DOM.

The basic approach is to first decide how you are going to use the custom element in your markup and then work your way backwards to create the template for the custom element. In this case, we plan to use the following markup every time we intend to use pull quotes in our document:

[code language="html"] Sample text and can even contain other HTML tags. [/code]

We’ll start by creating a file called pull-quote.html in the root directory. Edit the file and import the polymer.html file that can be found in the bower_components folder:

Continue reading %Building a Pull-Quote Custom Element with Polymer%

Creating a Note Taking App with React and Flux

Di, 2014-10-21 18:00

React, by Facebook, is a very nice library for creating user interfaces. The only problem is that React doesn't care how your application handles the data. Most people use React as the V in MV*. So, Facebook introduced a pattern called Flux which brings a functional approach to data handling inside an app. This tutorial gives a brief introduction on the Flux pattern and shows how to create a note taking app using React and Flux architecture.

A Primer on Flux

Flux relies on unidirectional data flow. We have two key components in the Flux pattern:

  1. Stores : A store component, as the name suggests, stores the application data.
  2. Actions : New data flows into the stores through actions. Stores listen to actions and do some tasks (e.g. modify data) when actions are invoked. This keeps the data flow unidirectional.

To reinforce the concept let's take a real world example. For example, in a note making app you can have the following arrangement:

  1. A store called NoteStore which stores a list of notes.
  2. You can have an action called createNote. The store NoteStore listens to the action createNote and updates its list with a new note whenever the action is invoked. Data flows into the store only through actions.
  3. The NoteStore triggers an event whenever its data changes. Your React component, say NoteListComponent, listens to this event and updates the list of notes presented on the view. This is how the data flows out of the store.

So, the data flow can be visualised as following :

The biggest advantage of the Flux pattern is that it keeps your application data flat. As mutation can be done only through actions, it's easier to understand how the data change affects the whole application.

Note:

If you have gone through Facebook's guide to Flux, you might have noticed the concept of a Dispatcher. A Dispatcher is a registry of callbacks into the stores. When an action is invoked, the Dispatcher responds to it and sends the associated data to all the registered stores. Stores then check the action type and perform tasks accordingly.

The above process has been greatly simplified by a library called Reflux . It removes the concept of Dispatchers by making the actions listenable. So, in Reflux stores can directly listen to actions and respond to their invocation.

To understand the Flux pattern fully let's build a simple note taking app with Reflux, React, and Node.js.

Continue reading %Creating a Note Taking App with React and Flux%

Continuous Delivery: The Right Way to Deploy Your Software

Di, 2014-10-21 17:00

How do you deploy your web site or application to your live server? Does this describe your process?…

  1. get a copy of the latest codebase
  2. add, edit and remove code as necessary
  3. test the update
  4. copy all/changed files to the server using FTP
  5. rinse and repeat
It's a simple work-flow used by many developers. A proportion of those will also manage updates without source control such as Git or SVN. The process may be adequate for small projects with infrequent updates. Unfortunately, it breaks down the moment your site or application reaches any level of complexity.

Continue reading %Continuous Delivery: The Right Way to Deploy Your Software%

Treasure! Free Mobile Design Resources

Di, 2014-10-21 16:30

Being a designer usually requires staying in the know of resources that you could use to get better at your craft as well as resources you could use in your work.

At SitePoint, there have been previous articles that point you to the best web design resources on the net. This article will focus on mobile design resources. It will focus on free resources, that I’ve grouped into three broad categories - education, inspiration and assets to use in your work. If you are a mobile designer(or any other designer, as the resources are relevant to other areas as well) I hope you find the links helpful.

Education UX Design for Mobile Developers

UX Design for Mobile Developers is course on Udacity that teaches the techniques and best practices used to create great user experiences. It is aimed at developers looking to pick up some design knowledge, to help them build well-designed as well as well-built apps, but programming experience is not required to benefit from the design principles in the course.

The course is free to watch but if you want one-on-one help from a coach as well as review of your designs, you will have to pay a fee.

This is a great start in learning UX design for mobile design. Even though the course is taught with Android in mind, the principles apply for any mobile platform.

User Experience Design for Developers

This is a show on the Android Developers YouTube channel where Google developer Nazmul Idris, who also teaches the Udacity course mentioned previously, teaches mobile UX design.

Aimed at the beginner, it shows you design principles and best practices that go into crafting great UX designs.

Android Design in Action

Android Design in Action is a show on the Android Developers YouTube channel where Google designers Nick Butcher, Adam Koch and Roman Nurik discuss various elements of Android Design.

In each episode, they look at various apps and tear-down their UI and UX design, explaining what works and what doesn’t. After this discussion of the app’s design, they present a new design of the same app and explain the decisions that went into the design process. If you are a mobile designer, especially an Android designer, then you will pick up gems of good design practices, design patterns and inspiration for your projects.

Hack Design

Hack Design is a website that offers design education to anyone looking to fill the gap in their design knowledge. It comprises of blogs, books, videos, games and tutorials curated by several top designers in the industry, organized into 50 lessons. You are emailed one lessons a week, but you can also consume them as you want by visiting the website.

It’s not targeted at mobile designers specifically, but it does contain some lessons in mobile design; and besides, whatever branch of design you choose, you still have to learn the basics - elements and principles of design, and Hack Design is a great place to start.

Inspiration

The following resources provide a place where you can find inspiration for your designs. In the creative process, it usually helps to look at other people’s work, see what works and what doesn’t, explore design patterns and see the different ways they have been used so that you can get an idea of what to try out in your design. You can learn a lot from observing what others have done, and the following websites have done a great job collecting various app designs in a central place for easy browsing.

CAPPTIVATE.co

Capptivate is a mobile pattern library that goes further than just showing screenshots of iOS apps. It shows five-second videos of apps and their transitions and animations. The videos are activated by a mouse over and the apps are categorised by either the design patterns(e.g. navigation, loading, pull to refresh) or the type of motion(e.g. fade, parallax, ripple).

If you are looking for ways to add animations and transitions to your app’s UI that will delight its users, then this is a great place to get some ideas.

Android Niceties

Android Niceties hosts a collection of screenshots of some of the most beautiful looking Android apps. You can view different screens of each app, and get an insight into Android UI conventions.

Mobile Patterns

Mobile Patterns hosts a collection of screenshots of both iOS and Android apps. You have the option of viewing UIs from both platforms or filtering out one. You can also view screens that are particular to a category such as sign up flows, splash screens, timelines, galleries, e.t.c.

Since it hosts UI design for both Android and iOS, this can be a great place to learn the design patterns and conventions for both platforms.

Pttrns

Pttrns displays a collection of mobile patterns for both iPhone and iPad. You can filter the patterns according to different categories such as launch screens, profiles, comments, lists, empty states, e.t.c.

This is another great place to look for inspiration.

Continue reading %Treasure! Free Mobile Design Resources%

11 of the Best WordPress Author Bio Plugins

Mo, 2014-10-20 19:00

These days, an author biography is so much more than an online trend, especially on multi-author websites. In fact, in researching this article, I couldn’t find a single example of resistance to author bios. Apparently, having solid author bio on your WordPress website is a must. Regardless of what industry you’re in, an author bio […]

Continue reading %11 of the Best WordPress Author Bio Plugins%

Preparing for ECMAScript 6: New Number Methods

Mo, 2014-10-20 18:00

In this series about the new features of ECMAScript 6, we've discussed about new methods available for the String and Array data types, but also new types of data like Map and WeakMap. In this article I'm going to introduce you to the new methods and constant added to the Number data type. Some of the methods covered, as we'll see, aren't new at all but they have been improved and/or moved under the right object (for example isNaN()). As always, we'll also put the new knowledge acquired into action with some examples. So, without further ado, let's start. Number.isInteger() The first method I want to cover is Number.isInteger(). It's a new addition in JavaScript and this is something you may have defined and used by yourself in the past. It determines whether the value passed to the function is an integer or not. This method returns true if the passed value is an integer, and false otherwise. The implementation of this method was pretty easy but it's still good to have it natively. One of the possible solutions to recreate this function is: [js] Number.isInteger = Number.isInteger || function (number) { return typeof number === 'number' && number % 1 === 0; }; [/js] For my fun, I tried to recreate this function and I ended up with a different approach: [js] Number.isInteger = Number.isInteger || function (number) { return typeof number === 'number' && Math.floor(number) === number; }; [/js] Both these functions are good and useful but they don't respect the ECMAScript 6 specifications. So, if you want to polyfill this method you need something a little bit more complex as we'll see in a few moments. For the moment, let's start by discovering the syntax of Number.isInteger(): [js] Number.isInteger(number) [/js] The number argument represents the value you want to test. Some examples of use of this method are shown below: [js] // prints "true" console.log(Number.isInteger(19)); // prints "false" console.log(Number.isInteger(3.5)); // prints "false" console.log(Number.isInteger([1, 2, 3])); [/js] A live demo of the previous code is shown below and also available as a JSFiddle. The method is supported by almost any modern browser and specifically by Firefox, Chrome, Opera, and Safari. If you want to support Internet Explorer and some other browsers, you need a polyfill. One that you can employ is available on the Mozilla Developer Network at the method's page and also reported below for your convenience: [js] if (!Number.isInteger) { Number.isInteger = function isInteger (nVal) { return typeof nVal === "number" && isFinite(nVal) && nVal > -9007199254740992 && nVal < 9007199254740992 && Math.floor(nVal) === nVal; }; } [/js]

Continue reading %Preparing for ECMAScript 6: New Number Methods%

A Standing Desk Might Not (Necessarily) Save Your Life

Mo, 2014-10-20 17:15

A couple of years ago I found myself unable to work effectively, with constant screaming headaches and stiff necks. It turned out this was due to my working at an inappropriate workspace — my dining table and a terrible chair — with a screen that was too low. Fortunately, I rarely have these issues anymore […]

Continue reading %A Standing Desk Might Not (Necessarily) Save Your Life%

Create an Icon Font Using Illustrator & Icomoon

Mo, 2014-10-20 16:30

Creating a web icons font with Illustrator and Icomoon

photo credit: listentoreason

An icon system can often become central design element in your web project. You can find a lot of free or commercial icon sets on the web, and they are often included in major CSS frameworks (Bootstrap 3 Glyphicons, is a perfect example).

Sometimes, however, you may need a specific glyphs not included in a generic set. Or you may just want to better coordinate the design of your icons with the other design elements of your project. In these cases you’ll need to draw a new icon set from scratch.

There are two widely-used methods to add a set of icons to your projects:

  1. Web font
  2. SVG

Today I’m going to cover web fonts. We’ll cover the use of SVG in another article.

Traditionally classic font creation had been a difficult and demanding task, but thankfully building icon font sets , has become considerably easier than it once was thanks to easy online tools such as Icomoon, Fontastic, or Fontello. Each allows you to build a font from either ‘cherry-picking’ pre-built icons from public libraries, or by uploading SVG files you’ve prepared yourself.

BYO Icons

To build your own font, the first step is to draw icons – we will use Illustrator for this task – and then save them as SVG.

Find your design style

Before you start drawing, you need to define style properties for your glyphs such as stroke sizes, grid proportions and so on.

Begin by doing some readability test at different sizes and build a template you will use to draw all your glyphs. It’s no use designing finely-detailed icons that don’t work at lower resolutions.

It’s also very useful to sketch your font before drawing, also a very rough sketch (like the one below) will help you to find ideas for all the symbols you need.

You can then to decide the grid size for your glyph: my tip is to not draw directly at your target size (for example 16x16px) as well as at very big sizes. I’ve found that a square of 60-80px side is often good for me. Scaling up or down from this size is generally successful.

Of course, this is not a ‘set-in-stone’ type rule: project needs and experience will change on a case by case basis.

For this article, I chose to draw my icons with a stroke of 8px, without fill and set inside a grid of 64x64px.

Starting drawing

Illustrator artboards are very useful for this job: you can draw each glyph in a different artboard, keeping each in a single file. The artboards can be rearranged, renamed and can be exported as standalone SVG files (which is precisely what we need for Icomoon).

Each artboard can also have independent axis coordinates, that will be very valuable for objects alignment, as we will see later.

We can now start creating a new 64x64px Illustrator document:

Note that you can start create all the artboards you need using the Number of Artboards option: I prefer to add artboards as I need them, but there is no reason why you can’t create all your artboards first.

Continue reading %Create an Icon Font Using Illustrator & Icomoon%

Drupal 8 Hooks and the Symfony Event Dispatcher

Mo, 2014-10-20 16:00

With the incorporation of many Symfony components into Drupal in its 8th version, we are seeing a shift away from many Drupalisms towards more modern PHP architectural decisions. For example, the both loved and hated hook system is getting slowly replaced. Plugins and annotations are taking away much of the need for info hooks and the Symfony Event Dispatcher component is replacing some of the invoked hooks. Although they remain strong in Drupal 8, it’s very possible that with Drupal 9 (or maybe 10) hooks will be completely removed.

In this article we are going to primarily look at how the Symfony Event Dispatcher component works in Drupal. Additionally, we will see also how to invoke and then implement a hook in Drupal 8 to achieve similar goals as with the former.

To follow along or to get quickly started, you can find all the code we work with here in this repository. You can just install the module and you are good to go. The version of Drupal 8 used is the first BETA release so it’s preferable to use that one to ensure compatibility. Alpha 15 should also work just fine. Let’s dive in.

What is the Event Dispatcher component?

A very good definition of the Event Dispatcher component can be found on the Symfony website:

The EventDispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them.

I recommend reading up on that documentation to better understand the principles behind the event dispatcher. You will get a good introduction to how it works in Symfony so we will not cover that here. Rather, we will see an example of how you can use it in Drupal 8.

Continue reading %Drupal 8 Hooks and the Symfony Event Dispatcher%

12 Tips for Naming Your Startup

Mo, 2014-10-20 15:30

Recently, I published a roundup of some effective tools to help you name your startup. Tools can be a great help but there is definitely a sense of satisfaction in doing it on your own. Below are a few ideas that will help you brainstorm a new brand name! A good brand name can be […]

Continue reading %12 Tips for Naming Your Startup%

Automatically Reload All the Things with Guard

Mo, 2014-10-20 14:00

It's a brisk afternoon at the office and you've been slaving away at a front end project for the last twelve hours. You've repeatedly had to go through the whole save-compile-reload phase with your browser. And when I say compile, I mean compile those SCSS and CoffeeScript files that you so desperately wanted with a series of painstaking shell commands. "I'm a Rubyist!", you shout, "there has to be a better way!". Well, there is. Allow me to introduce you to Guard, your new favorite Ruby gem for the front end.

What is Guard?

Guard is simply a file system watcher. In other words, it detects when you save a file, then runs a command. It's a little more complex than that, but we'll cover that next.

Continue reading %Automatically Reload All the Things with Guard%

Book Review: Practical Design Patterns in PHP

Sa, 2014-10-18 16:00

This review of Brandon Savage’s Practical Design Patterns in PHP will include my own opinions and impressions about both the book, and the aspect of self-publishing.

Design patterns are about common solutions to common problems.
… they are concepts, not blueprints; ideas, not finished designs.
… they add clarity to an otherwise difficult situation.
- Brandon Savage, Practical Design Patterns in PHP

Content

Starting out on a lighter, introductory note, Brandon explains the need for frameworks, argues that OOP doesn’t mean just wrapping stuff in classes, and goes into detail on why design patterns appear to be difficult to learn. He then continues with a mild introduction into SOLID principles, and lays the groundwork for more advanced concepts. He explains why each SOLID rule is important and what it means. Given that SOLID is a well established software design principle, it’s only natural to compare it against every pattern that’s about to be explained in the book. Or, to be more precise, to assess how well each pattern respects the SOLID principles, while providing the developer with its intended functionality.

If I express matters in Dreyfus model terminology, he claims the book is there to turn a novice into a competent level developer without subjecting them to advanced beginner mistakes when, in fact, such an approach to learning is not entirely possible - that’s just not how the human knowledge acquisition process works.

Continue reading %Book Review: Practical Design Patterns in PHP%

Integrating a CAPTCHA with the WordPress Login Form

Fr, 2014-10-17 19:00

In a previous tutorial, we took a deep dive into WordPress HTTP API and I promised to show us how APIs can be consumed via the HTTP API in a WordPress plugin.

We've seen a plugin example of how to use the HTTP API during the course of building a Domain WHOIS and Social Data WordPress Widget and in today's tutorial, we will write a plugin that integrates a CAPTCHA with the WordPress login system, using Google's reCAPTCHA. And of course, the HTTP API will be used to send a POST request to reCAPTCHA to validate the user's answer to the CAPTCHA challenge.

Below is a screenshot of the default WordPress login form protected by a CAPTCHA on activation of the plugin to be developed at the end of this tutorial.

Plugin Development

Before we begin coding the plugin, head over to reCAPTCHA, register your domain name and grab your public and private API keys.

Continue reading %Integrating a CAPTCHA with the WordPress Login Form%

7 JavaScript Libraries for Specific Visualizations

Fr, 2014-10-17 18:00

Apart from the usual charts and graphs libraries used to create interactive data visualizations already covered here, which can present a steep learning curve as a price for their powerful versatility, there are many less known JavaScript libraries that specifically address a visualization type. They come very handy when you deal with illustrating content from data journalism with an interactive experience. Here are a few of them to start with.

JSPlumb

JSPlumb helps you visually connect elements: flowcharts, kitchen sinks, state machines, and hierarchical charts. It uses SVG where available and VML on IE8 and below, as it is compatible down to IE6. Its different implementations support animation and drag and drop features, which may need specific plugins. Its code is compatible with jQuery, MooTools, and YUI, and can also be used in vanilla JavaScript. This free library is available on GitHub.

Its four main concepts are anchors (specific location), endpoints (visual representation of connections ends, attached to anchors), connectors (visual representation of the line that connects two elements), and overlays (connector decoration, like an arrow or a label). With these four elements only, you are ready to go.

JS Sequence Diagrams

JS Sequence Diagrams turns text into vector UML sequence diagrams. It depends on both Raphaël and Underscore.js, and the result can be downloaded in SVG or even saved as a plain image if the interactive side of it is not needed (like creating diagrams on the fly through user input).

Two different themes are available: straight lines and rectangles for a neat professional look, and hand-drawn lines and written text for a fresh napkin look and feel. The text input represents a UML sequence diagram with processes linked by arrows. The examples are self-explaining with such an understandable syntax. A text input sample is shown below.

[code] Title: Here is a title A->B: Normal line B-->C: Dashed line C->>D: Open arrow D-->>A: Dashed open arrow [/code]

Continue reading %7 JavaScript Libraries for Specific Visualizations%

On Our Radar This Week: Rubygems and Reasons to Love Angular

Fr, 2014-10-17 17:00

Welcome to On Our Radar, a weekly round-up of news, trends and other cool stuff from the world of web development.

Microsoft was in the news again this week, as it's CEO suffered a bout of foot-in-mouth during an on-stage conversation at the Celebration of Women in Computing conference (for which he subsequently apologized). Pundits also asked if Windows 10 will address the operating system's biggest weakness, whilst Project Spark came out of beta and we learned that Microsoft has taught Cortana to speak Klingon. buy' ngop

Elsewhere, Google officially unveiled its newest Nexus tablet device in the form of the Nexus 9 — an 8.9-inch device which will arrive running Android 5.0 Lollipop. Too much Google Glass landed one man in treatment for Internet addiction and it was revealed that Google's ‘biggest search competitor' is Amazon (somewhere, a Bing executive is crying).

Drones were also in the news as the Dronecode project was launched by the Linux Foundation. Drone racing seems to have become a thing and reports came in of Drones taking selfies to new heights (remember: a selfie taken by a drone is a dronie). One site asked "What would you do if you discovered a drone hovering over your property?" As shooting them down is very probably illegal, your garden hose might be your best bet here …

RubyGems

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem").

If you've ever wanted to create your own gem from scratch, this two part tutorial will walk you through the process and give you a bunch of handy tips along the way.

Recently, the Ruby Rogues interviewed Eric Hodel, one of the RubyGems developers.

Justin Weiss is a developer who has been digging into Ruby gems. Firstly, he explained how gems work, before examining how Rails (a gem itself) handles gems.

Here's a fantastic list of gems for Ruby on Rails code optimization and clean up, as well as a gem to facilitate interacting with the Hacker News API.

In other Ruby news, Sandi Metz expounded on the shape of code, whilst it was put forward that object-oriented programming is an expensive disaster which must end.

Continue reading %On Our Radar This Week: Rubygems and Reasons to Love Angular%

The Reality of Blogging

Fr, 2014-10-17 16:45

When blogging first became popular in the late 1990s, many people thought that they would be able to make a comfortable living sharing their thoughts with the world. Those at the top in the blogging arena, as with any profession, can make significant amounts of money. But before you quit your day job you should […]

Continue reading %The Reality of Blogging%

Content Research (or How to Tell If Your Content is Broken)

Fr, 2014-10-17 16:30

How well is your content working?

In the age of data-worship, most site owners answer that question by turning to their site analytics package. Pageviews, bounces, conversions, goals – these are the vital statistics by which most assess their content’s health.

But if you publish or manage content in almost any form – from a simple sales website to a full-blown digital publication like SitePoint – sooner or later you’ll want more information than this.

Much more.

You don’t just want to know what works to achieve an end-goal. You want to understand how users are actually using the content you’re providing.

I found this recently with a support site I write and manage. I didn’t want to know about ad conversions or video shares and leave it at that.

What I wanted to know were things like:

  • Were those print buttons we put on each help article a waste of space?
  • Did people think the presenters in our videos were entertaining, friendly, professional, or annoying?
  • How much of each article were people reading?

My questions didn’t stop with the digital experience, though. Content research, I’ve found, is the ultimate can of worms. The more you know, the more you want to know.

Soon I found myself asking what role our content played in the bigger picture of problem-solving that our users face as they use our software. What were the gaps – and how could we best help to fill them? And so on (and on).

These kinds of questions can easily be recast for other content-heavy sites, where you want to know if people make it to the end of the content, if they feel good about your stuff, and if, dare I say it, their lives are enriched or made easier somehow by what your site offers.

Your analytics package won’t tell you all that. This is where content research comes in.

What is content research? [caption id="attachment_92715" align="alignright" width="320"] Photo: gregorywass[/caption]

When I first had these problems, I didn’t know the answer to that question. All I knew was that I had content – most of which I hadn’t created – and I wanted to understand more about how that content actually worked for users.

So I needed to research my content. Simple, right?!

Well, sort of.

There is a plethora of tools and techniques out there, so you’ll want to pick the right tool for the job. The good news is that there’s probably more than one capable tool for any one job. The bad news is that if you use that tool poorly, you’ll get low-quality information – and possibly even be completely mislead by it.

So, put simply, content research is the process of finding out the best answers you can to the questions you have about how your content works for the people who are using it.

It’s about digging deeper than the stats we all know and love to ask non-standard questions in ways that enable you to understand, trust, and act on the answers you get.

Why would you do it?

From where I’m standing, having embarked on the content research path, it’s easy to see the benefits. For me, the question is, “Why wouldn’t you do it?”

Continue reading %Content Research (or How to Tell If Your Content is Broken)%

PHP and RabbitMQ: Advanced Examples

Fr, 2014-10-17 16:00

In part 1 we covered the theory and a simple use case of the AMQP protocol in PHP with RabbitMQ as the broker. Now, let’s dive into some more advanced examples.

Example 1: send request to process data asynchronously among several workers

In the example of the previous part, we had one producer, one consumer. If the consumer died, messages would continue to stack up in the queue until the consumer started again. It would then process all the messages, one by one.

This can be less than ideal in a concurrent user environment with a fair amount of requests per minute. Fortunately, scaling the consumers is super easy, but let’s implement another example.

Let’s say we have an invoice generation service, where the users just need to provide the invoice number, and the system will automatically generate a pdf file and email it to the user. Generating and sending the email could take even several seconds if the server on which the generation process runs is resource limited. Now suppose we are required to support several transactions per second, how do we accomplish this without overwhelming the server?

We need to implement the following pattern:

Let’s look at our producer class:

<?php namespace Acme\AmqpWrapper; use PhpAmqpLib\Connection\AMQPConnection; use PhpAmqpLib\Message\AMQPMessage; class WorkerSender { /* ... SOME OTHER CODE HERE ... */ /** * Sends an invoice generation task to the workers * * @param int $invoiceNum */ public function execute($invoiceNum) { $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare( 'invoice_queue', #queue - Queue names may be up to 255 bytes of UTF-8 characters false, #passive - can use this to check whether an exchange exists without modifying the server state true, #durable, make sure that RabbitMQ will never lose our queue if a crash occurs - the queue will survive a broker restart false, #exclusive - used by only one connection and the queue will be deleted when that connection closes false #auto delete - queue is deleted when last consumer unsubscribes ); $msg = new AMQPMessage( $invoiceNum, array('delivery_mode' => 2) # make message persistent, so it is not lost if server crashes or quits ); $channel->basic_publish( $msg, #message '', #exchange 'invoice_queue' #routing key (queue) ); $channel->close(); $connection->close(); } }

The WorkerSender::execute() method will receive an invoice number. Next we create a connection, channel and queue as usual.

Continue reading %PHP and RabbitMQ: Advanced Examples%