Javascript News

Syndicate content
Pipes Output
Updated: 12 hours 5 min ago

10 Essential SublimeText Plugins for JavaScript Developers

Mo, 2015-08-31 20:00

Sublime Text is a great application for just about any developer to have in their toolbox. It is a cross platform, highly customizable, advanced text editor and sits nicely between full featured IDEs (which are notoriously resource hungry) and command line editors such Vim or Emacs (which have steep learning curves).

One of the things that makes Sublime so great is its extensible plugin architecture. This makes it easy for developers to extend Sublime’s core functionality with new features such as code completion, or the embedding of remote API documentation. Sublime Text doesn’t come with plugins enabled out of the box — they are typically installed through a 3rd party package manager simply called Package Control. To install Package Control in Sublime Text, please follow the installation guide on their website.

In this article, I will outline ten must-have Sublime plugins for JavaScript developers, each of which can improve your workflow and make you more productive. So let’s get to it!

1. Babel

Of course the first one on my list is the Babel plugin. This plugin adds proper syntax highlighting to your ES6/2015 and React JSX code. After installing the plugin, the first thing you should do is set it as the default syntax for .es6, .jsx, and even .js files. However, you should be careful with the last one if you’re working with ES3/5 and not transpiling your code using Babel.

If you have not yet discovered the joy of Babel, I highly suggest it. It allows you to compile ES6/2015 and JSX code to ES5. It integrates well with all popular build tools and the CLI. Obviously, it doesn’t support legacy browsers, but you can follow the tips on their caveats page if you need to support IE10 and below.

Unfortunately, the Babel plugin doesn’t allow you to compile ES6 code on the fly from within Sublime. For those of you wanting to do that, I suggest you check out Compile Selected ES6.

2. JSHint

Next up is the JSHint plugin for Sublime. JSHint is a JavaScript Linter, which will look over your code and verify it has proper styling, proper syntax, and is free of common errors related to these. No matter if you’re a beginner or have been programming for most of your life, JSHint is a must have. Check out the JSHint about page for more information on what it can do for you.

For the JSHint SublimeText plugin to work, you need to have JSHint installed globally via npm:

npm install -g jshint

If you’re unsure how to do this, check out our tutorial on getting started with the Node Package manager.

Once the JSHint npm module and the JSHint SublimeText plugin are installed, you can simply invoke JSHint by opening your JavaScript file and pressing Ctrl + J (or Alt + J on Linux/Windows). Alternatively, you can access JSHint via the context menu.

If you've installed the plugin but would like a more explicit warning as to where the error occurred, check out JSHint Gutter. Or, if you’d like to try JSHint before installing the NPM package or the plugin, JSHint.com has a great online interactive tool into which you can paste your code for instant feedback.

3. JsFormat

JsFormat is based on JS Beautifier and can help you automatically format JavaScript and JSON. If you only use it for the JSON formatting alone, it’s worth having. But for me, the biggest advantage comes when I’m working with other developers’ code, or even on code I wrote a long time ago.

Such code can often be hard to read and following a common code formatting style really helps. While formatters may not be for everyone, they can really help the developer read code by introducing a common structure. Linters take care of some of this, but they don’t necessarily hit everything and do not automatically fix formatting. Code formatters save a lot of time and a lot of headaches.

Once installed, to use JSFormat, go to your JS file and hit Ctrl + Alt + f on Windows/Linux or Ctrl + ⌥ + f on Mac. Alternatively, use the context menu.

You may be thinking: “But I what if I don’t like the way they style JavaScript?”

Good news! JsFormat is highly configurable and based on the JS Beautifier settings. To adjust these for SublimeText 3, go to: Preferences -> Package Settings -> JsFormat -> Settings - Default

Then edit the JSON settings there to your liking.

Continue reading %10 Essential SublimeText Plugins for JavaScript Developers%

Automating LIFX Lights With The LightBlue Bean and IFTTT

Mo, 2015-08-31 18:00

The LightBlue Bean is a small low energy Bluetooth Arduino microcontroller with a built in 3-axis accelerometer and temperature sensor. It's quite an interesting way to add connectivity to objects via Bluetooth connectivity instead of Wi-Fi. It has digital and analog pins like a typical Arduino, so you can expand what it can do by adding new elements to the set up.

In order to add new elements, a bit of soldering is required. For this article, I wanted a solder-free demo that anyone with a LightBlue Bean can follow along with, so we'll be focusing on the built in accelerometer. A few months ago, I put together an IFTTT demo here on SitePoint which automatically turns off my LIFX light when I set my Jawbone UP24 to sleep mode. It is a nice touch but I still need to get my smartphone out to turn on my lights each night. I'd prefer something more automatic and decided to try out a few technology experiments to turn the lights on in convenient ways too. In this article, I'll cover the first of my prototypes - I'll be using a LightBlue Bean to detect my door movements and turn my lights on or off depending on if my door is opened or closed.

For those who are a fan of the LightBlue Bean, there is a newer version of the LightBlue Bean on Kickstarter right now called the LightBlue Bean+ which looks pretty neat! It has a rechargable battery, solderless connectors and plenty more useful features. There are only a few days left to put in your pledge!

How This Will Work

Our demo will work like so:

  1. Stick the LightBlue Bean on the door we want to track.
  2. Upload an Arduino sketch which watches for accelerometer changes (the door swinging one way or the other) and sends a message via the Bean Loader Virtual Serial.
  3. Set up a Node server watching for the serial messages coming through.
  4. Set the responses to those messages in the Node server to send a HTTP request to IFTTT's Maker channel to tell it to turn on the light.
  5. Set the LightBlue Bean to Virtual Serial mode.
  6. Run the Node server and close your door to see your light turn on!

