Monday, September 28, 2015

Origami: How to Build Terrific Prototypes in Minutes

Hello everyone. If you are just joining the Origami party I suggest you first read the first part of this series “App Prototyping: Getting started with Facebook Origami”, which will introduce you to the Origami and Quartz Composer philosophy, GUI and teach you how to get up and running with you first Origami project.

What Are We Making?

In this article, I'd like to show you how to put together an attractive prototype equipped with animations and interactions in a few easy steps.

[caption id="attachment_115723" align="alignright" width="325"]Animation: Demoing of the prototype Let's make this![/caption]

There is no better way to learn than by doing, so for this tutorial we will be prototyping a vacation photo sharing app.

For your convenience, if you don’t want to go through the trouble of designing a lookalike app just to follow this tutorial, you can find all the assets used in our example below by following this Link.

Before we start

Before we get going, there are a few key points that you'll find helpful in understanding the way Origami works.

Coordinates

[caption id="attachment_115732" align="alignright" width="200"]Co-ordinates system explained. The origin of the plane (x=0;y=0) is in the center of the devices screen.[/caption]

The first item you should keep in mind is the coordinates system. In contrast to building with quartz composer patches, Origami patches such as Layer/Layer Group or Text Layers use pixel coordinates.

Progress Values

Values in the range of 0 to 1 are a common concept in Origami prototyping. When putting together an animation you will need to wire a 'switch patch' that triggers either a 0 or 1 and is connected to a transition in which you configure different animation properties.

Like a common light switch, switches can only be in one of two positions – values of either 0 or 1, or ON and OFF, or Start and Finish. Switches are commonly used as triggers for other patches.

[caption id="attachment_115729" align="alignright" width="234"]A switch patch A switch patch is the most common use case of the binary values 0 and 1 portrayed as ON and OFF state.[/caption]

Keyboard Shortcuts

Luckily Origami comes equipped with a lot of keyboard shortcuts that speed up the prototyping process even more.

Shortcuts can be used when hovering the mouse over the work canvas.

You can find a full list of these shortcuts at the Origami's official documentation page by following this link.

A few example shortcuts taken from the documentation.

Folder Structures

While the location of your assets doesn’t directly affect the development of your prototype, it is convenient to keep all of your assets in one folder with the Origami project. So, just in case you mess up the wiring of a patch, you can just remove the layer completely and easily re-add it in the project again.

[caption id="attachment_115730" align="aligncenter" width="550"]A demo project structure A demo project structure.[/caption]

Let's start prototyping

First we need to start a new Origami Project. If you don’t know how to do that, follow the instructions on the first article of this series as we mentioned earlier.

[author_more]
App Prototyping: Getting Started with Facebook Origami
Prototyping for Android with Material Design
The 100 Year Old Trick to Writing at 240 Words Per Minute
[/author_more]

When starting a new project, I like to import all of the image layers that I intend to use and arrange them how they will logically appear in the prototype.

This saves a lot of time when you are dealing with a smaller project with just a few components like the one we are using in the example.

You can add an image layer by dragging and dropping pictures straight into the canvas. Alternatively, you can manually add an image layer from the patch explorer window.

[caption id="attachment_115721" align="aligncenter" width="640"]Importing all media used in our prototype Importing all media used in our prototype.[/caption]

Since we are building a 2-page prototype, it is good practice to use 'Layer Group Patches' so we don’t get lost in all the wiring that will go on for each page. Create a layer group patch by pressing 'G' on your keyboard (or by dragging and dropping the patch from the patch inspector).

After successfully adding the images in the Layer Group patch, you will notice that the Layer Group contents are not being rendered in the viewer. Don't panic!

The issue is we haven’t yet told Origami to render the output that comes from the layer group patch on the device screen. To do this, we must add a new layer patch and wire the Image output of the Layer Group patch into the input image property of the Layer patch as shown in the GIF below.

Wiring patches

After dividing the components of the second page and adding them to the layer group, you will notice that the items on the second page overlap those of the first.

