Javascript News

Syndicate content
Pipes Output
Updated: 12 min 16 sec ago

Using ACF Flexible Content Fields to Create Unique Layouts

Do, 2014-07-31 19:00

In December 2012, the New York Times broke out of their standard online post layout and wowed us with John Branch’s beautiful “Snow Fall” article. Instead of simply containing headings, text, and the occasional inline photo, this article made liberal use of full screen images, videos, custom text layouts, and animations to draw readers in and captivate them with a well-designed and well-told story.

It wasn’t long before other publishing sites followed suit and began departing from their “normal” design for occasional art-directed articles, like The Chicago Tribune’s “His Saving Grace” and The Verge’s “longform” articles.

Normally, articles on news sites follow a pretty standard pattern: featured image, headline, content (text, headings, and inline images), with a menu above, a sidebar next-door, and comments and a footer below. The large majority of WordPress sites follow that pattern as well. But with a little help from a couple helpful plugins and a custom template page, you can easily build attention-grabbing art-directed articles in WordPress.

For the sake of this tutorial, let’s pick several unique design elements we’d like to add to our “Snow Fall” layout. We’ll want (1) normal WYSIWYG editor areas, (2) hero images with optional text overlay, and (3) pull-quotes. We’ll also want to use as many of each kind of content as we want, in whatever order we want. Let’s go!

Advanced Custom Fields & Flexible Content Fields

To create customizable layouts, we’ll start with the Advanced Custom Fields plugin (WP Plugin Repo). ACF is free, but we’ll also need one of its paid add-ons: Flexible Content Fields. This add-on is less than $25 (USD) and is well worth it!

Continue reading %Using ACF Flexible Content Fields to Create Unique Layouts%

Obvious Design Always Wins

Do, 2014-07-31 18:30

If you’re like me, you are curious about how changing the interface of a mobile application or website may influence the engagement and the earnings of your product.

The idea for this article came to me after reading a tweet posted on the 11th of April by Luke Wroblewski.

His statement Obvious always wins and the image associated with it made me think about some real cases where a simple change may give unexpected results.

Let’s find out what obvious means in the field of mobile design, and look at some examples of obvious choices that affect users’ engagement in a good way. Then, we’ll also see how not so intuitive decisions can have the opposite effect.

Obvious always wins

What is obvious? And why do things seem obvious only after we see the solution? When someone tells us the solution to a problem or a puzzle, we exclaim “Oh, it was so obvious!”.

Things appear obvious when easily discovered, seen, or understood. No surprises there. What could be more easily discovered, seen, or understood than facts and methods we have already learned? We consider obvious most of what we know, and we consider challenging what we don’t know. For example, many people get frustrated when teaching and if their students don’t understand immediately.

The problem is not with them. The truth is that, if it was really so obvious, they wouldn’t be having any trouble.

Obvious is not what you think

In mobile Design there are no intuitive interfaces. There are only interfaces that are familiar, and once familiar they become intuitive. This brings us to the consideration that the concept of obvious is arbitrary and relative.

When you surf the Web or use mobile apps, they usually have, more or less, the same look. Sure they differ in layout, style and colors, but you expect to see common patterns. For example to find the main menu at the top of a screen, a search box in the top-right corner, a footer at the bottom, and so on. The layout is typically the result of conventions and trends of a given period. For example, I’m sure that you are able to distinguish something built recently and something older.

Continue reading %Obvious Design Always Wins%

Pure CSS Off-screen Navigation Menu

Do, 2014-07-31 18:00

Hamburger menu, drawer menu, off-canvas menu: Whatever you call it, hiding a website’s primary navigation just off screen is becoming a ubiquitous pattern in responsive web design. More and more sites feature a fixed-position icon that, when tapped, pushes the entire site to the side to reveal a hidden navigation menu.

While there are plenty of jQuery plugins that will create this effect for you, it’s actually pretty easy to achieve without using any JavaScript at all.

This article will show you how to make a simple version of the off-canvas menu and sliding effect using only CSS.

Before we get started, I’d like to make a note that using this method for creating the drawer menu means your site’s navigation will always be in a drawer, regardless of viewport size. If you only want the drawer menu on smaller screens, you’ll have to use some JavaScript to manipulate the DOM order or use some funky CSS to make the menu look right on larger screens. In other words: It’s pretty and simple, but it’s not always the right solution for every situation.