Additional rules could be included in our Node server later on to ensure that the code only runs during certain times of day too (to avoid the light going on when it really doesn't need to be). Or even better - add on a photo resistor to detect automatically if the light is needed!

Setting Up Your LightBlue Bean

If you are completely new to using the LightBlue Bean, you'll need to have both the latest Arduino software and the Bean Loader software installed on your Windows 8.1 or Mac computer (apparently the Bean Loader software does not work on older Windows PCs). The guides to getting your LightBlue Bean connected up to your Mac or PC are pretty thorough on the LightBlue Bean website:

This demo has all been set up on Mac OSX but should theoretically work on Windows too.

The steps in this article will assume you are comfortable with the basics of putting a sketch onto your LightBlue Bean, if not, run through the "Getting Started" link for your OS above first.

Our Arduino Sketch Code

All the code is available on GitHub for you to use and adapt for any purpose you choose!

Our Arduino sketch contains most of the brains behind the door watching and looks like so:

[code language="c"]
int minXVal = 0;
int maxXVal = 0;
int minYVal = 0;
int maxYVal = 0;
int minZVal = 0;
int maxZVal = 0;
int movement = 15;
bool ready = false;

void setup() {
Serial.begin();
}

void loop() {
AccelerationReading acceleration = Bean.getAcceleration();

if (!ready) {
for (int i = 0; i < 100; i++) {
if (acceleration.xAxis > maxXVal) {
maxXVal = acceleration.xAxis;
} else if (acceleration.xAxis < minXVal) {
minXVal = acceleration.xAxis;
}

if (acceleration.yAxis > maxYVal) {
maxYVal = acceleration.yAxis;
} else if (acceleration.yAxis < minYVal) {
minYVal = acceleration.yAxis;
}

if (acceleration.zAxis > maxZVal) {
maxZVal = acceleration.zAxis;
} else if (acceleration.zAxis < minZVal) {
minZVal = acceleration.zAxis;
}

delay(10);
}

ready = true;
} else {
if (acceleration.zAxis < minZVal - movement) {
String stringToPrint = "CLOSED";
Serial.println(stringToPrint);
} else if (acceleration.zAxis > maxZVal + movement) {
String stringToPrint = "OPEN";
Serial.println(stringToPrint);
}
}

Bean.sleep(1000);
}
[/code]

Our Sketch Code Explained

To start with, you'll see a range of variables called minXVal, maxXVal, minYVal, maxYVal, minZVal and maxZVal. These track our LightBlue Bean's initial accelerometer readings. Within my demo code, we only really use the z values, however I've left the others in here as you may need to use their values for your own implementations (e.g. if you place the Bean in a different orientation on the door or have a different sort of door, like a sliding door). The accelerometer tracks the force of gravity on each side of the Bean. We only want to know about the changes in these forces, so we need to know the range of forces acting on the Bean originally when it is stationary on our open door. This is where we store those values:

[code language="c"]
int minXVal = 0;
int maxXVal = 0;
int minYVal = 0;
int maxYVal = 0;
int minZVal = 0;
int maxZVal = 0;
[/code]

Next we set a variable called movement which is the level of movement we'll accept before triggering the action. You'll need to adjust this to suit your own situation (your door may move a lot more subtly whilst open than mine). In the sample code, we're allowing for movement of about -15 to +15 from our min and max values before we trigger anything:

[code language="c"]
int movement = 15;
[/code]

We will need time to run the initial test of the min and max values, so we use the ready variable to tell our loop whether we are ready to start watching for door movements within our min and max ranges:

[code language="c"]
bool ready = false;
[/code]

In our setup() Arduino function, we set the serial connection to start running when the Arduino is ready:

[code language="c"]
void setup() {
Serial.begin();
}
[/code]

Within our loop, we perform all our watching of our accelerometer values from the Bean. This will all be readable via the acceleration variable we set up at the start of the loop() function:

[code language="c"]
void loop() {
AccelerationReading acceleration = Bean.getAcceleration();

// Our accelerometer tests
}
[/code]

Continue reading %Automating LIFX Lights With The LightBlue Bean and IFTTT%

Why Agile is a Competitive Advantage in a Digital Age

Mo, 2015-08-31 16:30

This article was sponsored by Atlassian. Thank you for supporting the sponsors who make SitePoint possible.

Atlassian, the company behind the popular project and issue tracking software JIRA, recently partnered with Harvard Business Review Analytic Services to write a report on the successes of agile software development. The report outlines the recent shift in development trends, and how the increase in competition requires software teams to meet deadlines faster than ever. Moving to an agile workflow is the key to rapid development and release cycles, but there’s a trick to doing agile the right way. Let’s go over a few key points highlighted in the report in order to gain a better understanding of the best way to do agile.

The History of Agile

As it turns out, the agile process has been around for some time. Nearly two decades in fact. But only recently has the method of software development gained acceptance as a mainstream best practice. Although its taken a while to grow in popularity, the report from Atlassian and Harvard states that “IDC estimates the market size for agile lifecycle management tools will surpass $1 billion in worldwide revenues by 2017.” This means that agile’s popularity shows no signs of slowing down. Isn’t it time your team took notice?

So what makes agile so special? As the report outlines, agile differs from the traditional waterfall approach to programming. This waterfall method breaks down programming into several iterative steps, including planning, design development, testing, and implementation. Each step is designed to take place in succession, with no overlap occurring between the next. As you may be aware, this approach has its difficulties. Each step can take a long time to be completed, and often gets delayed due to changing business requirements. Of course the most important reason to choose agile over the waterfall approach is communication. With the traditional waterfall approach, it becomes difficult to create an environment of teamwork and collaboration, since each phase of the project needs to happen successively.

With agile, the waterfall approach is broken up into a much smaller scale, so that incremental parts of the project are can be iterated on at a much faster pace. This in turn promotes teamwork and communication, since all team members are encouraged to work with each other in order to deliver a smaller piece of the whole project.

Continue reading %Why Agile is a Competitive Advantage in a Digital Age%

Writing PHP Git Hooks with Static Review

Mo, 2015-08-31 16:00

If you’ve been using Git for more than a short length of time, you’ll hopefully have heard of Git hooks. If not, Git hooks, as Andrew Udvare introduced here on SitePoint back in August of last year, are scripts which run, based on certain events in the Git lifecycle, both on the client and on the server.

There are hooks for pre- and post-commit, pre- and post-update, pre-push, pre-rebase, and so on. The sample hooks are written in Bash, one of the Linux shell languages. But they can be written in almost any language you’re comfortable or proficient with.

As Tim Boronczyk pointed out in September 2013, there are a wide range of meaningful purposes which hooks can be put to. These include linting, spell-checking commit messages, checking patches against accepted coding standards, running composer, and so on.

Now, PHP’s a great language, don’t get me wrong, but it’s not necessarily the best language for shell scripting. Admittedly, it’s gotten a lot better than it once was. But compared to languages such as Bash, Python, and Ruby, it hasn’t been quite as suitable for creating Git hooks; that is, until now.

Thanks to Static Review, by Samuel Parkinson, you can now write Git hooks with native PHP, optionally building on the existing core classes. In today’s post, I’m going to give you a tour of what’s on offer, finishing up by writing a custom class to check for any lingering calls to var_dump().

Installing the Library

Like most, if not all modern PHP libraries and packages, StaticReview is installable via Composer. To install it in your project, run composer require sjparkinson/static-review in the root of your project. With that, let’s get going.

Continue reading %Writing PHP Git Hooks with Static Review%

JSON Validation by Committee

Mo, 2015-08-31 14:00

In my previous post, I went through the paces of creating a JSON Schema to describe the JSON that my service will accept and return. The process leans on the prmd gem to supply the initial JSON Schema templates, as well as validation and document generation. All in all, it's a process that feels like it should be more automated. I went through a fair amount of pain to get the schema created, manually defining types and links in my text editor. At the end of the effort, I have a .json file that describes what my API will accept and return, as well as matching Markdown documentation to boot.

In that post, I made promise of something better. A land where writing unit tests that verify the JSON returned by my Rails API is possible. A land where the production application will reject requests that do not conform to our JSON schema. Does that sound like a wonderful place? It does to me.

This post will build that land, showing you how to feed the schema into tools provided by the committee gem, using those tools to verify tests and application requests.

Continue reading %JSON Validation by Committee%

Five Fantastic Editorial Calendars For Content Makers

So, 2015-08-30 12:55

He who controls the spice controls the universe. Now swap spice for content and universe for Internet, and you'll begin to understand just how important content has become in the digital age. Planning, assigning, creating, scheduling and publishing content – the five major stages of content production – can quickly get out of hand if […]

Continue reading %Five Fantastic Editorial Calendars For Content Makers%

Build a Countdown Timer in Just 18 Lines of JavaScript

Fr, 2015-08-28 18:00

Sometimes in life, you’re going to need a JavaScript countdown clock for something other than a doomsday device. Whether you have an event, a sale, a promotion, or a game, you can benefit from building a clock in raw JavaScript rather than reaching for the nearest plugin. While there are many great clock plugins, here are the benefits you’ll get from using raw JavaScript:

  • Your code will be lightweight because it will have zero dependencies.
  • Your website will perform better because you won’t need to load external scripts and style sheets.
  • You’ll have more control because you will have built the clock to behave exactly the way you want it to (rather than trying to bend a plugin to your will).

So, without further ado, here’s how to make your own countdown clock in a mere 18 lines of JavaScript.

Basic Clock: Count down to a Specific Date or Time

Here’s a quick outline of the steps involved in creating a basic clock:

  • Set a valid end date.
  • Calculate the time remaining.
  • Convert the time to a usable format.
  • Output the clock data as a reusable object.
  • Display the clock on the page, and stop the clock when it reaches zero.
Set a Valid End Date

First, you’ll need to set a valid end date. This should be a string in any of the formats understood by JavaScript’s Date.parse() method. For example:

The ISO 8601 format:

var deadline = '2015-12-31';

The short format:

var deadline = '31/12/2015';

Or, the long format:

var deadline = 'December 31 2015';

Each of these formats allows you to specify an exact time (in hours minutes and seconds), as well as a time zone (or an offset from UTC in the case of ISO dates). For example:

var deadline = 'December 31 2015 23:59:59 GMT+02:00';

You can read more about date formatting in JavaScript in this article.

Calculate the Time Remaining

The next step is to calculate the time remaining. To make that happen, we need to write a function that takes a string representing a given end time (as outlined above), and calculate the difference between that time and the current time. Here’s what that looks like:

function getTimeRemaining(endtime){ var t = Date.parse(endtime) - Date.parse(new Date()); var seconds = Math.floor( (t/1000) % 60 ); var minutes = Math.floor( (t/1000/60) % 60 ); var hours = Math.floor( (t/(1000*60*60)) % 24 ); var days = Math.floor( t/(1000*60*60*24) ); return { 'total': t, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds }; }

First, we’re creating a variable t, to hold the remaining time until the deadline. The Date.parse() function is native JavaScript that converts a time string into a value in milliseconds. This allows us to subtract two times from each other and get the amount of time in between.

var t = Date.parse(endtime) - Date.parse(new Date()); Convert the Time to a Usable Format

Now we want to convert the milliseconds to days, hours, minutes, and seconds. Let’s use seconds as an example:

var seconds = Math.floor( (t/1000) % 60 );

Let’s break down what’s going on here.

  1. Divide milliseconds by 1000 to convert to seconds: (t/1000)
  2. Divide the total seconds by 60 and grab the remainder—you don’t want all of the seconds, just the ones remaining after the minutes have been counted: (t/1000) % 60
  3. Round this down to nearest whole number—because you want complete seconds, not fractions of seconds: Math.floor( (t/1000) % 60 )

Repeat this logic to convert the milliseconds to minutes, hours, and days.

Output the Clock Data as a Reusable Object

With the days, hours, minutes, and seconds prepared, we’re now ready to return the data as a reusable object:

return { 'total': t, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds };

This object allows you to call your function and get any of the calculated values. Here’s an example of how you’d get the remaining minutes:

getTimeRemaining(deadline).minutes

Convenient, right?

Display the Clock and Stop It When It Reaches Zero

Now that we have a function that spits out the days, hours, minutes, and seconds remaining, we can build our clock. First we’ll create the following HTML element to hold our clock:

<div id="clockdiv"></div>

Then we’ll write a function that outputs the clock data inside our new div:

function initializeClock(id, endtime){ var clock = document.getElementById(id); var timeinterval = setInterval(function(){ var t = getTimeRemaining(endtime); clock.innerHTML = 'days: ' + t.days + '<br>' + 'hours: '+ t.hours + '<br>' + 'minutes: ' + t.minutes + '<br>' + 'seconds: ' + t.seconds; if(t.total<=0){ clearInterval(timeinterval); } },1000); }

This function takes two parameters: the id of the element that will contain our clock and the end time of the countdown. Inside the function, we’ll declare a variable called clock and use it to store a reference to our clock container div so that we don’t have to keep querying the DOM.

Continue reading %Build a Countdown Timer in Just 18 Lines of JavaScript%

Watch: Combining Dynamic Strings with Python

Fr, 2015-08-28 17:30

Imagine we've been tasked with creating a company slogan. To allow some parts to change, we'll use variables. Combining all of these parts into a great looking slogan will be done using string concatenation. Let's jump in and see how its done.

Imagine we've been tasked with creating a company slogan. To allow some parts to change, we'll use variables. Combining all of these parts into a great looking slogan will be done using string concatenation. Let's jump in and see how its done.

Loading the player...

Continue reading %Watch: Combining Dynamic Strings with Python%

Logging with Monolog: From Devtools to Slack

Fr, 2015-08-28 16:00

Logging is an important part of the app development/maintenance cycle. It’s not just about the data you log, but also about how you do it. In this article, we are going to explore the Monolog package and see how it can help us take advantage of our logs.

Installation

Monolog is available on Packagist, which means that you can install it via Composer.

composer require 'monolog/monolog:1.13.*'

However, there is a great chance that you’re using a framework for your app. Monolog provides a list of integrations for most popular frameworks. I’m using Silex for this demo, but I won’t be using the provided integration to show how you can configure Monolog for any of your apps.

The Logger

When you create a new logger, you should give it a channel name. This is how you distinguish your list of loggers. I will bind my logger to the app container.

// app/bootstrap/container.php $logger = new \Monolog\Logger('general'); $app->container->logger = $logger;

Because Monolog is PSR-3, you can be sure that you are adhering to the PHP-FIG standards. This will allow you to switch to any other implementation if you don’t feel comfortable with Monolog (I don’t see any reason why you wouldn’t). You can now start logging using one of the following methods, depending on your log level. (log, debug, info, warning, error, critical, alert, emergency).

Continue reading %Logging with Monolog: From Devtools to Slack%

Generating a Useful Style Guide with Sketch App

Fr, 2015-08-28 15:00

When it comes to designing large multi-artboard websites in Sketch App, Shared Styles, Text Styles and Symbols are your biggest allies. Nobody wants to keep recreating those call-to-action buttons over and over.

And while we could simply group (command+g) these button layers together and duplicate (command+d), what happens when we decide that these buttons actually need to be another colour? Styles and Symbols allow us to make mighty artboard-wide changes to a specific element.

Classing Reusable Styles

I’m going to start off with a rather cliché “here’s one we did earlier”; if you want to follow along step-by-step you can download the sample .sketch file here.

Start by selecting the middle body of text under the heading. On the right-hand side (The Inspector), click the dropdown box that says “No Text Style”, and then “Create New Text Style”.

Give this style a name - I chose “Header Text”. If you ever want to reuse this style anywhere else in the design, you can simply click on that dropdown box again and select “Header Text”.

If you code any CSS, then you’ll already know that this is exactly how we use CSS classes, and it should feel re-assuringly familiar.

You might find what we just did incredibly boring, but I swear to you, its true beauty will be much more apparent later on.

Defining Entire Elements with Reusable Symbols

Now…Symbols.

Symbols can be applied to Groups of layers only (select multiple layers, then hit command+g), which comes in handy when you need to reuse elements containing multiple layers but you’re not willing to “flatten” them.

Lets try it out on the yellow button - click the same dropdown box that now says “No Symbol” and then “Create New Symbol”. Let's call it “Yellow Button”.

Again, we’ll only experience the true magic of this later on.

Explaining Your Styles with the Sketch Notebook

Knowing why a given style was originally created is often the biggest challenge in returning to project files/graphics. At the time it was probably abundantly clear that the 'red buttons are for sale items' – but 7 months later someone is staring at those red buttons with a furrowed brow. What does it all mean??

Sketch Notebook is an add-on that’s going to let us leave comments on our artboards. For those that use our .sketch file afterwards, they’ll need to refer to these comments as a style guide when building upon the design or developing it with code.

First, navigate to PluginsReveal Plugins Folder, and then download the Sketch Notebook Plugin into that folder. If you use a plugin management interface such as Sketch Toolbox, you’ll find Sketch Notebook is downloadable from there too.

When you’re all set, click on the yellow button once again and run the keyboard shortcut; command+option+control+9.

Your comment should already have a title and it’ll be referenced by the number one. Add your comment, something along the lines of “Should be used as a call-to-action in the green header only.”

You'll notice that Sketch Notebook will automatically append a sidebar to the right-hand side of your artboard; the yellow button will have a “1” next to it that references your notebook comment.

Bonus: Creating a Separate Style Guide Artboard

Press “A” to begin choosing a new artboard. It doesn’t really matter what size the artboard is because this’ll only be an artboard for housing our reusable user interface elements as a separate style guide that can be referred to later on. You can declare sizes and a background colour in The Inspector.

Now we’ll start clicking on the elements that we want to copy over to our style guide artboard, in our case this is the “Header Text” and “Yellow Button”. Right-click and choose “Copy”, and then right-click again on our new artboard and choose “Place Here”. In the Layers Panel (on the left), double-check that we’re copying into the correct artboard; a simple drag and drop from the Layers Panel will do the trick.

As you can see from the screenshot image above, I’ve used The Inspector to change the background colour of the button. Since the (imaginary) client has requested that all buttons now be black, it’s highly convenient that all of our buttons are linked by a common Symbol - “Yellow Button” - which triggers a document-wide change.

Continue reading %Generating a Useful Style Guide with Sketch App%

Push Notifications in Ionic Apps with Google Cloud Messaging

Fr, 2015-08-28 15:00

In this tutorial we're going look at how to implement push notifications in an Android App using the Google Cloud Messaging Platform. We will be using the Ionic framework and Cordova to create the app. The server component will be implemented using Node. You can checkout all the code for the project that we will be building from Github.

Continue reading %Push Notifications in Ionic Apps with Google Cloud Messaging%

Phoenix for Railsies: Form Helpers and Models

Fr, 2015-08-28 14:00

Phoenix is a web framework built for Elixir, an awesome language that’s built on the Erlang Virtual Machine. Coming from a Rails background, Phoenix seems immediately familiar. Although it is missing a few of the niceties that Rails gives us, Phoenix has excellent support for technologies such as WebSockets, which makes it a great candidate […]

Continue reading %Phoenix for Railsies: Form Helpers and Models%

Laugh Your Way to More Sales: How to be Funny

Fr, 2015-08-28 03:24

If you can make someone laugh, you can make them do anything. Likability matters – in business, in love, basically, everything in life requires you to be likable by other people. One easy way to be likable is to make people laugh. Yes, there are some anomalies, who don’t like to laugh, and I’d recommend […]

Continue reading %Laugh Your Way to More Sales: How to be Funny%

Introduction to the MEAN Stack

Do, 2015-08-27 20:00

It was a long time ago since the acronym LAMP (Linux Apache MySql PHP) was created. Today another very common stack is the MEAN stack. Probably not all of you know what that the acronym “MEAN” stands for, so let's start with the basic. MEAN stands for MongoDB, Express, AngularJS and Node.js. It deals with a full stack JavaScript solution for building websites and web applications. From the database to the back-end code and the front-end code, everything is written using JavaScript. In case you aren’t familiar with the technologies used by the MEAN stack, you can find a short introduction about these technologies in the following section.

MEAN

M stands for MongoDB, the world’s leading NoSQL database. That’s a kind of document type database that stores its data into a JSON-like formatted binary file called BSON (Binary JSON). It’s easy to use, and for JavaScript developers it should be as simple as working with JSON.

E stands for Express, a lightweight, minimalist framework built for Node.js. It’s been created for web applications and APIs, and comes with a myriad of HTTP facilities for the developer.

A stands for AngularJS, the Model-View-Whatever JS framework build by Google. AngularJS makes API consuming as simple as it could be, so using it as the client-side of MEAN is very helpful for every developer. Moreover, AngularJS is optimized for mobile development, so by using the same code base on the browser, you have already built a mobile app for the web application you’re developing.

N stands for Node.js, the foundation of Express. It runs on Chrome’s V8 engine and is capable of non-blocking, event-driven I/O. The Node.js application will handle multiple requests on a single service without them blocking each-other (hence non-blocking).

Continue reading %Introduction to the MEAN Stack%

An Editable Grid with jQuery, Bootstrap, and Shield UI Lite

Do, 2015-08-27 18:30

In this short tip, I provide a few easy steps to set up an editable grid (or table) using Bootstrap and Shield UI Lite.

Shield UI Lite is an open source jQuery library that includes, among other components, a jQuery grid. The grid supports editing out-of-the-box, as well as sorting, grouping, and different column editors.

About Shield UI Lite

Shield UI is a web component development company that specializes in the design, development, and marketing of UI widgets for pure JavaScript development, as well as for development in ASP.NET, ASP.NET MVC, and Java Wicket. The company offers Data Visualization components, as well as a whole array of standard web development components, such as grids, barcodes – one and two dimensional, extended input components – such as numeric and masked textboxes, and many more.

The Shield UI Lite Suite is one of the newest open source libraries on the market and what is specific about it is that it contains a wealth of components, all of which are feature rich and mature. This includes the jQuery Grid, which supports all important web grid operations out-of-the-box. The component supports editing with either inline or standard edit form editing, as well as editing with an external form. Also supported is cell editing.

In addition to this, the Shield UI Grid has a built-in datasource component, which facilitates the binding to all types of data – from local JSON structures, to remote web services; the built-in DataSource also takes care of all delete, update and insert operations.

For data-heavy applications, the Shield UI jQuery widget offers an enhanced virtual scrolling feature significantly improves performance, even when working with millions of real data records. To see more examples of the component and its options, you can refer to the online demos or the documentation.

Using the Code

For the editable grid that we’ll be creating, I’m using a local data source in order to keep things simple. The source code for the libraries can be found on GitHub. The full sample code, along with all sample data used, as well as additional CSS is available in the CodePen demo.

The first step in setting up the layout is to use a standard Bootstrap container. In our case, this is a div with a Bootstrap panel nested inside. Since any standard web grid component usually hosts a lot of data, our layout spans the full width of the screen.

The code for this step is straightforward and looks like this:

[code language="html"]
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="text-center">Bootstrap Editable jQuery Grid
<span class="fa fa-edit pull-right bigicon"></span></h4>
</div>
<div class="panel-body text-center">
<div id="grid"></div>
</div>
</div>
</div>
[/code]

This is all the HTML needed to set up the sample. The next step is adding references to all the resources used in the sample, such as stylesheets, JavaScript files, and data.

The data used for the example is a standard JSON collection, which is loaded separately in order to be passed to the grid component. Using a local data source simplifies the setup. Additionally we need the stylesheet for the grid and the JavaScript for initializing it.

The inclusion of these resources is demonstrated below:

The CSS:

[code language="html"]
<link rel="stylesheet" href="shieldui-lite.min.css">
[/code]

The scripts:

[code language="html"]
<script src="shieldui-lite-all.min.js"></script>
<script src="shortGridData.js"></script>
[/code]

Setting up the Grid

The next step in the process is setting up the Shield UI Lite grid component. Once we have included the necessary resources, we can initialize it with some JavaScript in the document.ready handler.

There are two logical parts in describing the component. The first is handling the datasource for the data that will be visualized in the grid, and the other one is setting up the columns, which will be actually rendered, as well as any additional settings, such as sorting, hover effects, etc.

Continue reading %An Editable Grid with jQuery, Bootstrap, and Shield UI Lite%

Using Sass’s @error, @warn, and @debug Directives

Do, 2015-08-27 00:00

Feedback methods are essential in any programming language. In JavaScript, you’ve probably used console.log() or maybe alert(). In PHP, you can use var_dump() or print_r(). In Ruby, you may use debug or inspect. All these functions allow you to debug any value and find out what your code is doing at any point in the logic where you need help.

Sass has three directives for providing feedback to developers. They are @error, @warn, and @debug. In this post, we’ll look at how to use these directives, what use cases they’re best suited for, and what kind of feedback they can provide for other developers who use our code.

Basic Syntax and Use

All three of these directives follow the same syntax:

[code language="sass"]
@directive "String of text to output.";
[/code]

If you need to interpolate a variable’s value in that string, you can do so using the standard Sass interpolation (#{$variable}) and the value will be printed in the string. With this method, you can tell a developer both the name of the variable and its current value:

[code language="sass"]
@error "Sorry, but `#{$variable}` is not a valid value for $variable.";
[/code]

Note that the ticks (`) around the interpolation are not required. You may want to include them because they give the developer an obvious start/stop point for the variable’s contents.

If a developer makes a mistake when using your Sass code, these directives will send the specified message to the compiler and the compiler will show that message to the developer. For example, GUI apps (like CodeKit) will show a system notification with the error. Certain Grunt and Gulp notification packages can do that as well.

If a developer is compiling with the command line (Sass, Compass, Grunt, or Gulp), the message will likely end up in their console (Terminal, iTerm2, Putty, etc). If you’re writing Sass online with Sassmeister or Codepen, you’ll only get limited feedback, but you may get an inline notification in your editor or text in the output window.

Now that we know how to write @error, @warn, and @debug messages and where they’ll appear for the developer, let’s look at the difference between these directives and the best uses for each one.

Stop Everything – The @error Directive

Sass’s @error directive stops the Sass compiler completely and sends its string of text to the compiler’s output as a fatal error. Use this directive when you need to send a message that stops the developer immediately and forces them to correct their mistake right away. This is ideal for letting a developer know they’ve done something wrong or entered a value that’s entirely incompatible. Sass will include the line number with any fatal error, including @error output. The @error directive is ideal for validating arguments within a mixin or function.

Note: If your compiler is older than Sass 3.4 or LibSass 3.1, @error is not available. You can use this log() function to emulate @error in older Sass versions.

As an example, if you’ve written a function that relies on a certain input format for its calculations, you can validate the input and use @error to stop the compiler and alert the developer that they’ve made a mistake that can’t be overlooked. If you’ve written a function that relies on a key/value pair from a map, @error can make sure that the key that’s called from the map actually exists.

This Sass color management tool uses @error to ensure that the developer only uses a color name that’s a valid CSS color name or a key from a related map:

Map:

[code language="sass"]
$colors: (
brand-red: #c0392b,
brand-blue: #2980b9,
text-gray: #2c3e50,
text-silver: #bdc3c7
);
[/code]

Function:

[code language="sass"]
// Ignore the `$variation: false` bit here,
// or read the post for more information.

@function color-variation($color, $variation: false) {
@if map-has-key($colors, $color) {
$color: map-get($colors, $color);
} @else {
@if type-of($color) != color {
@error "Invalid color name: `#{$color}`.";
}
}
}
[/code]