There are many ways to solve this depending on what you are trying to achieve. Since we want the second page to slide in horizontally, we can move it out of the way by changing the X-position property of the patch to -800. Easy.

To configure and change patch properties, just click the patch inspector icon in the canvas window.

[caption id="attachment_115727" align="aligncenter" width="640"]Opening the Patch Inspector Opening the Patch Inspector[/caption]

Great! Now we want to go to that second page when tapping the “Explore Now” button on the app's welcome screen. We also want the second screen of the app to slide in elegantly – maybe even with a groovy little bounce while it does so.

To accomplish that we are going to drop 5 patches into our work canvas. Don't worry if this sounds a little complex or overwhelming – you will see that it is fairly easy to wire them together once you understand the logic.

What we will be using

In the Patch Explorer window you are going to search for the following five patches:

  1. Hit Area patch: This is the place on the screen where you want to catch events
  2. Interaction 2 patch: This patch catches interaction events from a layer patch (or the whole screen if not connected to any patch).
  3. Switch patch: Switch patch uses exactly like a light switch. It starts out as off and when you flip it will turn on.
  4. Transition patch: This patch takes a number in the range of 0 to 1 and converts it to a number within a range starting with Start Value and ending in End Value.
  5. Pop Animation patch: This patch animates a changing value with a spring.

Connecting the Dots

We've got our patches – it's time to wire them together.

First we set up our Hit Area patch on top of the “Explore Now” button to catch the Tap event through the Interaction patch.

After the Interaction patch catches the tap event on the hit area, it will trigger the ON state in our Switch patch, which will then send a value of 1 to the transition patch. This tells the transition patch to start increment from -800 to 0.

These incrementing numbers will be passed through a pop animation, the progress of which will be wired to the X-position of the Layer it's connected to.

For this effect to work like the example, you should first change the patch properties of the Layer Group (which contains the output of our second page) to -800 X-position and give it an Anchor Point of the value of Center.

[caption id="attachment_115724" align="aligncenter" width="985"]To achieve the exact same results, copy the same properties for the patches below To achieve the exact same results, copy the same properties for the patches below.[/caption]

Since we have set the start value of the transition to -800, the Layer patch will zoom in from -800px horizontally off screen, before bouncing to a stop in the center of screen, thanks to our Pop Animation patch. To achieve the same effect to the example prototype, just change the Bounciness to 20 and Speed to 6 of the Pop Animation patch (but feel free to tweak it).

Continue reading %Origami: How to Build Terrific Prototypes in Minutes%


by Mateo Prifti via SitePoint

How to Solve Coding Anti-Patterns for Ruby Rookies

Ruby Rookies

As a freelance developer, I often work with developers from different programming backgrounds and of different skill-levels. Over time, I've learned to tell a programmer's Ruby level of experience by looking at the code they've written. Not only that, I can also place a safe bet on the programmer's coding background based on certain patterns within the code that give subtle clues as to the coder's previous programming experiences. There are certain coding practices that Ruby Rookies tend to employ often. Let's call these anti-patterns. This post enumerates the most common of these anti-patterns.

Continue reading %How to Solve Coding Anti-Patterns for Ruby Rookies%


by Fred Heath via SitePoint

Improving SEO Using Nginx

Search engines exist so that humans can better look for content that they desire.

Search engine optimization is about making your website easier to understand for the crawler bots! It is about making modifications to your website, to help improve your site's user experience and performance. It should be remembered that a site should be optimized first for its users. They are the consumers of the site, and are using a search engine only to get to it.

You are most likely aware of SEO techniques with many essential elements of a web page, but might not be making the most of them. Every site needs its own optimization techniques based on content, usage, etc. Let's see how all the awesome features of Nginx help improve SEO.

Setting Max-Age Expiry Header

Setting max-age header, for static content, is one of the most effective ways to speed up the website. If someone uses a site frequently, then static content like images and CSS are not requested again from the user, but used from the local cache. 

This can be easily achieved by mentioning in the location directive that serves static files:

