Thursday, January 28, 2016

Building a React Universal Blog App: A Step-by-Step Guide

When we think of single page applications (SPAs) we think browsers, JavaScript, speed and, in my case, invisibility to search engines. This is because a SPA renders a page's content using JavaScript and since web crawlers do not use a browser to view web pages, they cannot view and index the content. Or, to better say, most of them can't. This is a problem that some developers have tried to solve in various ways:

  1. Adding an escaped fragment version of a website which requires all pages to be available in static form and adds a lot of extra work (now deprecated).
  2. Using a paid service to un-browserify a SPA into static markup for search engine spiders to crawl.
  3. Trust that search engines are now advanced enough to read our JavaScript-only content (I wouldn't just yet).

Using Node.js on the server and React on the client, we can build our JavaScript app to be universal (or isomorphic). This could offer several benefits from server-side and browser-side rendering, allowing both search engines and humans using browsers to view our SPA content.

In this step-by-step tutorial I will show you how to build a React Universal Blog App that will first render markup on the server side to make our content available to search engines. Then, it will let the browser take over in a single page application that is both fast and responsive.

Continue reading %Building a React Universal Blog App: A Step-by-Step Guide%


by Tony Spiro via SitePoint

Free Icon Set: Star Wars and Marvel Superheros

marvel-superheroes-vector-icon-pack-preview

The cool peeps from Vecteezy, gave One Page Mania a couple exclusive icon sets to share with our readers. “Marvel Superhero” is an icon set of 16 icons in color and outline. These icons are flat style, with simple details.

The other icon set is “Star Wars” outline version, and come with 16 characters and logos.

Both sets include .AI, .PSD, .EPS and .PNG versions of the icons. The download link and preview are below, and you can check out Vecteezy for more vector icons.

 

marvel-superheroes-vector-icon-pack-preview

 

DOWNLOAD Marvel Icon Set

 

Star Wars flat vector icon set free

 

DOWNLOAD Star Wars Icon Set


by Michael via One Page Mania

Introduction to jCanvas: jQuery Meets HTML5 Canvas

HTML5 lets you draw graphics straight into your web page using the <canvas> element and its related JavaScript API.

In this post, I’m going to introduce you to jCanvas, a free and open source jQuery-based library for the HTML5 Canvas API.

If you develop with jQuery, jCanvas makes it easier and quicker to code cool canvas drawings and interactive applications using jQuery syntax.

What is jCanvas?

The jCanvas website explains:

jCanvas is a JavaScript library, written using jQuery and for jQuery, that wraps around the HTML5 canvas API, adding new features and capabilities, many of which are customizable. Capabilities include layers, events, drag-and-drop, animation, and much more.

The result is a flexible API wrapped up in a sugary, jQuery-esque syntax that brings power and ease to the HTML5 canvas.

jCanvas enables you to do everything you can do with the native Canvas API and more. If you prefer, you can also use native HTML5 Canvas API methods with jCanvas. The draw() method serves just this purpose. Furthermore, you can easily extend jCanvas with your own methods and properties using its extend() feature.

[author_more]

Adding jCanvas to Your Project

To include jCanvas in your project, download the script from the official website or the GitHub page, then include it in your project folder. As mentioned, jCanvas needs jQuery to work, so be sure to include that too.

Your project’s script files will look something like this:

[code language="html"]
<script src="js/jquery.min.js></script>
<script src="js/jcanvas.min.js></script>
<script src="js/script.js></script>
[/code]

The last one would be where you put your custom JavaScript using the jCanvas API. Now let’s take jCanvas for a test drive.

Setting up the HTML Document

To follow along with the examples, start by adding a <canvas> element tag to a basic HTML5 document.

[code language="html"]
<canvas id="myCanvas" width="600" height="300">
<p>This is fallback content
for users of assistive technologies
or of browsers that don't have
full support for the Canvas API.</p>
</canvas>
[/code]

Here are a few points of interest about the code snippet above.

  • By default, the dimensions of the <canvas> drawing surface are 300px by 150px. You can modify this default size in the width and height attributes inside the element’s markup.
  • Adding an id attribute is not required but will be an easy way to access the element with JavaScript.
  • Content inside the <canvas> element is just a bitmap image. This makes it inaccessible to users of assistive technologies. Also, browsers that don’t have support for the Canvas API will not be able to access its content or interact with it in any way. Therefore, while techniques aiming to make <canvas> more accessible are yet to be made available, adding some fallback content for this category of users is the recommended practice.

If you were to use the native Canvas API, your JavaScript would look something like this:

[code language="javascript"]
var canvas = document.getElementById('myCanvas'),
context = canvas.getContext('2d');
[/code]

The variable context in the code above stores a reference to the 2D context property of the Canvas object. It’s this property that enables you to access all other properties and methods exposed by the HTML5 Canvas API.

If you’d like to learn more about the topic, HTML5 Canvas Tutorial: An Introduction by Ivaylo Gerchev is a great read.

jCanvas methods and properties already contain a reference to the 2D context, therefore you can jump straight into drawing.

Drawing Shapes with jCanvas

Most jCanvas methods accept a map of property-value pairs that you can list in any order you like.

Let’s start by drawing a rectangle shape.

The Rectangle Shape

This is how you draw a rectangle shape using the drawRect() method of the jCanvas object.

[code language="javascript"]
// Store the canvas object into a variable
var $myCanvas = $('#myCanvas');

// rectangle shape
$myCanvas.drawRect({
fillStyle: 'steelblue',
strokeStyle: 'blue',
strokeWidth: 4,
x: 150, y: 100,
fromCenter: false,
width: 200,
height: 100
});
[/code]

The snippet above caches the canvas object into a variable called $myCanvas. The properties inside the drawRect() method are mostly self-explanatory, but here’s a brief rundown:

  • fillStyle sets the rectangle’s background color;
  • strokeStyle sets its border color;
  • strokeWidth sets the shape’s border width;
  • x and y set the coordinates corresponding to the rectangle’s horizontal and vertical position inside the canvas. A value of 0 for x and of 0 for y, i.e., (0, 0), corresponds to the top left corner of the canvas. The x coordinates increase to the right and the y coordinates increase towards the bottom of the canvas. When drawing the rectangle, by default, jCanvas takes the x and y coordinates to lie at the center of the shape.
  • To change this so that x and y correspond to the rectangle’s top left corner, set the fromCenter property to false.
  • Finally, the width and height properties set the dimensions of the rectangle.

Rectangle drawn on canvas with explanation of canvas coordinates system

Here is a demo with the rectangle shape:

See the Pen jCanvas example: Rectangle by SitePoint (@SitePoint) on CodePen.

Arcs and Circles

Arcs are portions of the rim of a circle. With jCanvas, drawing arcs is just a matter of setting the desired values for a few properties inside the drawArc() method:

[code language="javascript"]
$myCanvas.drawArc({
strokeStyle: 'steelblue',
strokeStyle: 'blue',
strokeWidth: 4,
x: 300, y: 100,
radius: 50,
// start and end angles in degrees
start: 0, end: 200
});
[/code]

Drawing arcs involves setting a value for the radius property as well as the start and end angles in degrees. If you’d like the direction of your arc to be counterclockwise, add the ccw property to the code above and set it to true.

Continue reading %Introduction to jCanvas: jQuery Meets HTML5 Canvas%


by Maria Antonietta Perna via SitePoint

MediumEditor – Simple Javascript Inline Editor

MediumEditor is a simple inline editor that is clone of Medium.com WYSIWYG editor. MediumEditor has been written using JavaScript, no additional frameworks required.


by via jQuery-Plugins.net RSS Feed

All You Need to Know About Estonia’s E-Residency Program

Estonia's Capitol, Tallin

Estonia has become the first country in the world to offer a transnational digital identity. It’s attracted the attention of entrepreneurs and digital nomads worldwide, but there’s still a huge amount of confusion about the benefits of the E-Residency Program and what e-residency actually means. Let's take a look.

What Is E-Residency?

It’s a way of accessing Estonia’s government services without ever actually visiting Estonia.

[author_more]

You can start a company with all the benefits of the EU legal framework as well as remotely access low maintenance administrative tools such as tax declaration and company formation. In 2009, Estonia broke a world record for the “fastest time to register a new legal entity” - 18 minutes.

In short, this beautiful Baltic country is offering remotely accessible services that would normally only be available to actual residents of Estonia. For digital nomad entrepreneurs that don’t have a fixed location, this is a huge deal and a big step towards full location-independence, and to top it off, it comes with minimal bureaucracy and a clear, desirable tax framework.

What Is E-Residency Not?

E-Residency does not mean actual residency. It’s not a visa, a right to remain, an identification card or citizenship, nor does it come with any of the social rights that Estonians locals have.

More importantly, it’s not a way of avoiding tax in any way, although I will elaborate on the tax benefits later on.

What Are the Benefits of Becoming An Estonian E-Resident?

Here’s a clearer, more concise list of benefits:

  • Very low administrative burden
  • 0% corporation tax (but 20% income tax)
  • A euro-currency or multi-currency bank account
  • More trust due to incorporating in a EU state
  • Access to more online services such as PayPal
  • Modern banking that can be managed remotely
  • You specifically want a business in Estonia
  • Save time and money by using government software

EU Benefits

But here’s the big question, do you need to be an Estonian e-resident to have all of this? Well, the answer to that is no. You can set up a more cost-effective international bank account to avoid currency conversion fees, and you can start a company in a country with minimal accounting requirements or zero tax.

However, depending on where you reside and where you’re setting up shop, it can be difficult; usually, it’s impossible without having to immigrate or at least spend time in the country while you set up a bank account and sign documents.

Bottom line: becoming a resident or starting a company in another country usually feels like a bit of a hack. It’s possible, but few countries have actually made the effort to make the ordeal convenient. E-residency is the solution for the digital era.

Continue reading %All You Need to Know About Estonia’s E-Residency Program%


by Daniel Schwarz via SitePoint

How to Make Your Users Enjoy Waiting

Waiting is typically an enormously displeasurable activity: It’s unproductive, boring, and even tense. And so, if you ask users to wait, many of them will refuse. According to a study by Forrester Research, almost half of consumers expect a site to load in two seconds—and if it takes longer than three, 40% leave. So, should […]

Continue reading %How to Make Your Users Enjoy Waiting%


by Aja Frost via SitePoint

Hackable PDF Typesetting in Ruby with Prawn

Installing Prawn

If you're running a Rails operation, LaTeX isn't the most convenient approach for generating documents. There are some gems available, but it's really nice when the logic and the presentation are in the same language. That's what Prawn supplies.

First, we need to install the Prawn gem:

gem install prawn

We can verify that Prawn is working with the following test:

require "prawn"

Prawn::Document.generate("hello.pdf") do
  text "Hello World!"
end

Making Text

Most of Prawn's commands are fairly minimalistic and what you would expect:

require "prawn"

Prawn::Document.generate("styling_text.pdf") do
  text "Default text styling"
  text "Blue 16pt Helvetica", size: 16, font: "Helvetica", color: "0000FF"
  text "Aligned Center", align: :center

  font_size 12
  font "Courier" do
    text "Size 12 Courier"
    font_size 10 do
      text "Slightly smaller Courier"
    end
  end
  text "Default font size 12"

  font "Helvetica"
  3.times do |i|
    text "Helvetica with leading 10 line #{i}", leading: 10
  end
end

Continue reading %Hackable PDF Typesetting in Ruby with Prawn%


by Robert Qualls via SitePoint