Usage:

[code language="sass"]
.element {
color: color-variation(brand-orange);
}
[/code]

Output:

[code language="bash"]
>> Invalid color name: `brand-orange`.
>> Line 9 Column 7 sass/test.scss
[/code]

In this example, if the developer tries calling the color-variation() function with a string that’s neither a valid CSS color nor a key from the $colors map, there’s nothing Sass can do to output a valid color. Using @error gives the developer specific, actionable feedback.

Continue reading %Using Sass’s @error, @warn, and @debug Directives%

Getting Hired as a Developer: Tips from Senior Recruiters

Mi, 2015-08-26 22:00

There's no magic bullet for getting hired as a developer. But there is some great advice available to help in the process.

I recently interviewed Matt Langan and Christian Macolino, two Senior Tech Recruiters over at Atlassian. I wanted to get a realistic understanding of the subject from the perspective of the people involved with hiring tech talent for a $3.3 billion software company.

This article looks at issues surrounding getting hired, including some practical tips and pointers that arose out of the interview.

Resumes and Online Portfolios

Let's start with tried-and-tested resumes and portfolios. Through these, we present everything that's important about us to recruiters, interviewers, and anyone else involved in the hiring process.

Often developers invest more time in this portion of job hunting than in the actual searching process.

Digital or traditional?