The max parameter sets “Expires” to the value Thu, 31 Dec 2037 23:55:55 GMT. Do not forget to reload Nginx after these changes! 

You can verify the change by sending a curl request to the resource and inspecting the response headers to have a Cache-Control max-age header with the specified value. Also, if you use Chrome Developer Tools, you should see subsequent requests to that resource being returned with a 304 (Not Modified) response status.

Gzip Pre-Compression

The amount of data downloaded by browsers to render a page is steadily increasing. Given that we can't shrug away from reducing data, the only other way is to reduce its size for network transit.

To be able to serve gzip'ed content using Nginx, you will need to recompile Nginx with the following flags:

Now, we will need to compress all the static files (using the gzip command), place them in the same directory, and make these changes to nginx config:

With this enabled, Nginx will always look for a pre-compressed file.

Removing Whitespace

HttpStripModule removes whitespace (spaces, tabs, and new lines) from HTML documents. In combination with the gzip pre-compression module above, it can speed up your websites by a substantial amount.

Etags for Static Content

Etags are unique IDs representing the current state of the URL. They are used for cache validation, and can help save substantial bandwidth. 

You can use the following setup in Nginx to enable Etags.

Profile Workers Using Google Performance Tools

Once you start using Nginx to its capacity, you'll want to look at how well Nginx is doing its job, so it's important to gather analytics about Nginx itself. For that, we can use Google Performance Tools. The module is not built with default Nginx and can be enabled by doing this:

Remember to restart Nginx after changing the config to include:

This simple change will help us in profiling Nginx workers.

WWW to Non-WWW Redirects

For crawlers, a www domain is different from non-www, i.e. tutsplus.com is different from www.tutsplus.com. Technically, they are separate entities. A search engine can detect copied content, and this can negatively affect the site's ranking. To avoid these things, it is important to decide on standard naming and use it throughout.

As an example, let's use non-www as what we want to achieve. This can be easily achieved by using a rewrite rule:

In addition to all these, you can also achieve some interesting things using modules like:


by Nishant Modak via Tuts+ Code

#DelhiCarpools

#DelhiCarpools

Interactive One Pager by Tapan Babbar encouraging "Carpooling" to work in Delhi. The site features a unique feature where you need to hold down a key to keep carpooling.

by Rob Hope via One Page Love

PostCSS Quickstart Guide: Instant Setup Options

Using the Citrix Webinar API in WordPress

WP_Query Arguments: Taxonomies

So far in this series, you've learned how WP_Query is structured and what its properties and methods are. Now we're looking at the various arguments you can use with WP_Query and how you code them.

WP_Query has a large number of possible arguments, which makes it extremely flexible. As you can use it to query just about anything held in your wp_posts table, it has arguments for every permutation of query you might want to run on your content.

In this tutorial I'll look at arguments for querying taxonomy terms.

A Recap on How Arguments Work in WP_Query

Before we start, let's have a quick recap on how arguments work in WP_Query. When you code WP_Query in your themes or plugins, you need to include four main elements:

  • the arguments for the query, using parameters which will be covered in this tutorial
  • the query itself
  • the loop
  • finishing off: closing if and while tags and resetting post data

In practice this will look something like the following:

The arguments are what tells WordPress what data to fetch from the database and it's those that I'll cover here. So all we're focusing on here is the first part of the code:

As you can see, the arguments are contained in an array. You'll learn how to code them as you work through this tutorial.

Coding Your Arguments

There is a specific way to code the arguments in the array, which is as follows:

You must enclose the parameters and their values in single quotation marks, use => between them, and separate them with a comma. If you get this wrong, WordPress may not add all of your arguments to the query or you may get a white screen.

The Taxonomy Parameters

