Javascript News

Syndicate content
Pipes Output
Updated: 2 hours 28 min ago

Simple Ergonomics Tips for Desk Jockeys

4 hours 33 min ago

Human bodies are an ingenious but strange design solution. Not fast by animal standards, but we cover the ground well. We have above-average vision, good climbing abilities and excellent fine motor skills.

One thing we're actually not very well designed for is sitting.

In fact, one 2012 study suggests sitting for extended periods is more damaging to your health than smoking.

A hundred years ago, this wasn't so much of a problem. Most of us spent our days rivetting ships, toiling in fields or striding a delivery route.

Unfortunately, as desk jockeys and code monkeys, we spend most of our waking hours in front of a computer by necessity.

Comfortability is very subjective, but there are some more or less universal ergonomics rules how to arrange your work environment to reduce trauma and increase productivity. Firstly, what is Ergonomics?

Ergonomics is a relatively modern term – it was first used in 1949. It comes from the Green "ergon," (work) and "nomoi" (natural laws). Ergonomics is essentially usability, so it should naturally resonate with designers.

According to the definition in the Merriam Webster dictionary:

  • ergonomics: a science that deals with designing and arranging things so that people can use them easily and safely
  • ergonomics: the parts or qualities of something's design that make it easy to use

The purpose of ergonomics is to increase your productivity and to keep your health. In some countries, legislation makes it mandatory for employers to ensure ergonomics in the workplace, but this isn't the case everywhere.

Continue reading %Simple Ergonomics Tips for Desk Jockeys%

jQuery 1.11.1 RC1 and 2.1.1 RC1 Released

Fr, 2014-04-18 19:30

Spring has sprung, and these release candidates for jQuery 1.11.1 and 2.1.1 are in full bloom. You know what that means? It’s time to get serious about testing! We really want our next release to be solid and reliable, and to do that we need your help. Please try out these files in your projects and pages, just a quick test would be appreciated. If you unearth any problems, let us know at

The beta files are located on the jQuery CDN, you can include them directly from the CDN if you like (but don’t use them in production!). As always, the 1.x branch includes support for IE 6/7/8 and the 2.x branch does not:

Here are the bugs fixed since the last official release (1.11.0 and 2.1.0):

Common to jQuery 1.11.1 RC1 and 2.1.1 RC1 Ajax Attributes Build Core Css Dimensions Event Misc jQuery 1.11.1 RC1 Css jQuery 2.1.1 RC1 Ajax Attributes Core Css Event Manipulation Selector

A Review of the Brackets Editor

Fr, 2014-04-18 19:00