When looking for a position with a tech company in particular, we might assume that digital portfolios—personal websites and online resumes—would be preferred to standard-format resumes. But that's not always the case. Especially for non-design roles, recruiters care more about just getting the information they need.

Christian phrased it this way:

As long as we've got the data there—enough information that we can dig into about their experience, and ask the right questions—that's all that we care about.

This also applies for smaller firms, or non-tech companies whose hiring processes involve more managerial oversight and less tech.

However, for those smaller companies, the online portfolio may be as important or more so. With less expertise and testing available to gauge your worth, a company may resort to carefully analyzing your past work even more than a large tech company might. Only you can judge how much time each of these tools is worth—by carefully considering what your target positions are.

Choosing Your Path

When we discussed education and the very first positions that developers take on, Matt had the following advice regarding education and getting started:

Get involved in side projects, hobbies, start a blog, join in on discussions on forums, get involved with Stack Overflow or Github, ask questions, provide answers, take part in coding competitions, go to tech meetups.

In your current job, master what you're doing, ask for more responsibility, and help others learn—particularly those more junior to you.

This, of course, is excellent advice. If you've been hired for a particular discipline, use your side projects not only to keep up with that core language or tool, but also to spread out your knowledge base and gain at least a basic understanding of some other languages, software, and other tools.

