OAuth2 JavaScript Tutorial

When building modern and socially-aware web applications, the related problems of user authorization and authentication arise repeatedly. The rich API ecosystem offered by the Web to developers is to some extent complicated by questions of security: How do we make sure our users are who they say they are? How do we ensure they have authority to access a particular resource, like a profile or a photo album?

OAuth2 is an authorization protocol that solves these problems, enabling secure access to third-party APIs (like Google Maps’ or Twitter’s) in your own applications. This tutorial discusses the use of OAuth2 in a small example application that will make use of a Google+ API.

The Running Example

Throughout this tutorial we will be referring to a tiny demo application called “Logonoff”. The only things we can do with it are log in, look at some data, and log out, and it looks like this:

The application makes use of a JavaScript library called hello.js that presents a unified API for interacting with a number of OAuth providers, such as Google, Facebook, Twitter, Github, and more. We chose to use hello.js because it is popular, versatile, and simple.

If you want to run Logonoff on your system, you can download the code and follow the instructions on Github.
Continue reading…

Angular 2 Tutorial – Simple “Hello World” App Example

Angular 2 reached release candidate status a couple of weeks ago. As Angular 2 is making its way to a final release, now is a good time to take a look at the framework, what it does and what the main differences with Angular 1 are. In this tutorial, we will go through different examples and build a small sample traffic light application using Angular 2 to illustrate some of those new concepts. Let’s get started with components.

Recording #1

Continue reading…

ElasticSearch Tutorial: Creating an Index and Querying

Elasticsearch is a highly-scalable document storage engine that specializes in search. Elasticsearch comes with reasonable default settings, but it will also easily scale to being able to search hundreds of millions of documents with sub-second latency. As you’ll see in this tutorial, the JSON-based nature of Elasticsearch, along with its simple REST API, make it easy to learn.


Elasticsearch is written in Java, so it should work on any operating system that can run Java. If you don’t have Java installed on your machine already, click here to download and install it. We’re going to do this tutorial with version 2.3.1 of Elasticsearch.

Elasticsearch is really simple to get up and running – you can have a one-node cluster running in just a few minutes with the following steps:

  1. Download and unzip Elasticsearch 2.3.1 found here.
  2. Navigate to the directory you unzipped it to, and run bin/elasticsearch if you are using Linux or OS X or bin/elasticsearch.bat if you are using Windows.
  3. In your browser, navigate to http://localhost:9200/, you should see a page that looks something like this:


Continue reading…

Using AJAX in a Ruby on Rails App

AJAX is an important part of many Rails applications. It allows for making client-side changes without the need to reload the page. In this tutorial, you’ll see a very simple example of how to send a JavaScript response from the server and some of the more interesting things that can be done.

For this tutorial, we’ll be using AJAX to toggle between showing and hiding a menu of download options, which prevents them from cluttering up your screen when they aren’t needed. To get the code on GitHub, click here.

AJAX Demo V4.5

First, let’s outline what the mini app should do.

  • The home page needs to have a Show Options button which when clicked to reveal the download options.
  • With the download options revealed we should see:
    • Options for downloading data, a sample, or a demo.
    • A button to hide the download options.
  • Clicking the Hide Options button should return things back to how they were.

Continue reading…

Python Celery & RabbitMQ Tutorial

Celery is an asynchronous task queue. It can be used for anything that needs to be run asynchronously. For example, background computation of expensive queries. RabbitMQ is a message broker widely used with Celery. In this tutorial, we are going to have an introduction to basic concepts of Celery with RabbitMQ and then set up Celery for a small demo project. At the end of this tutorial, you will be able to setup a Celery web console monitoring your tasks.


Basic Concepts

Let’s use the below graphic to explain the foundations:celery_architecture_final


The Broker (RabbitMQ) is responsible for the creation of task queues, dispatching tasks to task queues according to some routing rules, and then delivering tasks from task queues to workers.

Consumer (Celery Workers)

The Consumer is the one or multiple Celery workers executing the tasks. You could start many workers depending on your use case.

Result Backend

The Result Backend is used for storing the results of your tasks. However, it is not a required element, so if you do not include it in your settings, you cannot access the results of your tasks.

Continue reading…

Angular Google Maps Tutorial: Demo, Examples

Angular Google Maps is a set of directives that integrate Google Maps in an AngularJS application. It makes using Google Maps in such an application very easy as you don’t need to know the Google Maps API in order to use it.


Getting Started

Let’s start with a simple example to illustrate how easy it is to display data on a map:

angular.module('appMaps', ['uiGmapgoogle-maps'])
    .controller('mainCtrl', function($scope) {
        $scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 };

This is all your controller needs in order to display a map centered on the specified location, which is defined by a latitude and a longitude. Zoom level is a value between 1 and 20, 20 being the most zoomed-in value, and 1 being the most zoomed-out.

The HTML code to display that map is fairly straightforward:

<div id="map_canvas" ng-controller="mainCtrl">
      <ui-gmap-google-map center="map.center" zoom="map.zoom"></ui-gmap-google-map>

All of this obviously requires some dependencies: The Google Maps API, Angular JS, Angular Google Maps and Lodash, which is a dependency of Angular Google Maps. Here is what the end result looks like:

first map

Continue reading…

Build an Angular 1.5 component – An AngularJS tutorial

Angular 1.5 recently introduced components, a feature also available in Angular 2. Using components from and in Angular 1.x makes a lot of the sense as it will help your application bridge the gap between Angular 1.x and Angular 2, which is the main reason why the Angular team announced components availability in Angular 1.5.

What’s a component?

A component is basically a directive that uses a simpler configuration and that is suitable for a component-based architecture, which is what Angular 2 is all about.  Think of a component as a widget: A piece of HTML code that you can reuse in several different places in your web application.

Continue reading…

Class-based Views Django Tutorial

The web framework for perfectionists with deadlines.

Django is all about making programmers more productive. As a web application framework, it provides tools and structure to help web developers get their work done fast.

The reason that developers use application frameworks today is because the vast majority of web programming is extremely repetitive: handling incoming requests, checking session information, authenticating users, CRUD database operations, etc.

The fraction of code that makes your web application unique is very small. Frameworks help developers satisfy one of the key principles of good code design: don’t repeat yourself (stay DRY).

View Functions and the Need for Class-based Views

One of the first tools that the Django project provided to developers was view functions:

def list_user_snippets(request):
    # Show list of a user's code snippets
    # for a Pastebin-like application
    snippets = Snippet.objects.filter(user=request.user)
    context = {'snippets':snippets}
    return render(request, 'mysnippets/snippet_list.html', context)

Continue reading…

Django REST Framework Tutorial

If you are working on a single-page application and you want it to have some persistence, it’s a really good idea to have a REST api. This way you’ll be able to store your domain’s entities in the database. In this article, you will learn how to create a basic application with Django and Django REST framework. You can use this as a starting point, and then it’s quite easy to extend this project with different pluggable Django applications.

You can find a repository here and demo here. The animation below shows the automatically generated html interface of the api created in this tutorial:

ezgif.com-crop Continue reading…