Setting parameters for taxonomy terms is a little more complicated than for categories and tags since you use tax_query. Within this argument you write a nested array of arguments to specify the taxonomy and term using these parameters:

  • taxonomy (string): Taxonomy.
  • field (string): Select taxonomy term by ('term_id (default), 'name' or 'slug').
  • terms (int/string/array): Taxonomy term(s).
  • include_children (boolean): Whether or not to include children for hierarchical taxonomies. Defaults to true.
  • operator (string): Operator to test. Possible values are 'IN' (default), 'NOT IN', 'AND'.

The fact that you have the operator parameter means you don't need to choose from one of a range of available arguments to define whether you're including or excluding terms (as you do for tags and categories), but use tax_query for everything taxonomy-related instead.

If you want to query for multiple taxonomies, you can also use the relation parameter before all of your arrays (one for each taxonomy) with AND or OR to specify whether you want to find posts with all of the terms or any of them.

This is most easily explained with some examples.

Querying for One Taxonomy Term

This is the simplest scenario and involves just using one nested array:

The above queries for posts with the my-term-slug term in the my-taxonomy taxonomy. Note that you also need to use the field parameter to identify which field you're using to identify the term, unless you're using the term ID which is the default. If you wanted to use the term ID you'd use something like this:

Using the ID makes it harder for you to identify what your query is looking for at a later date, but avoids any potential problems if you think your users might edit the term slugs.

Querying For Multiple Terms in One Taxonomy

If you want to identify posts with one or more of an array of terms in the same taxonomy, you still write one nested array, but add an array of terms.

For example, to query posts with any of a list of term IDs from your taxonomy, you use:

But what if you wanted to query posts with all of these terms? You'll need to use the operator parameter inside your nested array:

Note that the first example actually uses the IN operator to find posts with any of the terms, but as this is the default you don't have to specify it in your arguments.

Another scenario is if you want to query for posts which don't have any of an array of terms in one taxonomy, which you do like this:

Here I've replaced the AND operator with NOT IN, which means WordPress will find posts without any of the terms in the array.

Note that if you prefer to use slugs instead of term IDs, you can do so with any of these scenarios. The last example would look like this:

Another scenario is if you want to query for posts that have one term but not another. This uses the IN operator (which you don't need to include as it's the default), with a minus sign before the ID of any terms you want to exclude:

This queries posts with term 11 but not term 12.

Querying Terms From Multiple Taxonomies

If you want to work with more than one taxonomy, you'll need to create more than one array. Let's look at the simplest example, to query posts with one term from taxonomy1 and one term from taxonomy2:

Here I've written two nested arrays: one for each taxonomy, using the same arguments as I did for the examples using just one taxonomy. I've preceded these with the relation argument. You need to include the relation argument to tell WordPress whether it's looking for all or some of the posts output by each array. This works as follows:

  • If you use 'relation' => 'AND', WordPress will fetch the posts specified in the first array and the second array. So in the example above, only posts with both the slug-one slug in taxonomy1 and the slug-two slug in taxonomy2 will be queried.
  • If you use 'relation' => 'OR', WordPress will fetch posts output by the first array or the second array. So in this case you'll get posts with either the slug-one slug or the slug-two slug (or both).

This is the code you'd use if you were looking for posts with either of the two slugs:

You can also look for more than one term in a given taxonomy by adding it to the array:

By combining the relation argument with nested queries also using the operator argument, you can create quite complex queries. The arguments below would query posts with a term from one taxonomy but without a term from another taxonomy:

Note that I've used 'relation' => 'AND' here: if I used OR, it would query posts with slug-two and posts without slug-one, rather than posts which have slug-two but not slug-one, which is what I'm looking for. 

You could conceivably take this further to query your taxonomies' terms however you wanted: using the operator argument in both nested queries or adding an additional nested query to query terms in another taxonomy.

A Note on the tax Argument

You may be wondering why I haven't included the {tax} argument, where you simply write your argument as follows:

You may be familiar with this way of querying taxonomies if you've done it in the past, but it's now deprecated and you shouldn't use it. So stick to 'tax_query'! Using tax_query gives you a lot more flexibility anyway.

Summary

Querying taxonomies is a bit more complicated than categories and tags, as you need to get to grips with the tax_query argument.

However, as we've seen, this is a very powerful argument that gives you a lot of scope and flexibility to query your database in whatever way you wish.


by Rachel McCollin via Tuts+ Code