Constant learning is critical. On the point of continual education, Christian had a sobering point:

The first five years of your career really set the stage. In a new role or area, you're like a sponge, you're open to learning, you're curious, you ask questions.

But after the four or five year mark, you start to know a lot, people look to you for guidance, and your learning starts to switch off a little bit. So if you learn bad practices and bad habits early on in your career, you'll actually carry those with you.

Self assessment

For those already beyond that point, maybe this is time for some self-assessment.

Take a moment to consider where you are in your career. Are you still learning from your coworkers, your users, and your projects? Are you self-improving and growing through personal side projects? Do you still have a passion for your work?

Find the passion

It seems to be a common factor with a lot of companies that a passion for development is critical. Sometimes, especially for junior roles, it can even matter more than the specifics of education or knowledge.

Yet many of us are so caught up in the job security quest that we forget what drew us to programming in the beginning. We fail to realize sometimes that the passion and drive that got a lot of us here is what employers want.

Make a change

If you're already employed as a developer, and you're not still learning, and you're no longer passionate about your career, then consider what you can do to extract yourself from that position and change things. It could be as simple as an attitude shift or a change in responsibilities at your current workplace. It could be as dramatic as switching positions, employers, or even career paths.

Sometimes the hardest part is simply making the change. Beware of sticking with the status quo just because it's easier.