Here’s a CodePen demo showing the end result:

See the Pen Pure CSS Off-Screen Navigation Menu by SitePoint (@SitePoint) on CodePen.

Start with Some HTML

The markup for our off-canvas menu is a bit different than your standard navigation menu. Instead of sticking it in the site’s header, we’re going to start right inside the <body> tag.

This is the basic structure:

[code language="html"] [/code]

You can see our site’s markup is made up of three main elements: the navigation, a checkbox and label pair, and the site’s actual content.

A few things to note:

  • The navigation section is first in the source order because it’s “behind” everything else on the site. You can use whatever HTML tags you want to build the navigation. Here I’m using an unordered list, which is common.
  • The trigger to slide out our menu is a checkbox input with a label. Typically the label would come before the input or wrap around the input. In this case, the input has to come directly before the label. We’ll see why later when we add the CSS.
  • The rest of our site has to be wrapped in a unique div. This is so that when we open the menu, everything else can slide slightly off-screen to reveal the hidden navigation elements underneath.

Now that we’ve got our basic HTML structure, we can start making it look pretty!

Continue reading %Pure CSS Off-screen Navigation Menu%

A 6-Step Plan for Creating Genuinely Useful Product Support Pages

Do, 2014-07-31 17:00

It’d be nice to think that your product UX is so exceptional that users won’t ever need any help with it. But until every user thinks exactly like you do, your target audience and users will have questions.

How will you answer them?

This six-point plan should help. Not only that, it will help you create help information that actually helps you identify problems with your product UX – problems you can ameliorate, if not solve, with better design.

Let’s see how.

1. Determine the purpose of your help pages

Working out what you want your help pages to do is a pretty obvious first step. Depending on your product, audience, and support strategy, your online help pages’ purpose may vary:

  • Is it a place where users can help each other?
  • Will it let users contact your support staff direct? In real time?
  • Is it a place where users can access self-help?

You’ll likely already have an idea of what purpose, or purposes, you want the pages to serve, but it’s good to put it into words up-front, before you begin to consider help formats or technologies.

2. Choose which user actions will be served by your help pages

This is an important point, one that directly reflects your overall support strategy.

Yet it’s easy to get this bit wrong: to decide you’ll create an FAQ page and expect it to do everything users need, or to simply list an email address, and pay support staff to answer common questions that could more effectively be answered with some FAQs.

So think this through. What kinds of questions, if any, will be addressed on your help pages? Which user actions will you provide self-help for? And what will be the next step or steps for users who can’t resolve their issues on your help pages?

One point here: it’s easy to start thinking that all users will just contact support if you list a phone number or email address, so why bother with help pages?

But in my experience (and probably yours), a majority of users do want to self-help. This can be great for your support strategy, if you take the time to work out where the breaking points are, and how far you actually want your self-help content to go.

3. Identify the points in each use case where a user will seek help

Now it’s time to go a bit deeper and look at actual use cases you’ve used to develop your product.

Look through the key use cases, page flows and actions users will pursue within your app, and make a list of the questions they’ll have, or problems they’ll face along the way. Perhaps you’ve already done this as part of the UX design and dev process. Great. The important thing is to identify where in your product help is needed, and what will be helpful at those points.

Continue reading %A 6-Step Plan for Creating Genuinely Useful Product Support Pages%

Introducing InvoiceNinja: Self-hosted Invoicing

Do, 2014-07-31 16:00

For a freelancer, nothing is more important than time. Tracking invoices or doing paperwork can quickly become tedious and occupy a large portion of that. In March, I showed you FusionInvoice, a tool to keep track of your clients and invoices. Although it’s a nice and easy to use tool, its open-source version has since been discontinued and in part taken over by InvoicePlane. In this post, however, I’d like to introduce you to InvoiceNinja.

Introducing InvoiceNinja

InvoiceNinja is an open-source self-hosted and cloud hosted invoicing platform.

True to its motto, InvoiceNinja’s interface is simple and intuitive making creating invoices a breeze. Tasks like managing clients, issuing a new invoice or adding a payment are just simple actions that even an inexperienced user will feel comfortable doing. Its simplistic dashboard greets the user displaying relevant information about the invoices created and their status. The live preview of the invoice will help you to easily review it before sending it to your clients.

