Lately on Stackoverflow.com I came across to several questions regarding the same argument: “How can I cache remote request”, “how to share information between controllers”, “how to avoid several $http calls”. So I decided to create a small project starting from angular seed (https://github.com/angular/angular-seed) to show a possible solution.

The idea is to use a service to store the fetched data and to share it between controllers avoiding several calls during the initial request. For this purpose we need two separate view (view1 and view 2), two separate controllers, a main app.js for the application configuration and a service file to create our caching service (not mentioning common Angularjs files).

App directory structure:

App.js is very simple and just bootstrapping the application with the dependencies: ngRoute for the routing the the view’s modules. It defines also the standard view to open in case no route is defined.

1: angular.module('myApp', [

2: 'ngRoute',

3: 'myApp.view1',

4: 'myApp.view2'

5: ])

6:

7: .config(['$routeProvider', function ($routeProvider) {

8: $routeProvider.otherwise({redirectTo: '/view1'});

9: }])

Views are also very simple, basically just injecting the service and prompting the variable value in the html partial.

View1Ctrl:

1: angular.module('myApp.view1', ['ngRoute'])

2:

3: .config(['$routeProvider', function ($routeProvider) {

4: $routeProvider.when('/view1', {

5: templateUrl: 'view1/view1.html',

6: controller: 'View1Ctrl',

7: controllerAs: 'vc'

8: });

9: }])

10:

11: .controller('View1Ctrl', function (userService) {

12: var vm = this;

13: userService.getUserInfo().then(function (result) {

14: vm.name = result

15: }, function (err) {

16: vm.name = err

17: });

18: });

View1.html:

1: <p>This is the partial for view 1!</p>

2:

3: <span>{{vc.name}}</span>

And the core of the project: the userService. The idea is to use service variables to store the fetched result (cachedUser) and to avoid additional call during the request (promise).

Basically after the first call the promise variable is set and avoids any further remote requests, if the cachedUser variable is not set, we will return the promise, otherwise via angular $q defer service we deliver the promise containing the cached value. In every case we are returning a promise avoiding any data type problem in the controller.

Today I would like to write a post different from the other I wrote in the past, I would like to do a reflection about the laugh.

Wikipedia says: “Laughter is a physical reaction in humans and some other species of primate, consisting typically of rhythmical, often audible contractions of the diaphragm and other parts of the respiratory system. It is a response to certain external or internal stimuli. …” and also “Laughter is a part of human behavior regulated by the brain, helping humans clarify their intentions in social interaction and providing an emotional context to conversations.”

Why don’t we laugh more? What is the meaning of it? Following Wikipedia description, we are primate and the laugh is an action which is part of our behavior. There is plenty of studies demonstrating that smiling is positive and healthful, why don’t we laugh more then?

At young ages we are used to enjoy the laughing freely without any control, getting older it became obscene and we are embarrassed to laugh in public, I’m talking about the guffaws that make you cry and not small timid smiles, of course. But at the end the action itself is coming from the past, is part of our origins and belonging to our ancestors. Monkey do laugh, chimpanzee do, also other animals do.

I’ll deepen into this argument because is charming and interesting, if you have any comment drop me an email or a comment, in the meanwhile my suggestion is just: laugh and smile as much as you can, it’s healthy!

Back in the past I promised a follow up article to explain how to push data to your LinkedIn stream. The time as come and here we go, so before we take off for this journey maybe you would like to create a LinkedIn fake account for your tests, instead of using your official one.

Just go the official page: https://www.linkedin.com and follow the usual steps for the account creation, once done continue with the tutorial.

In my case I don’t care too much about flooding my timeline since I get every now and then annoying spam mail and maybe that could be the right time to taste my revenge.

Jokes a part the core of this tutorial is represented by the developers API: https://www.linkedin.com/secure/developer. Those API permits you to interface your program to LinkedIn account and perform several actions for example, read/write your profile, share news on the social stream, share on your groups and basically communicate and access Job search.

Okay, more or less simple, let’s move ahead and click on the link, you will land in an almost empty page:

Just click on add new application and fill the form. If everything went well it will be prompted the following page:

Hurrah! Well done, that was the toughest part! Please take note (a screenshot) of those information since you will need them later during the hacking session.

Now the funniest part comes, in command line or in you preferred ruby editor create the ruby file, in my case I call it linkedin.rb. To consume the API we will use a gem called (guess what?) linkedin, so copy:

gem "linkedin"

To your gemfile (in the same directory as the linkedin.rb) and run bundle install in the command line. In case you do not have any gemfile just run gem install linkedin and it will install the gem for you.

After a long absence from blogging snippet of code or anything interesting (lately I was kind of busy with work and personal issues to solve), I’d like to share with you something that I created months ago but I hadn’t the time to publish: a ruby code to publish new images to imgur.

As you can find on Wikipedia, Imgur is an online image hosting service founded by Alan Schaaf in 2009 in Athens, Ohio (not Greece as I imagined first by reading it). Imgur describes itself as “the home to the web’s most popular image content, curated in real time by a dedicated community through commenting, voting and sharing. It offers free image hosting to millions of users a day, and a comment-based social community.

So far so good, but how can we interact with it? Imgur exposes APIs to interact with the entire Imgur infrastructure via a standardized programmatic interface. Using Imgur’s API, you can do just about anything you can do on imgur.com, while using your programming language of choice, in my case Ruby.

Lets move ahead! First of all you need to register to have an account, then navigate to the imgur API http://api.imgur.com and read the documentation. The following step consist in the creation of the API KEY.

Under settings > applications click on create you own

And register you application:

For tests purposes just pick random values, in my case:

Application name: imgTest

Authorization type: OAuth authentication without callback

Email:myemail@degiorgi.me

Description: test

Fill the captcha and submit the form.

Great! Now you have the Client-ID and the token to perform programmatic access to your account.

Introduction to Couchbase Server

Couchbase Server is a NoSQL document database for interactive web applications. It has a flexible data model, is easily scalable, provides consistent high performance and is ‘always-on,’ meaning it is can serve application data 24 hours, 7 days a week. Couchbase Server provides the following benefits:

Flexible Data Model

With Couchbase Server, you use JSON documents to represent application objects and the relationships between objects. This document model is flexible enough so that you can change application objects without having to migrate the database schema, or plan for significant application downtime. Even the same type of object in your application can have a different data structures. For instance, you can initially represent a user name as a single document field. You can later structure a user document so that the first name and last name are separate fields in the JSON document without any downtime, and without having to update all user documents in the system.

The other advantage in a flexible, document-based data model is that it is well suited to representing real-world items and how you want to represent them. JSON documents support nested structures, as well as field representing relationships between items which enable you to realistically represent objects in your application.

Easy Scalability

It is easy to scale your application with Couchbase Server, both within a cluster of servers and between clusters at different data centers. You can add additional instances of Couchbase Server to address additional users and growth in application data without any interruptions or changes in your application code. With one click of a button, you can rapidly grow your cluster of Couchbase Servers to handle additional workload and keep data evenly distributed.

Couchbase Server is designed for massively concurrent data use and consistent high throughput. It provides consistent sub-millisecond response times which help ensure an enjoyable experience for users of your application. By providing consistent, high data throughput, Couchbase Server enables you to support more users with less servers. The server also automatically spreads workload across all servers to maintain consistent performance and reduce bottlenecks at any given server in a cluster.

“Always Online”

Couchbase Server provides consistent sub-millisecond response times which help ensure an enjoyable experience for users of your application. By providing consistent, high data throughput, Couchbase Server enables you to support more users with less servers. The server also automatically spreads workload across all servers to maintain consistent performance and reduce bottlenecks at any given server in a cluster.

Features such as cross-data center replication and auto-failover help ensure availability of data during server or datacenter failure.

All of these features of Couchbase Server enable development of web applications where low–latency and high throughput are required by end users. Web applications can quickly access the right information within a Couchbase cluster and developers can rapidly scale up their web applications by adding servers.

Installing and Upgrading

To start using Couchbase Server, you need to follow these steps:

Make sure your machine meets the system requirements. See Preparation.

A minimum specification machine should have the following characteristics:

Dual-core CPU running at 2GHz for key-value store

4GB RAM (physical)

For development and testing purposes a reduced CPU and RAM than the minimum specified can be used. This can be as low as 1GB of free RAM beyond operating system requirements and a single CPU core.

However, you should not use a configuration lower than that specified above in production. Performance on machines lower than the minimum specification will be significantly lower and should not be used as an indication of the performance on a production machine.

View performance on machines with less than 2 CPU cores will be significantly reduced.

You must have enough memory to run your operating system and the memory reserved for use by Couchbase Server. For example, if you want to dedicate 8GB of RAM to Couchbase Server you must have enough RAM to host your operating system. If you are running additional applications and servers, you will need additional RAM. For smaller systems, such as those with less than 16GB you should for instance you should allocate at least 40% of RAM to your operating system.

Installing Couchbase Server

To install Couchbase Server on your machine you must download the appropriate package for your chosen platform from http://www.couchbase.com/downloads. For each platform, follow the corresponding platform-specific instructions.

If you are installing Couchbase Server on to a machine that has previously had Couchbase Server installed and you do not want to perform an upgrade installation, you must remove Couchbase Server and any associated data from your machine before you start the installation. For more information on uninstalling Couchbase Server, see Uninstalling Couchbase Server.

Ubuntu Linux Installation

The Ubuntu installation uses the DEB package. To install, use the dpkg command-line tool using the DEB file that you downloaded. The following example uses sudo which will require root-access to allow installation:

Past week end I had the chance to enjoy a fresh 40cm snow-powder on the alps, here follows a list of breathtaking pictures I took and it will start from the view by exiting the car in Andermatt parking place, the weather was just great and the sun shining like in summer.

The best place to snowboard in that location is situated between Sedrun and Andermatt, is called Oberalp and it is probably one of the most beautiful location in the alps.

Andermatt

To reach it you need to take the Bernina Express which in half hour brings you on the roof of the alps.

While ascending with this rack railway you can enjoy the view of the Gemstock, one of the most difficult ski place in Switzerland.

The train proceeds thru the valley of the Oberalp and the landscape is something that take you the breath away.

Here is a picture of the train station by Oberalp Pass this is one of the train stop of the Bernina Express.

After a 3 minutes uphill walk that is the mountain landscape that has been presented to my eyes.

On the right you can see the restaurant which lays on top of the train station… For me that was just a speechless landscape!

Looking to the other side of the valley you can appreciate the beauty of the nature. Fresh, untouched powder that later I surfed with my board.

I managed to arrive on top of the mountain, at the beginning with the Ski lift and then on foot, the panorama was just wonderful.

And after a whole day spent surfing the fresh snow I went back to Nätschen (Andermat ski field) and I boarded back to my car.

I hope you will enjoy the pictures and the mountain spirit of the alps.

Born in the southern part of Switzerland, I spend my childhood at the feet of the Alps near Lugano’s lake.

After the gymnasium I moved to Zurich for my studies at the ETH Zurich and finished them in Ticino by the SUPSI Manno as Informatics engineer. I had the chance to work a few months as assistant then I got a job offer in Zurich and I started working as technical consultant for Motive Inc. I traveled around the world and worked for many customers (BT, Telecom Italy, Swisscom, Saudi Telecom and more) where I covered roles as developer, trainer, deployment manager, QA lead as well as technical leader.

Motive got acquired by Alcatel Lucent and therefore I continued delivering my service as before but for a different company.

After 4 years I decided to search new incentives and I changed to a new company: Steria Schweiz AG, where I’m engaged as software developer and consultant.