Continue reading %Getting Hired as a Developer: Tips from Senior Recruiters%

Responsive Web Design: Where Do We Go From Here?

Mi, 2015-08-26 21:00

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

I had the great pleasure of delivering the closing keynote at Responsive Day Out 3: The Final Breakpoint. Held in Brighton, UK on 19 June 2015, the conference is a gathering of designers and developers sharing their workflow strategies, techniques, and experiences with responsive web design.

Here’s what I had to say.

Today has provided an amazing tour of the world of responsive design. We’ve seen how to level-up our workflows and processes. We’ve learned new ways to improve the accessibility of our products. We’ve grappled with modern CSS and HTML capabilities that help us embrace the hugely variable display sizes that swirl and whirl around us.

We’ve explored the future of modular code and browsers’ capacity for working without network connectivity. And we’ve even taken a trip into the possible future of where the web might go.

We’ve come a long way since Ethan’s article, fluid grids, flexible media, and media queries. Those three tenets sowed a seed that has grown and flourished as we have come to better understand the implications of device proliferation. We’ve seen that the web is capable of going anywhere and doing pretty much anything.

I would argue that “Responsive Web Design” was the first article that really managed to capture the concepts that John Allsopp had discussed so many years before in “A Dao of Web Design” and distilled them into something the design and development community could really sink their teeth into. It provided a concrete example of the web’s ability to flex and mold itself into whatever shape it needed to take on.