Through integration with PayPal, Google Wallet and 21 other payment processors, InvoiceNinja makes it very easy for your clients to reimburse you for your work directly through the application.

Continue reading %Introducing InvoiceNinja: Self-hosted Invoicing%

Not an Accountant? How to Make Sense of Your Business Finances

Do, 2014-07-31 14:00

One of the most difficult things that many people grapple with when they first go self-employed is their business's finances.

But as intimidating as dealing with your accounts can seem, it's not actually that difficult. It's true that things can get trickier once your business starts to grow (especially if you start to hire a staff), but for the most part, accounts are really just about organization.

So if you're thinking of going freelance but the thought of dealing with the dreaded tax man strikes fear into your heart, don't despair. It's a lot easier than it looks.

For the sake of this post, let's assume that you're just about to hang out your shingle as a freelancer.

Where do you start when it comes to organizing your business accounts?

Continue reading %Not an Accountant? How to Make Sense of Your Business Finances%

WordPress i18n and Localization

Mi, 2014-07-30 19:00

WordPress is arguably the world's leading content management system (CMS) in use today (some argue that it's also much more than a CMS), powering over 60 million websites globally.

By default, WordPress is presented in U.S. English (en_US), but it does come with a built-in language capability. This has allowed the WordPress community to translate WordPress into several languages. WordPress themes, translation files and support have also been made available in various languages.

WordPress i18n Support

WordPress uses the gettext libraries and tools for internationalization (i18n). It is the libraries that facilitate the internationalization of WordPress, themes and plugins.

Note: i18n is an abbreviation for internationalization and its called i18n because there are 18 letters between “i” and “n”.

If you are not familiar with the concept of i18N, translations, and Gettext, I strongly encourage you to read this series to have an understanding of what’s involved.

In this article, I'll cover the basics of WordPress i18n. I am going to walk you through the simple process of installing a localized version of WordPress (WordPress in your own language), and also show you how to turn an existing WordPress site to a localized version.

Installing a Localized Version of WordPress

A lot of WordPress enthusiasts from different parts of the World have teamed-up to translate WordPress into their various languages. For example, the French, German and Italian localized version of WordPress is available at fr.wordpress.org, de.wordpress.org and it.wordpress.org respectively.

Let’s see how we can install a localized WordPress using the German internationalization as our benchmark for this tutorial.

Continue reading %WordPress i18n and Localization%

2D Animation Tutorial Using Spine for Mobile Apps

Mi, 2014-07-30 18:30

In the classic book by Disney animators Frank Thomas and Ollie Johnson, “The Illusion of Life”, the art of character animation is described as crafting,

drawings that appear to think and make decisions and act of their own volition.

Animation, especially of seemingly living things, seems like a major hurdle for the mobile app developer who needs to create people, insects, birds, and lifelike plants to bring their mobile games to life. Many turn to sprite sheets, using software such as Texture Packer to turn a series of drawings into a ‘moving picture’ much like the Disney animators did, frame by frame with each sprite moving slightly to give an illusion of a moving figure when played in sequence, like an old-fashioned flip book.

Sprite sheets, however, present some problems for mobile apps if they are at all complicated. First, they are difficult to edit and maintain, as to change any element of the sprite sheet means carefully and precisely replacing all elements of a sprite sheet. One mistake and the animation looks jerky and “unreal”.

Additionally, sprite sheets consume a certain amount of texture memory in your app. First, you will need a copy of each element of your animation embedded into your sprite sheet, there might be dozens of images packed into a png file. Second, you might want to content-scale that sprite sheet so that it looks good on retina screens, so you will need a @2x version of it, using even more memory. For fast-moving games with many complex animations, sprite sheets can quickly become a maintenance and memory problem.

There must be a better way!

Enter Spine, the easy-to-use and well-designed software by Esoteric Software. Spine was created as a Kickstarter project and has quickly become a tool of choice for many developers of mobile games. As one Corona developer noted,

…bought it after trying it for something like 2 seconds.. This is the coolest thing that happened for Corona based games since Corona!