This article is going to take a look at Brackets, an open-sourced editor originally developed by Adobe. It may not have had quite the same level of publicity and hype as Atom, GitHub's new lightweight editor, but it's a promising option for the front end developer. Target Audience It's worth pointing out that Brackets is primarily aimed at front end developers and web designers. Although it's essentially a text editor and therefore suitable for coding pretty much anything, it's optimized for HTML, CSS, and JS (as well as derivatives such as SASS, Less, CoffeeScript, and so on). Ruby, Python, PHP developers, and the like might be better served looking elsewhere, whether that be for a fully-fledged IDE or something more lightweight such as Sublime or, indeed, Atom. What Makes Brackets Different? Brackets makes a big deal of the fact that it's written using a combination of HTML, CSS, and JavaScript. While this may mean little for the casual user, those who wish to extend - or even hack it - have the opportunity to do so using technologies they're probably already familiar with. The fact that it's open-sourced also makes it stand out from the crowd. Sublime, for example, is a commercial product, while Atom is closed-source and won't be free forever. Getting Brackets Brackets can be downloaded from the website, and is available for Mac OSX, Windows, and Linux (32 or 64-bit). For the purposes of this review, I'm running the 37th "sprint", on Mac OSX. First Steps When you open Brackets for the first time, you're thrown straight into an HTML-based tutorial file with accompanying CSS, which is a great way to start exploring. The left-hand column lists the working files, and beneath that is a folder view. It's like Sublime in that you can view a file with one click without actually opening it. A double-click opens the file for editing, adding it to the working files list. The right-hand column contains icons for opening Live Preview (which we'll look at shortly) and for the Extension Manager. Many third-party extensions create their own icons and place them in this bar, so it can quickly become an invaluable launchpad. A Quick Feature Tour Let's look at some of the key features of Brackets. Live Preview The Live Preview feature launches a new Chrome window showing the current page that not only doesn't require a manual refresh when you change a file, but also as you type. It's essentially Chrome's Web Inspector, but with all the benefits of a self-contained editor. It's a truly great feature, particularly if you have a splt-screen setup. It doesn't just work with HTML files, either. If you make a change to a linked CSS file which impacts the current page, that too gets reflected immediately in the browser. If you're editing a CSS file used by the currently visible page, highlighting rules causes the preview to highlight elements which are affected by them. Quick Edit The Quick Edit feature is context-specific. Let's look at a few of its uses. CSS When you're editing HTML, if you click a tag with a corresponding CSS declaration situated in a linked file and hit Ctrl / Command + E, an inline editor appears allowing you to quickly edit that rule. This is probably best illustrated with the following screenshot.

Continue reading %A Review of the Brackets Editor%

6 Online Document and Text Editors Reviewed

Fr, 2014-04-18 18:00

Who wants to limit himself to one computer nowadays? Say hello to online editors, where you can login in anywhere you want and start (or continue where you left off) right away. And some of these editors come pretty close to advanced text editors like MS Word. In this article I will show you what’s around.


This is the one I am using right now. StackEdit is a very easy to work with editor (the tool) for making documents in Markdown format, which my editor (the person) prefers. Markdown separates style and content, and with the right plugin allows for effortless copying into your favorite CMS.

You can connect StackEdit to Google Drive or Dropbox, and use auto-sync as a backup. And, you can publish from within StackEdit to WordPress, Tumblr, Github etc. You can also use it for making PDFs, which is a nice addition.

It uses shortcuts via a GUI, offers advanced settings for templating, and (very important) is really convenient when you have an unreliable connection because of its offline functionality. Also, you don’t need to register and you can start working right away.

The only downside of StackEdit is that it doesn’t have an integrated spell checker that works properly. It underlines misspelled words, but relies on your browser for correcting. But this is a known issue they are working on so we may see an improvement some day.

In the end it’s a great product, not only for the Markdown format but for general use as well. And I love the way it displays the final article on the right and if you scroll either of the two views, the other view will follow to scroll to the correct place as well.


Markable is another MarkDown editor, but this one is more suited for those who still prefer to code in Notepad. It offers a very clean interface, but there are no shortcuts, so unless you are familiar with the Markdown syntax you might want to use their cheat sheet or have another cheat sheet handy. It does allow you to see the results of your work on the right of your screen.

Continue reading %6 Online Document and Text Editors Reviewed%

A Look at Valentina

Fr, 2014-04-18 16:00

Valentina is a set of tools including: Valentina DB (a new SQL database server), Valentina Studio (a database management tool), Valentina Report (a GUI to create reports to be used in an application like PHP) and a related development toolkit (called ADK).

In this article, we will take a look at:

  • How to use Valentina Studio to manage our MySQL database;
  • How to use Valentina Report to create a presentable report.

We will not, however, discuss the the Valentina Database as it is impossible to grasp a new database server and cover its underlying mechanisms in such a short article.

Valentina Studio

Valentina Studio, the database management tool, has two versions. One is free and can be downloaded here. Another is the Pro version, with more features, priced at $200 per unit. Both versions support Windows, Mac and Linux platforms, making it a cross-platform tool.

In this article, I will use Valentina Studio Pro. Thanks to Valentina for providing me with a key for my installation and evaluation.

The startup speed of Valentina Studio is fast, faster than another tool that I am using. Its main interface has 3 panes:

Fig. 1 The welcoming window

  • Servers: Provides CS based database management. It supports four types of “servers”: MySQL, PostgreSQL, Valentina and ODBC. It supports both local server and remote server connections. In my case, we can see there are two remote MySQL connections and one local connection. A red dot before the connection (or “Bookmark” in Valentina’s term) means the server is currently down. A green dot means it is up and running.
  • Database: Supports files based database management. Currently it supports Valentina DB and SQLite.
  • Projects: This is mainly used in report generation. A “report” generated by Valentina can reside locally and remotely. But it must have Valentina Report Server support (bundled with Valentina Server) to be called from an application. The report project manages the source, query and design of a report. We will cover this later.

After selecting a server, the databases in that server will be displayed in the following cascading column view:

This is my favorite view in Valentina Studio. In this view, different levels of entities (database, table, fields, links, indexes, etc) are displayed in columns in a cascading style. Selecting a database in column one, we can choose to display tables, links, views in column two; and for tables, view its fields, indexes, etc in column three. And the final level of details will be displayed in the right most pane. We can also create and modify an entity accordingly.

Another view, less used in my case, is the tree view:

When a table is selected, it displays the table data in a grid view; when a field is selected, only the column data is displayed. In the grid, we can right click on a record to export that record into CSV or SQL.

Continue reading %A Look at Valentina%

Watir-Webdriver: Control the Browser

Fr, 2014-04-18 13:51

Watir-WebDriver (Watir is short for Web Application Testing in Ruby) is a Ruby gem which allows you to automate your browser (make it click a button, submit a form, wait for some text to appear before continuing, and so on). With its help, a real user can be simulated, allowing you to automate the full stack testing of your web application.

Watir-WebDriver syntax is very clean and inspired by similar frameworks in other languages (Watij for Java and Watin for C#). It is also a well-maintened gem with over 68 releases.

Continue reading %Watir-Webdriver: Control the Browser%

Getting Started with Go

Do, 2014-04-17 22:24

Unless you’ve been living under a rock these last few years, you’ll have heard of Go (sometimes referred to as Golang), a language originating from Google, some years ago.

Go is slated as:

…an open source programming language that makes it easy to build simple, reliable, and efficient software.

Quoting another source, Go

is a statically-typed language with syntax loosely derived from that of C, adding automatic memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

Available for most modern operating systems, including Mac OS X, Linux, BSD and Microsoft Windows, it was conceived and initially created at Google, back in 2007, by Robert Griesemer, Rob Pike, and Ken Thompson. Each of these three developers have quite impressive pedigrees.

Robert Griesemer was involved in Google’s V8 JavaScript engine and the Java HotSpot virtual machine; Rob Pike and Ken Thompson both worked at Bell Labs implementing the original UNIX operating system.

Most programming languages, especially one with such a strong C heritage, can be difficult to get started with. Go on the other hand, is quite the opposite. And in today’s tutorial, I’m going to show you how to get started developing with Google Go, right from installation to a running application.


Whether you’re on Mac OS X, Linux and FreeBSD, or Windows, Go is easy to install and configure. I’m assuming in this tutorial that you have a UNIX/Linux operating system. When I first installed Go, being on a Mac, I used the latest package file.

But you can just as easily install, from source, using the following commands:

tar -C /usr/local -xzf go1.2.1.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin

If you’re not familiar, these will extract a copy of the go files, from go1.2.1.linux-amd64.tar.gz, to /usr/local/go in your filesystem, and add the bin directory within it to your profile path.

Alternatively, if you’re on Windows, download and run the MSI Installer.

When the installer’s complete, you’ll find the installed files under c:\Go; and the installer should have added c:\Go\bin to your PATH environment variable. You may want to check, just to be sure though.

Configuring Your Environment

With that done, we have the binaries required to begin. But we need to ensure that our environment’s also ready, which requires one more step and a bit of background.

Go development uses the concept of a workspace, which contains the source files (src), compiled binary files (bin) and packages (pkg).

The source file directory structure, generally, models open source code repositories, such as Github. So a typical source directory could look as follows:

src settermjd sitepoint hello-world.go

You can see that under src, I’ve linked to my Github repository, called sitepoint, and in it is one file, hello-world.go.

I could have multiple repositories, and link to multiple hosts, including Bitbucket and Codebase. By taking this approach, I believe that Go inherently keeps code very well structured and organized.

Continue reading %Getting Started with Go%

An Introduction to the MEAN Stack

Do, 2014-04-17 19:00

The term MEAN stack refers to a collection of JavaScript based technologies used to develop web applications. MEAN is an acronym for MongoDB, ExpressJS, AngularJS and Node.js. From client to server to database, MEAN is full stack JavaScript. This article explores the basics of the MEAN stack and shows how to create a simple bucket list application. Introduction Node.js is a server side JavaScript execution environment. It's a platform built on Google Chrome's V8 JavaScript runtime. It helps in building highly scalable and concurrent applications rapidly. Express is lightweight framework used to build web applications in Node. It provides a number of robust features for building single and multi page web application. Express is inspired by the popular Ruby framework, Sinatra. MongoDB is a schemaless NoSQL database system. MongoDB saves data in binary JSON format which makes it easier to pass data between client and server. AngularJS is a JavaScript framework developed by Google. It provides some awesome features like the two-way data binding. It's a complete solution for rapid and awesome front end development. In this article, we'll be creating a simple CRUD application using the MEAN stack. So, let's dive in. Prerequisites Before getting started, we need to install the various MEAN software packages. Begin by installing Node.js from the download page. Next, install download and install MongoDB. Here is a guide I followed to get MongoDB up and running on my Ubuntu system. To make things easier, we'll be starting from a MEAN boilerplate project. Simply clone the boilerplate repo and install the dependencies using npm as shown in the following listing. [code] git clone cd mean npm install [/code] This installs the required packages. Next, we need to set the default port on which MongoDB runs to 27017 as specified in the README file of the boilerplate. Open up the file /etc/mongodb.conf and uncomment the line port = 27017. Now, restart the mongod server as shown below. [code] mongod --config /etc/mongodb.conf [/code] Next, from the project directory simply type grunt. If all goes well, you will see a message like this: [code] Express app started on port 3000 [/code] Now that the server is running, navigate to http://localhost:3000/ in a browser to see the boilerplate app running. Boilerplate Overview We now have a fully functional boilerplate application. It has authentication implemented, including using social media login. We won't be going much into that, but will be creating our own little app. If you have a look at the application structure, the public folder contains our AngularJS front end and the server folder contains our NodeJS backend. Creating a Listing View First, let's start by creating our front end using AngularJS. Navigate to the public folder. Create a new folder called bucketList, where we'll keep our front end files. Inside the bucketList directory, create subdirectories named controllers, routes, services, and views. Inside the bucketList folder also create a file named bucketList.js containing the following code. [js] 'use strict'; angular.module('mean.bucketList', []); [/js] Next, open mean/public/init.js and add the module mean.bucketList. The modified portion should look like this: [js] angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.router', 'mean.system', 'mean.articles', 'mean.auth', 'mean.bucketList']); [/js] Now, navigate to public/bucketList/routes and add the bucketList.js route file to handle routing in our app. The code to accomplish this is shown below. [js] 'use strict'; //Setting up route angular.module('mean.bucketList').config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { // states for my app $stateProvider .state('all bucket list', { url: '/bucketList', templateUrl: 'public/bucketList/views/list.html' }); } ]); [/js] Inside public/bucketList/views/ create a file named list.html. This is our view, which will display our bucket list. The contents of this file are shown below. [html] Welcome to the bucket list collection [/html] Also create a file named bucketList.js inside public/bucketList/controllers containing the following code. [js] 'use strict'; angular.module('mean.bucketList').controller('BucketListController', ['$scope', '$stateParams', '$location', 'Global', function($scope, $stateParams, $location, Global) { $ = Global; } ]); [/js] Next, start the app using grunt. Make sure that MongoDB is running too if it's not already. Navigate your browser to http://localhost:3000/#!/bucketList, and you should see the list view that we created. If you are wondering about the #! in the url, it's just done to separate the AngularJS and NodeJS routing.

Continue reading %An Introduction to the MEAN Stack%

Learning to focus()

Do, 2014-04-17 18:00

Thanks to good fortune, I have a functional pair of eyes. When it comes to traversing web pages, this is something of a boon since shifting my focus from one part of the page to another requires nothing more than semi-consciously contracting my extraocular muscles and rotating my eyeballs a fraction of their circumference.

Though my visual — and, therefore, cognitive — focus could now be said to have changed, the user interface itself does not know my attention has turned. At least, not until I begin to physically interact with the newly scrutinized region. To put it another way, rotating my eyeballs is an unrecorded event.

Herein lies a very common but frequently unaddressed accessibility issue: If I’m not using my eyes (and my mouse hand to point), how do I ‘focus’ on something in order to then interact with it? The answer, as I’m sure you know, is via programmatic focus. It’s not as simple as just incorporating ‘focusable’ elements into our designs, however. Sometimes it is not the user but the interface on the user’s behalf that must move focus between different areas. This requires deliberate focus management on the part of the developer.

For accessibility, managing focus is essential in many of even the simplest JavaScript-driven interactive widgets, but correct usage is almost impossible to test for with automated QA tools. That’s why I want to take you through a couple of simple examples today.

ScrollTop Animation

In this example, I invite you to imagine you have ‘enhanced’ a same-page navigation link so that, instead of jumping abruptly to the link’s target fragment (#section1, let’s say), you are ushered gently to this destination via a JavaScript scrollTop animation. The important thing to note regarding accessibility when using this technique is the necessity to override the default function of the <a> element.

[code language="javascript"] event.preventDefault(); [/code]

By doing this you are telling the browser to avoid, at all costs, doing anything standard, expected or interoperable. You are telling the link not to link. In fact, the only way to make certain the link actually takes the user correctly to the page fragment is to turn JavaScript off. Well, then.

By simply linking to a page fragment — as one would with JavaScript off — the browser essentially focuses this fragment. This is where screen reader output and keyboard interaction is now based. By animating the scrollTop, no such focusing action takes place, meaning screen reader output and keyboard interaction continues from the area of the page that is no longer in view. This is no good.

Continue reading %Learning to focus()%

Interview: Tom Oram and Rob Allen

Do, 2014-04-17 16:00

In our second interview, we talk to Tom Oram, who works for a small development firm in Wales and Rob Allen, from Nineteen Feet.

These two developers have a solid wealth of PHP experience and knowledge and have helped me refine my ideas and approaches on many occasions. With that, we’ll start with Tom.

Tom Oram What lead you to PHP?

A job. I was offered a job using a language I knew nothing about called PHP. It was PHP version 3 at the time, so much less advanced than it is now. Since then, I’ve been using PHP almost every day of my working life.

What have been the things about PHP that bit you?

In previous versions I’ve had various things which have caused confusion and frustration, most notably references and object copying in PHP 4.

However in PHP 5 I don’t really have anything that really catches me out. There are, however, things which I think could be improved or added to make the language easier and more consistent to use.

What have been the highlights or redeeming features

I guess the best thing about PHP is the speed in which you can get going. You can have an idea and very quickly try it out while at the same time it’s very well suited to larger and more complex projects as well.

What are the compelling PHP features for you?

For me I love interfaces and the fact that static typing is becoming more and more possible while still allowing dynamic typing.

What do you want to see added to the language?
  • Type hinting for scalar parameter types
  • Type hinting of return values
  • Nested classes
Why PHP over Ruby, Python, Go, etc?

Honestly I think they all have their own pros and cons. In many ways I think the other languages are designed better and are more consistent.

However if you’re used to programming in a statically typed language (especially Java) then PHP might seem easier to relate to than Python or Ruby.

Do you see yourself moving to another language in the future?

I use other languages all the time, and if a job is better suited to another language I will use that. However for web-based projects I always reach for PHP first, I currently have no intention of changing that.

Do you have a custom framework/setup?

Continue reading %Interview: Tom Oram and Rob Allen%

Controlling an Arduino with NodeJS and Johnny-Five

Mi, 2014-04-16 19:00

One of the advantages of being a JavaScript developer is the array of APIs and frameworks that bring a whole new level of possibilities to what previously was restricted to web development. A great example of this is the world of electronics and Arduinos. JavaScript libraries/frameworks such as Firmata and Johnny-Five make it a lot easier for JavaScript developers to get more involved and develop applications that can interact with, respond to and control Arduino powered technology. This video aims to help those new to Arduinos and NodeJS understand the basics of getting started. I'll provide an overview of what you'll need to do in order to get a Node application speaking to an Arduino using the Johnny-Five JavaScript framework. By the end we will have used the power of JavaScript to turn an LED light on and off!

Continue reading %Controlling an Arduino with NodeJS and Johnny-Five%

12 Little-Known CSS Facts

Mi, 2014-04-16 18:00

CSS is not an overly complex language. But even if you’ve been writing CSS for many years, you probably still come across new things — properties you’ve never used, values you’ve never considered, or specification details you never knew about.

In my research, I come across new little tidbits all the time, so I thought I’d share some of them in this post. Admittedly, not everything in this post will have a ton of immediate practical value, but maybe you can mentally file some of these away for later use.

The color Property Isn’t Just for Text

Let’s start with the easier stuff. The color property is used extensively by every CSS developer. Some of you not as experienced with CSS may not realize, however, that it doesn’t define only the color of the text.

Take a look at the demo below:

See the Pen CtwFG by SitePoint (@SitePoint) on CodePen.

Notice in the CSS, only one color property is used, on the body element, setting it to yellow. As you can see, everything on the page is yellow, including:

  • The alt text displayed on a missing image
  • The border on the list element
  • The bullet (or marker) on the unordered list
  • The number marker on the ordered list
  • The hr element

Interestingly, the hr element, by default does not inherit the value of the color property, but I had to force it to do so by using border-color: inherit. This is kind of odd behaviour to me.

All of this is verified by the spec:

This property describes the foreground color of an element’s text
content. In addition it is used to provide a potential indirect value
… for any other properties that accept color values.

I can’t think of anything else that would qualify as ‘foreground’, but if you do, let us know in the comments.

Continue reading %12 Little-Known CSS Facts%

Getting Started with PHP Underscore

Mi, 2014-04-16 17:00

If you’ve ever used the Backbone framework for JavaScript, you’ll already be familiar with Underscore. Indeed, it’s become incredibly useful for JavaScript developers in general. But did you know that it’s been ported to PHP?

In this article I’ll take a look at Underscore, what it can do, and provide some examples of where it might be useful.

What is Underscore?

Underscore describes itself as a “utility belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It’s the tie to go along with jQuery’s tux, and Backbone.js’s suspenders.”

Most notably, Underscore provides a bunch of utilities for working with collections and arrays, some for working with objects, basic templating functionality and a number of other useful functions.

The functions which operate on collections and arrays can be particularly useful when dealing with JSON, which makes it great for handling responses from web services.

Continue reading %Getting Started with PHP Underscore%

jQuery Chicago Pebble Giveaway and Filing Extension

Di, 2014-04-15 20:24

As we announced at the end of jQuery San Diego in February, we’re excited that the next stop for #jqcon is Chicago! In case you missed the news, we’ll be setting up shop in the City That Never Sleeps Isn’t Windy on September 12th & 13th, 2014. We’re partnering again with Bocoup to make it a four-day affair, bringing you Roost on September 11th & 12th.

Speaker Filing Extension

While we can’t do anything about today’s deadline for those of us in the US to file our tax returns, we can offer our own form of amnesty: a two-week-plus extension of our Call for Speakers until the end of April! If you got swamped in receipts – or anything else – and thought you’d missed your chance to submit, breathe a sigh of relief, and if you didn’t know the call was even open, this should hopefully provide you enough time to come up with a solid talk proposal. (And if you already have submitted, thanks!)

We’re experimenting a bit with our time slot construction in Chicago, so if you have a talk that you feel needs to go deep into technical material and run for 45 minutes or an hour, or want to lead a more hands-on-workshop type of session for even longer, we’re eager to hear about it and encourage you to to get in touch with questions about your ideas at or on the #jquery-content channel on Freenode.

Join Us

Our early bird tickets have been going fast and will likely be gone before our original early-bird cutoff of May 31st, so if you’re aiming to keep another 50 bucks in your deep-dish pizza budget, you’ll want to act sooner than later!

The conference will be right downtown at the Sheraton Chicago Hotel & Towers, and we’re able to offer attendees of both jQuery Chicago and Roost a discounted rate if you register as part of our room block.

Join Us…Together!

We’ve always held that jQuery is better with friends, and if you’ve got colleagues you want to attend with or send to the conference, we have group packages available that include sponsorships and discounts. Get in touch with us for a prospectus and to figure out how to get your team to Chicago!

A “Rocky” Start

If the prospect of jQuery’s first foray into the Old Northwest wasn’t exciting enough, we’re psyched to inform you that we’ll be giving away classic Pebble devices throughout ticket sales. We’ll take a random draw of people who’ve bought tickets each month and select 2-3 folks who’ll receive a Pebble from us (and the kind folks at Pebble who’ve donated the devices) at the conference in September. The sooner you buy, the better your odds, so what are you waiting for? This post is over anyway!

Building a Recipe Search Site with Angular and Elasticsearch

Di, 2014-04-15 19:00

Have you ever wanted to build a search feature into an application? In the old days, you might have found yourself wrangling with Solr, or building your own search service on top of Lucene — if you were lucky. But, since 2010, there's been an easier way: Elasticsearch. Elasticsearch is an open-source storage engine built on Lucene. It's more than a search engine; it's a true document store, albeit one emphasizing search performance over consistency or durability. This means that, for many applications, you can use Elasticsearch as your entire backend. Applications such as... Building a Recipe Search Engine In this article, you'll learn how to use Elasticsearch with AngularJS to create a search engine for recipes, just like the one at Why recipes?

  1. OpenRecipes exists, which makes our job a lot easier.
  2. Why not?
OpenRecipes is an open-source project that scrapes a bunch of recipe sites for recipes, then provides them for download in a handy JSON format. That's great for us, because Elasticsearch uses JSON too. However, we have to get Elasticsearch up and running before we can feed it all those recipes. Download Elasticsearch and unzip it into whatever directory you like. Next, open a terminal, cd to the directory you just unzipped, and run bin/elasticsearch (bin/elasticsearch.bat on Windows). Ta-da! You've just started your very own elasticsearch instance. Leave that running while you follow along. One of the great features of Elasticsearch is its out-of-the-box RESTful backend, which makes it easy to interact with from many environments. We'll be using the JavaScript driver, but you could use whichever one you like; the code is going to look very similar either way. If you like, you can refer to this handy reference (disclaimer: written by me). Now, you'll need a copy of the OpenRecipes database. It's just a big file full of JSON documents, so it's straightfoward to write a quick Node.js script to get them in there. You'll need to get the JavaScript Elasticsearch library for this, so run npm install elasticsearch. Then, create a file named load_recipes.js, and add the following code. [js] var fs = require('fs'); var es = require('elasticsearch'); var client = new es.Client({ host: 'localhost:9200' }); fs.readFile('recipeitems-latest.json', {encoding: 'utf-8'}, function(err, data) { if (err) { throw err; } // Build up a giant bulk request for elasticsearch. bulk_request = data.split('\n').reduce(function(bulk_request, line) { var obj, recipe; try { obj = JSON.parse(line); } catch(e) { console.log('Done reading'); return bulk_request; } // Rework the data slightly recipe = { id: obj._id.$oid, // Was originally a mongodb entry name:, source: obj.source, url: obj.url, recipeYield: obj.recipeYield, ingredients: obj.ingredients.split('\n'), prepTime: obj.prepTime, cookTime: obj.cookTime, datePublished: obj.datePublished, description: obj.description }; bulk_request.push({index: {_index: 'recipes', _type: 'recipe', _id:}}); bulk_request.push(recipe); return bulk_request; }, []); // A little voodoo to simulate synchronous insert var busy = false; var callback = function(err, resp) { if (err) { console.log(err); } busy = false; }; // Recursively whittle away at bulk_request, 1000 at a time. var perhaps_insert = function(){ if (!busy) { busy = true; client.bulk({ body: bulk_request.slice(0, 1000) }, callback); bulk_request = bulk_request.slice(1000); console.log(bulk_request.length); } if (bulk_request.length > 0) { setTimeout(perhaps_insert, 10); } else { console.log('Inserted all records.'); } }; perhaps_insert(); }); [/js] Next, run the script using the command node load_recipes.js. 160,000 records later, we have a full database of recipes ready to go. Check it out with curl if you have it handy: [code] $ curl -XPOST http://localhost:9200/recipes/recipe/_search -d '{"query": {"match": {"_all": "cake"}}}' [/code] Now, you might be OK using curl to search for recipes, but if the world is going to love your recipe search, you'll need to...

Continue reading %Building a Recipe Search Site with Angular and Elasticsearch%

Caching Values from Sass Mixins

Di, 2014-04-15 18:00

Let’s back up a little bit so I can explain the context of this post. In recent weeks I have been actively comparing rendering output between mixins and placeholders. As a result, the more I think about it, the more I believe using mixins and placeholders as they are described in the Sass docs is simply not enough.

Let’s focus on the main goal here: CSS output. In this whole experiment, I am not considering code complexity or code quality. I’m only considering final CSS output. The point is to have CSS output that is as light and lean as possible.

If you’ve read my previous SitePoint articles covering placeholders vs mixins and @extend directives, you would be aware that there are a couple of drawbacks with both features. Mixins do not merge selectors while @extend directives are restricted to their scope, hence they are basically unusable in a responsive context with @media blocks (which I tackled and partially solved in my article on cross-scope @extend).

Today, I would like to deal with another issue: Mixin grouping.

What is Mixin Grouping?

Mixins are really handy when you want to create shortcuts in your variable code. For instance, you could have a mixin accepting two arguments to output both width and height. Or a mixin for offset positioning. That’s nice.

The problem with mixins is every time you call them, they dump CSS rule sets. If you call them twice with the same arguments from 2 different selectors, they won’t be merged into a single rule set. Instead, they will dump the same rule set twice — which kind of sucks.

For this article, we’ll deal with a very simple use case: A size mixin to assign width and height. Here is what it looks like:

Continue reading %Caching Values from Sass Mixins%

How to Test Browsers on Virtual Machines from Modern.IE

Mo, 2014-04-14 18:00

This article was sponsored by Thank you for supporting the sponsors who make SitePoint possible! Internet Explorer remains the world's second most-used browser with almost one in four users on the desktop. A high proportion of those are from large businesses and government agencies yet, despite the commercial opportunities, few of us devote enough time to testing IE until it's too late. The solution is to test early and test often -- especially the older browsers. Testing IE poses a challenge; it's available only on Windows and, even then, you can install only one version at a time. Emulators and IE's own document modes can help but you should never trust them for anything more than basic layout checks. A few years ago it would have been necessary to install and maintain a suite of PCs with various combinations of Windows and IE. Fortunately, we can do the same without hardware using Virtual Machines. What are Virtual Machines? You've possibly seen emulators that run old operating systems such as Amiga OS, games consoles, or arcade machines on Windows, Mac, or Linux. In essence, these are Virtual Machines (VMs) that make the original OS and software think it's running on real hardware. In reality, it's all happening within the host PC's memory. We're not limited to old OSs -- we can emulate a real PC and run any platform we desire. For example, we can run Windows XP in a VM application on Windows 8.1 so we can retain older, incompatible software. Because it's handled as a data file, we can start, stop move or restore XP anytime we choose. Virtual Machines therefore provide a mechanism to run any edition of Internet Explorer from a Windows, Mac or Linux host. There's little excuse -- you probably have the software already and Microsoft provide a range of free Windows/IE VMs at

Continue reading %How to Test Browsers on Virtual Machines from Modern.IE%

Implementing Multi-Language Support

Mo, 2014-04-14 17:00

Setting up a multilingual site may be a good way to attract new customers to your business or gain more participants in your project. Translating a simple site with a few static pages probably won’t probably be complicated, but more complex PHP web applications may require a lot of work when launching multiple language support. In this article I’ll present different types of content that need to be taken under consideration when internationalizing a site. Read on to get to know how to handle translating them into different languages.

Continue reading %Implementing Multi-Language Support%

UX Dilemma: Red Button vs. Green Button

Mo, 2014-04-14 16:30

When it comes to calls to action, 'button color' is one of the classic metrics to A/B test. It's also a hot discussion topic on design forums, if this Stack Exchange UX discussion is anything to go by.

In the discussion, a user asks:

Which option is more intuitive for the user?

Here are the two options he presents:

Whilst one reader dismissed the options out of hand -- citing the reasons as being 10% of males are red/green color blind -- the question certainly raised a lot of intelligent debate.

This included discussion on the psychological meaning of color, along with the platform used and the physical placement of the buttons.

What Color Means

As far as online standard usage goes, red has been commonly associated with delete. It also typically denotes danger in Western civilisations -- think of stop signs, fire engines and tail lights.

Continue reading %UX Dilemma: Red Button vs. Green Button%

Opal: Ruby in the Browser and the Game of Life

Mo, 2014-04-14 13:30

In the previous installment, I introduced Opal and showed how to get it set up on your system. We created the first half of Conway’s Game of Life in Opal. In this article, we will complete our application by implementing the rest of the logic, and hooking it to the canvas. The completed source can be found at the end of the article.

Continue reading %Opal: Ruby in the Browser and the Game of Life%