It was the first time many designers had come to terms with the idea that “experience” was not some monolithic thing.

Sure, many of us in the web standards community had been talking the talk and walking the walk with regard to progressive enhancement. And we were gaining converts, but progress was slow. Ethan demonstrated—directly and succinctly—what the progressive enhancement of visual design could look like.

Providing an identical experience for each and every human being that tries to access our sites would be impossible. There are simply far too many factors to consider. We’ve got screen size, display density, CPU speed, amount of RAM, sensor availability, feature availability, interface methods … breathe … operating system type, operating system version, browser type, browser version, plug-ins installed, network speed, network latency, network congestion, firewalls, proxies, routers, and probably a dozen other factors my mind is incapable of plucking amid the whirlwind of technical considerations.

And that doesn’t even consider our users.

When it comes to the people we need to reach for our work to actually matter, we have to consider literacy level, reading acumen, level of domain knowledge, cognitive impairments like learning disabilities and dyslexia, attention deficit issues, environmental distractions, vision impairment, hearing impairment, motor impairment, how much they understand how to use their device, how much they understand how to use their browser, how well-versed in common web conventions they are, and a ton of other “human factors”.

Every person is different and everyone comes to the web with their own set of special needs. Some are always with them, blindness for example. Others are transient, like breaking your mousing arm. Still others are purely situational and dependent on the device you are using at the time and its technical capabilities or constraints.