Instead of creating frame-by-frame animations, Spine works by creating skeletal animations. In short, you create a skeleton and “dress it” into a skin, apply keyframes, and create an animation in a short amount of time. It’s an intuitive process once you understand the basics of the software. In this tutorial, I’ll show how to create a simple two-part animation: a bee that has two states, fluttering, and pausing.

To begin, you need at least the trial version of Spine. Download it at esotericsoftware.com/spine-download. Note, you won’t be able to export any files to use in your mobile apps until you buy a version of the software, either the Essential version at $60 or the Professional at $249. Most of the functionality an Indie developer needs is included in Essential, so I recommend buying it if, after the trial version shows you Spine’s capabilities, you think you could use it in your projects. 

Continue reading %2D Animation Tutorial Using Spine for Mobile Apps%

Keep Sass Simple

Mi, 2014-07-30 18:00

In a couple of months, it will be 2 years since I started using Sass. Almost every day. At work. At home. On side projects. To the point where people ask for my help when it comes to Sass, and believe me I am very glad to provide help whenever I can.

Some requests are fair. Some are dead-simple but hey, we all started somewhere. And some are just insane. Look, I don’t judge; at some point every single person using Sass (or any other preprocessor for that matter) has been tempted to over-engineer something to make things simple™. Me included, and more than once.

Let’s Optimise!

The other day, I was asked how to do this:

[code language="sass"] .class { width: 20px; } .other-class { width: em(.class:width); } [/code]

Basically, convert .class width to em then use it as the width of .other-class. Think about that for a second. Not only is px to em very difficult to achieve due to the lack of context in Sass, but now it is about referencing the value from the property of a selector as the value to a property from another selector. Nope.

Even Stylus — which is well known for being quite advanced — can’t do that. At best, it can refer to the value of the property in the same code block (known as property lookup). Obviously Sass — being much more conservative — can’t do that either.

But the problem is not about having the ability to do something like this. The problem is about wanting to do something like this. This should not happen. Ever. If you come up with a case where you need this, you’re obviously doing something wrong.

Note: if you ever wanted to do something like this, don’t feel ashamed or offended. This is just one example among many.

Because We Can

Okay, let’s agree on the fact that the above request is indeed a wrong way of using Sass. Do you want a more controversial example? The Sass 3.4 changelog recently got featured everywhere, promoting the incoming selector functions. Those features are meant to be able to manipulate selectors like lists, with functions like selector-nest(), selector-replace(), and so on.

Continue reading %Keep Sass Simple%

4 Features That Make Me Choose NuSphere PhpED

Mi, 2014-07-30 16:00

In the last survey on the best PHP IDE for 2014, my longtime favorite PhpED was missing. I didn’t act on it then, but what better way to spread the love than to devote an article to it.

I’ve spent the first part of my programming career without a real IDE. UltraEdit was meeting most of my needs. At a certain point you start to realize you’re missing out on something and the quest for a real IDE begins.
For quite some time I was relatively happy with NetBeans; after some time though, I did find myself fighting it on too many occasions. I again concluded that it was time to move on. Having a historical hate for Eclipse (we had a serious misunderstanding back at version 3 dot something from which I still haven’t recovered) meant I had to test the commercial IDEs.

Why I chose PhpED

Speed, overview and simplicity. That sums it up, really. There are a few things that mattered for me, speed-wise; switching projects, getting code suggestions and fast debugging. Overview is something that I want because my projects get quite complex at times. An IDE like Eclipse overwhelms me with way too many options and buttons which I hardly ever use, keep it simple please. I believe I found my requirements and more in PhpED…

Project wizard

The project wizard will help you set up your project like you want it; simple local project, local server or remote server. Run on web server and/or CLI. Set up the directories, code page, PHP/HTML/CSS versions and finally checking to see if the debugger is working. It’ll be quite specific on how to fix issues or offer to fix them should there be any.

Coding

All the normal things are present when it comes to editing code: dynamic syntax highlighting for multiple languages, variable highlighting, fast searching and more. The code suggestion is instant; the IDE presents the possibilities that match the start that you typed. When you find what you wanted and your code is documented using PHPDoc, then it’ll show that while you’re entering your variables.