Trying to devise one monolithic experience for each and every person to have in every context that considers every factor would be impossible. And yet, Sir Tim Berners Lee had a vision for a web that was capable of going anywhere. Was he insane?

Sir Tim’s vision for the web was that content could be created once and accessed from anywhere. Disparate but related pieces of “hypermedia” scattered across the globe could be connected to one another via links. Moreover, they would be retrievable by anyone on any device capable of reading HTML. For free.

Ultimately, Sir Tim envisioned universal accessibility.

For a great many of us, ensuring our websites are accessible is an afterthought. We talk a good game when it comes to “user centered” this or that, but often treat the word “accessibility” as a synonym for “screen reader”. It’s so much more than that. “Accessibility” is about people. People consume content and use interfaces in many different ways, some similar and some quite dissimilar to how we do it.

Sure, people with visual impairments often use a screen reader to consume content. But they might also use a braille touch feedback device or a braille printer. They probably also use a keyboard. Or they may use a touchscreen in concert with audio cues. Or they may even use a camera to allow them to “read” content via OCR and text-to-speech. And yes, visual impairment affects a decent percentage of the populace (especially as we age), but it is only part of the “accessibility” puzzle.

The contrast between text and the background is an important factor in ensuring content remains readable in different lighting situations. Color choice is an accessibility concern.

The language we use on our sites and in our interfaces directly affects how easy it is for our users to understand what we do, the products we are offering, and why it matters. It also affects how we make our users feel about themselves, their experience, and our companies. Language is an accessibility concern.

The size of our web pages has a direct effect on how long our pages take to download, how much it costs our customers to access them, and (sometimes) even whether or not the content can be reached. Performance is an accessibility concern.

Continue reading %Responsive Web Design: Where Do We Go From Here?%

Introducing enquire.js

Mi, 2015-08-26 20:00

For some time now, I’ve been using the enquire.js library to augment the use of media queries in JavaScript. I’ve had a lot of success using the library in various projects, but most developers I’ve met confessed they’ve never used or even heard of it.

In this article, I want to introduce you the library, explain why and how you’d want to use it.

What is enquire.js?

enquire.js is a lightweight, pure JavaScript library for responding to CSS media queries. In my own words, enquire.js gives you additional functionality and flexibility on top of window.matchMedia() when working with media queries in JavaScript.

The library was written by Nick Williams and it’s been around for about three years, having a healthy amount of open source activity. Its aim is not to replace or polyfill matchMedia; rather, it exists to provide additional functionality around media queries that don’t exist natively.

Why Would I Use It?

There are lots of use cases where enquire.js could be used, including:

  • Move nodes around the DOM
  • Load supplementary content (e.g. ads) via Ajax
  • Load and run a JavaScript library (e.g. Packery) to enhance a page

Each of these use cases is covered in the following sections.

Continue reading %Introducing enquire.js%

5 Beautiful Hotel Themes for WordPress

Mi, 2015-08-26 19:15

Despite its original intended use as blogging software, WordPress has succeeded to surpass many expectations and serve for much more universal purposes, turning it into a “Jack of all trades”. In many cases, WordPress is able to save a lot of effort and money for a range of rather complex websites, which would require much more resources.

Check-in!

Hotel and accommodation websites are among the group of websites which don’t require highly complex website infrastructure. That said, it isn't always possible to meet requirements with a WordPress installation out-of-the-box. You might not be a hotel owner, but you may need to deal with a hotel project at some point. For this case, I will introduce you to a fine selection of tasty hotel themes for WordPress which will get the job done, no matter it's a 5 star hotel or an AirBnB-like hostel.

Hotel Master

Continue reading %5 Beautiful Hotel Themes for WordPress%