In the example above, you can perhaps spot something that can be improved; it fails to show multiline comments of the documentation. This is good to get a simple overview of the function call, but quite often you document something for a reason and you want to see it all.

Continue reading %4 Features That Make Me Choose NuSphere PhpED%

What’s the Point of Agile Points?

Mi, 2014-07-30 14:00

One of the first questions I always get asked when I'm talking to someone who is new to scrum is this: Why use points to estimate the effort involved in completing a story, instead of estimating in hours or days?

Points seem arbitrary, and hard to see how they can help a team with its real-world concerns, like meeting deadlines.

Hours and days, on the other hand, can be easily understood, measured, and weighed against practical external requirements.

Additionally, one of the key rewards that gets teams interested in implementing an agile workflow is the promise that they can learn to accurately estimate the amount of work the team can do in a certain number of days or weeks. Points seems like a step back from that goal.

So why use points?

There is a practical, measurable, real-world value to using a relative estimation tool like points.

To illustrate this, let's set up two imaginary teams--one that uses hours to estimate effort and one that uses points.

Continue reading %What’s the Point of Agile Points?%

Golden Master Testing: More Refactoring, More Understanding

Mi, 2014-07-30 14:00

p>After a tedious slog through views and controllers, we finally reached the part of refactoring that becomes an adventure: Grasping at straws. Second guessing everything. Obsessively running the tests. Nurturing the delicate hope that our new-found understanding is, indeed, insight and not just another failed assumption.

Continue reading %Golden Master Testing: More Refactoring, More Understanding%

Responsive, Fluid-Width, Variable-Item Navigation with CSS

Di, 2014-07-29 19:30

Around six months ago I was asked to develop a single row navigation bar that could contain a variable number of menu items while filling the entire width of the container. The amount of navigational items was dictated elsewhere and likely to change in future.

Thinking ahead, it would have been impractical to change the CSS every time a menu item was added or removed. A resolution had to be found, ideally without using JavaScript.

Using Percentage Widths

Fixed widths are unable to consistently fill the responsive container, as the below image illustrates.

So we need to use percentages to accomplish this. Percentages are the prevalent method to achieve a fluid grid layout in responsive designs and will come in useful here.

For example, take the below familiar HTML into consideration:

[code language="html"] [/code]

And we’ll add the following CSS:

[code language="css"] nav { width: 100%; background: #f0f0f0; border: 1px solid #ccc; border-right: none; } nav ul { overflow: hidden; margin: 0; padding: 0; } nav ul li { list-style: none; float: left; text-align: center; border-left: 1px solid #fff; border-right: 1px solid #ccc; width: 16.6667%; /* fallback for non-calc() browsers */ width: calc(100% / 6); box-sizing: border-box; } nav ul li:first-child { border-left: none; } nav ul li a { display: block; text-decoration: none; color: #616161; padding: 10px 0; } [/code]

Areas of note are:

  • The <nav> element is given width: 100% to fill the entire available space.
  • <li> elements are supplied with two width properties - width: calc(100% / 6); and width: 16.6667%;. This is where the menu items are divided across the <nav> element into 6 equal widths. The order these properties are listed is important to allow browsers that support calc() to utilize it over the standard percentage width. Browsers without support for calc() will simply ignore it and use the fallback. I tend to use calc() with percentages to assist in readability and to allow the browser to use the result it is optimized for. That way I don’t have to worry about whether to include recurring decimal places.
  • box-sizing: border-box; is declared on the <li> elements. This forces the width property to include the border-left and border-right values in the total width. Without using this property, the <li> elements wouldn’t fit within the <nav> area and the last <li> element would wrap onto a new line. Many prefer to set box-sizing: border-box; to all elements in order to easily manage widths, as Paul Irish suggests.

The result of adding these styles is shown in the CodePen demo below:

Continue reading %Responsive, Fluid-Width, Variable-Item Navigation with CSS%

PHP News You May Have Missed – July 2014

Di, 2014-07-29 18:00

A handful of news cropped up again that didn’t really get the attention they deserved, so I’ll use this opportunity to rehash some of them and explain others. The “news” here are usually less than brand new - instead, they’re bits of information you should pay attention to if you’re even the least bit interested in the PHP community and environment.

The Zend Rush

Zend, the company behind anything that has “Zend” in its name (Framework, Server, Studio, Engine…) has been very aggressive in product updates of late. They started the year off with a new release of their Zend Certification exam, continued with a huge update to the Zend Server, which we’ve covered in another post, and wrapped things up by updating Zend Studio to a new major version - it now goes to 11! We’ll be taking a more in-depth look at it in another post.

Continue reading %PHP News You May Have Missed – July 2014%

Understanding the Difference: WordPress.com vs WordPress.org

Di, 2014-07-29 17:15

New to WordPress? Trying to understand the differences between WordPress.com and WordPress.org? The video below explains the difference between the two WordPress types and how to choose which one is right for your next website.

Continue reading %Understanding the Difference: WordPress.com vs WordPress.org%

5 Sites For Fantastic Creative Commons Design Resources

Di, 2014-07-29 16:28

“You wouldn’t download a car” You might recognise this question from the compulsory anti-piracy video on many movies and other digital media. The irony? In 2014, I very well might download a car! 3D printing makes this very achievable — even trivial — if you have the necessary hardware and resources. Yet statements like this […]

Continue reading %5 Sites For Fantastic Creative Commons Design Resources%

8 Online Payment Options That Aren’t PayPal

Di, 2014-07-29 14:00

When most people think of online payments, one name comes to mind: PayPal.

But for all PayPal's strengths, it's a bad idea to rely on it as the single system to accept payments on your site. Monopolies are never healthy, and you need to diversify your payment channels.

Why You Need PayPal Alternatives?

There are plenty of reasons why you should support multiple payment options, but here are several of the most important ones:

  • Your partners or customers can't make or accept PayPal payments. This is the major reason to offer payment alternatives. There are always people who can't (or won't) pay or receive money via PayPal, and for them it does make a difference if a site offers alternatives or not. In this case, if you are not open to alternatives, you simply lose these customers or partners. On the other hand, you need to make some estimates if the gain is worth the extra effort. It might turn out that offering more options doesn't increase your income but does increase costs and the hassle.
  • Your PayPal account could be blocked. We have all heard horror stories about PayPal blocking accounts for various reasons, or for no reason at all (so the victims claim), and even if these stories are not 100% true, it's still a nightmare. You shouldn't put all your payment eggs in one basket--the risk is too high.
  • You need a safer way to receive payments, especially for larger sums. PayPal is very convenient for small amounts but if you regularly send or receive thousands of dollars, then you are better of with other forms of payments, such as checks or wire transfer.
  • You want to reduce costs. PayPal fees are certainly not the lowest in the industry, so you might end up paying hundreds or even thousands of dollars a month in commissions. There are lower cost alternatives but unfortunately they have other limitations. In fact, if reducing costs is your main reason to look for PayPal alternatives, your options are limited.

Continue reading %8 Online Payment Options That Aren’t PayPal%

When WordPress Meets Vagrant: VVV

Mo, 2014-07-28 19:00

Vagrant has changed the way I work. In this article I discuss how Vagrant, a tool for creating and managing virtual environments, helps me work more efficiently. I will then introduce Varying Vagrant Vagrants (VVV), an evolving Vagrant configuration purpose-built for WordPress developers.

Are You Still Using WAMP/MAMP?

If you're reading this, there is a high chance that you have used local development in the past. We all have gone through this. WAMP/WampServer, LAMP or MAMP, we've all had nightmares developing with them. Most of the time I was developing using WAMP (Windows environment), then I changed my development environment to Linux. It was the best thing I have ever done.

If you’ve ever worked in a team, you have probably come across the scenario where someone says “It works on my machine”. Or perhaps you've lost time losing your development environment when you've switched computers or bought a new laptop.

Working on different projects, often requires different PHP versions, and different extensions. Sometimes there are conflicts with extensions. Things may break. Let's not even talk about differences in the operating system, that's another level of nightmare.

But what I hate the most, is messing with my primary system. I don't want to my system to become dirty. I don't want to install something and to forget that it is there. Projects finish but (usually) extensions and configurations stay there, and then you have to reconfigure everything.

But don't worry, I think those days are over. I've been experimenting with Vagrant for a while and it has permanently changed the way I work.

Continue reading %When WordPress Meets Vagrant: VVV%

3 New JavaScript APIs You May Want to Follow

Mo, 2014-07-28 18:00

If you're a SitePoint frequent reader and perhaps a follower of mine, you're aware that I've written a lot of articles about HTML5 and JavaScript APIs. So far, I've published articles discussing APIs that you can start using today, even if with the use of a polyfill.

Today I'll break this habit by giving you a preview of some APIs that are still at a very early stage. To give you an idea of how cutting edge these APIs are, consider that 2 out of 3 were announced just few days ago. Because of this, the bad news is that none of them can be used right now. However, if you're interested in what they do, you may want to follow the development of the specifications and maybe provide your feedback.

Without further ado, let's start!

Web Alarms API

The Web Alarms API provides access to the device alarm settings, which can schedule a notification or for an application to be started at a specific time. The typical use case for this API involves applications like alarms, calendars, or any other software that needs to perform an action at a specific time.

Starting from last year, this API is a W3C Working Draft. So, the specifications are at the first stage of the process to become a W3C Recommendation. This API is exposed through the alarms property of the window.navigator object. The alarms property offers three methods:

  • getAll(): Retrieves all the alarms added to the device as an array of Alarm objects.
  • add(): Registers an alarm based on a Date object and returns an AlarmRequest object.
  • remove(): Removes a previously added alarm based on the unique ID (unique within the application origin).

Just to give you an idea of how you could ideally call these methods, here is an example that adds an alarm (remember that at the moment this code won't work in any browser):

[js] var alarmId; var request = navigator.alarms.add( new Date("June 29, 2012 07:30:00"), "respectTimezone", ); request.onsuccess = function (e) { alarmId = e.target.result; }; request.onerror = function (e) { alert(e.target.error.name); }; [/js]

Then, if you want to remove the same alarm, you can write:

[js] var request = navigator.alarms.remove(alarmId); request.onsuccess = function (e) { alert("alarm removed"); }; request.onerror = function (e) { alert(e.target.error.name); }; [/js]

Continue reading %3 New JavaScript APIs You May Want to Follow%

Debugging in Git with Blame and Bisect

Mo, 2014-07-28 18:00

When you are working with a huge code base, you may discover bugs in your code (or worse, in someone else’s code) that prevent you from proceeding any further in your development. You can checkout to an old commit to see if the bug was present there — but this is often the worst way of doing so. Imagine you have a hundred commits to check — how much time would be wasted?

Thankfully, Git has two tools that help you with debugging. We will have a look at both and try to understand their use cases. Let us start by intentionally introducing a bug into our code:

I’ve added a line to the file my_file that is unwanted and assumed to cause the error. I also add a few commits after that to bury the faulty commit. Let us verify that the faulty line has been added to the file by running the following:

[code language="shell"] cat my_file [/code]

Notice the “Unwanted line” that is supposedly causing the error.

Debugging with Blame

Once you have discovered a bug, you may or may not know the location of the faulty code. Let’s say that you do. In our case, let’s say that you know my_file is causing the trouble. In that case, we can run the following command to get more information about the lines in the files, and the commits those lines belong to.

[code language="shell"] git blame my_file [/code]

If you look at the output of git blame, you can see that commit 0bf63b53 is what introduced the bug (“Unwanted line”). If you want to check what else was changed in that commit, or want more information about the same, you can run the following:

[code language="shell"] git show 0bf63b53 [/code]

There you go — we now know which commit caused the error and what else was changed in that commit. We can proceed to fixing the error.

Debugging with Bisect

git blame helps you when you have some idea about what is causing the problem. What if you had no idea what is causing the error and there are hundreds of commits before you can go back to a working state? This is where git bisect comes into play.

Imagine git bisect as a wizard that takes you through your commits to find out which commit brought in the error. It performs a binary search to look through the commits, before arriving at the one that introduced the bug.

To start off, we need to select a “good” commit, where the bug is not present. We then need to select a “bad” commit where the bug was present (ideally the latest commit that contains the bug, so you can assign it as “bad”). Git then walks you through recent commits and asks you whether they are “good” or “bad”, until it finds the culprit. It’s essentially a binary search algorithm over the array of commits to find which commit was the first “bad” commit.

Continue reading %Debugging in Git with Blame and Bisect%