Featured Image -- 298

Introducing A New Optional Feature Called Nearby Friends

Ephramar:

Facebook for Mobile: Got a new facelift

Originally posted on Facebook Newsroom:

By Andrea Vaccari, Product Manager

Today we are beginning to roll out a new feature called Nearby Friends that you can choose to turn on. Nearby Friends helps you discover which friends are nearby or on the go.

If you turn on Nearby Friends, you’ll occasionally be notified when friends are nearby, so you can get in touch with them and meet up. For example, when you’re headed to the movies, Nearby Friends will let you know if friends are nearby so you can see the movie together or meet up afterward.

Nearby Friends 1

Nearby Friends is an optional feature. You can choose who can see if you’re nearby (for example: your friends, close friends, or a specific friends list) and you can turn it on and off at any time.

Nearby Friends 2

Sharing your location with Nearby Friends goes two ways — you and your friends both have to turn on Nearby Friends…

View original 222 more words

Node.js MVC: Express.js + Derby Hello World Tutorial

Node MVC Framework

Express.js is a popular node frameworks which uses middleware concept to enhance functionality of applications. Derby is a new sophisticated Model View Controller (MVC) framework which is designed to be used with Express as it’s middleware. Derby also comes with the support of Racer, data synchronization engine, and Handlebars-like template engine among many other features.

Derby Installation

Let’s set up a basic Derby application architecture without the use of scaffolding. Usually project generators are confusing when people just start to learn a new comprehensive framework. This is a bare minimum “Hello World” application tutorial that still illustrates Derby skeleton and demonstrates live-templates with websockets.

Of course we’ll need Node.js and NPM which can be obtained at nodejs.org. To install derby globally run:

$ npm install -g derby

To check the installation:

$ derby -V

My version as of April 2013 is 0.3.15. We should be good to go to creating our first app!

File Structure

This is the project folder structure:

project/
  -package.json
  -index.js
  -derby-app.js
  views/
    derby-app.html
  styles/
    derby-app.less

Dependencies

Let’s include dependencies and other basic information in package.json file:

 {
  "name": "DerbyTutorial",
  "description": "",
  "version": "0.0.0",
  "main": "./server.js",
  "dependencies": {
    "derby": "*",
    "express": "3.x"
  },
  "private": true
}

Now we can run npm install which will download our dependencies intonode_modules folder.

Views

Views must be in views folder and they must be either in index.html under a folder which has the same name as your derby app JavaScript file, i.e.,views/derby-app/index.html, or be inside of a file which has the same name as your derby app JS file, i.e., derby-app.html.

In this example “Hello World” app we’ll use <Body:> template and {message}variable. Derby uses mustach-handlebars-like syntax for reactive binding.index.html looks like this:

<Body:>
  <input value="{message}"><h1>{message}</h1>

Same thing with Stylus/LESS files, in our example index.css has just one line:

h1 {
  color: blue;
}

To find out more about those wonderful CSS preprocessors check out documentation at Stylus and LESS.

Main Server

index.js is our main server file, and we begin it with an inclusion of dependencies with require() function:

var http = require('http'),
  express = require('express'),
  derby = require('derby'),
  derbyApp = require('./derby-app');

Last line is our derby application file derby-app.js.

Now we’re creating Express.js application (v3.x has significant differences between 2.x) and an HTTP server:

var expressApp = new express(),
  server = http.createServer(expressApp);

Derby uses Racer data synchronization library which we create like this:

var store = derby.createStore({
  listen: server
});

To fetch some data from back-end to the front-end we instantiate model object:

var model = store.createModel();

Most importantly we need to pass model and routes as middlewares to Express.js app. We need to expose public folder for socket.io to work properly.

expressApp.
  use(store.modelMiddleware()).
  use(express.static(__dirname + '/public')).
  use(derbyApp.router()).
  use(expressApp.router);

Now we can start the server on port 3001 (or any other):

server.listen(3001, function(){
  model.set('message', 'Hello World!');
});

Full code of index.js file:

var http = require('http'),
  express = require('express'),
  derby = require('derby'),
  derbyApp = require('./derby-app');

var expressApp = new express(),
  server = http.createServer(expressApp);

var store = derby.createStore({
  listen: server
});

var model = store.createModel();

expressApp.
  use(store.modelMiddleware()).
  use(express.static(__dirname + '/public')).
  use(derbyApp.router()).
  use(expressApp.router);

server.listen(3001, function(){
  model.set('message', 'Hello World!');
});

Derby Application

Finally, Derby app file which contains code for both a front-end and a back-end. Front-end only code is inside of app.ready() callback. To start, let’s require and create an app. Derby uses unusual construction (not the same familiar good oldmodule.exports = app):

var derby = require('derby'),
  app = derby.createApp(module);

To make socket.io magic work we need to subscribe model attribute to its visual representation, in other words bind data and view. We can do it in the root route, and this is how we define it (patter is /, a.k.a. root):

app.get('/', function(page, model, params) {
  model.subscribe('message', function() {
    page.render();  
  })  
});

Full code of derby-app.js file:

var derby = require('derby'),
  app = derby.createApp(module);

app.get('/', function(page, model, params) {
  model.subscribe('message', function() {
    page.render();  
  })  
});  

Launching Hello World App

Now everything should be ready to boot our server. Execute node . or node index.js and open a browser at http://localhost:3001. You should be able to see something like this: http://cl.ly/image/3J1O0I3n1T46.

Derby + Express.js Hello World App

Passing Values to Back-End

Of course static data is not much, so we can slightly modify our app to make back-end and front-end pieces talks with each other.

In the server file index.js add store.afterDb to listen to set events on messageattribute:

server.listen(3001, function(){
  model.set('message', 'Hello World!');
  store.afterDb('set','message', function(txn, doc, prevDoc, done){
    console.log(txn)
    done();
  }) 
});

Full code of index.js after modifications:

var http = require('http'),
  express = require('express'),
  derby = require('derby'),
  derbyApp = require('./derby-app');

var expressApp = new express(),
  server = http.createServer(expressApp);

var store = derby.createStore({
  listen: server
});

var model = store.createModel();

expressApp.
  use(store.modelMiddleware()).
  use(express.static(__dirname + '/public')).
  use(derbyApp.router()).
  use(expressApp.router);

server.listen(3001, function(){
  model.set('message', 'Hello World!');
  store.afterDb('set','message', function(txn, doc, prevDoc, done){
    console.log(txn)
    done();
  })   
});

In Derby application file derby-app.js add model.on() to app.ready():

  app.ready(function(model){
        model.on('set', 'message',function(path, object){
        console.log('message has been changed: '+ object);
      })
  });

Full derby-app.js file after modifications:

var derby = require('derby'),
  app = derby.createApp(module);

app.get('/', function(page, model, params) {
  model.subscribe('message', function() {
    page.render();
  })
});app.ready(function(model) {
  model.on('set', 'message', function(path, object) {
    console.log('message has been changed: ' + object);
  })
});

Now we’ll see logs both in the terminal window and in the browser Developer Tools console. The end result should look like this in the browser:http://cl.ly/image/0p3z1G3M1E2c, and like this in the terminal:http://cl.ly/image/322I1u002n38.

Hello World App: Browser Console Logs

Hello World App: Terminal Console Logs

For more magic in the persistence area, check out Racer’s db property. With it you can set up an automatic synch between views and database!

Let me know if you’re interested in any specific topic for future blog post and don’t forget to checkout my JavaScript books:

The full code of all the files in this Express.js + Derby Hello World app is available as a gist at https://gist.github.com/azat-co/5530311.

A blip, not a strain, on PH-Taiwan relations

It is most unfortunate that the government of Taiwan has suspended the issuance of visas to Filipinos intending to either work or visit their island. The suspension was in reaction to the unfortunate killing of a Taiwanese fisherman by the Philippine Coast Guard (PCG) in contested waters a few days ago.
The emotional reaction is understandable because Taiwan considers itself the aggrieved party. But Taiwan-Philippine relations have always been excellent, and there is no reason why they should not continue to remain so.

Sooner or later, the incident will be seen in its proper perspective. The PCG was only doing its job, and had no intention of inflicting harm, much less causing the death, of the fisherman from Taiwan. A representative from the Philippine government has already visited the family of the victim to offer condolences and to explain why the country had to act the way it did.

The Taiwanese should understand the Philippines’ situation vis-à-vis its territorial waters. China, for one, has been aggressively asserting its claim on Philippine territory in recent months and taking no action against perceived threats is not an acceptable option.

Unlike China, Taiwan may be easier to talk to where territorial conflicts are concerned.

One tragic event should not permanently strain Philippine-Taiwan relations.

Political Families Have Much to Celebrate After Philippine Elections

In the Philippines, a political family that runs together, wins big together.

Former Philippine first lady Imelda Marcos, with her children Ferdinand “Bongbong” Marcos Jr., right, and daughter Irene Marcos-Araneta, left, fill in ballots on Monday in the country’s midterm elections.

And among them, the family of Vice President Jejomar Binay appears the biggest winner after Monday’s midterm elections.  Mr. Binay wasn’t running in the elections. But two of his daughters were vying for seats in the Philippine Congress: Nancy, for a seat in the Senate, while Abigail sought re-election as Makati representative.  Mr. Binay’s son and namesake, Jejomar Jr., sought a second-term as mayor of Makati, the position that his father last held before winning the vice presidency.

Both Jejomar Jr. and Abigail Binay won re-election by landslides, while Nancy came in fifth among the top vote-getters for the 12 seats up for grabs in the Senate.

The family of the late President Ferdinand Marcos also continued to dominate politics in his home province of Ilocos Norte. His 83-year-old widow Imelda won another term as congresswoman by a landslide and his eldest daughter, Imee, won after running unopposed as governor of the province some 480 kilometers north of Manila. Ferdinand Marcos Jr. was elected senator in 2010 and won’t be up for re-election until 2016. Before he was elected as senator, he served as congressman and governor of Ilocos Norte, positions now held by his mother and sister, respectively.

In the south, boxing superstar Emmanuel “Pacman” Pacquiao will comfortably win a second term as representative of the lone congressional district of the province of Sarangani. His wife,  Marie Geraldine, better known as Jinkee, a political neophyte, is leading her rival to the post of vice governor of Sarangani. Roel Pacquiao, the youngest brother of the congressman, is seeking a congressional seat in the first district of South Cotabato.

Roel Pacquiao, the youngest brother of the congressman who was himself running for a congressional seat in the first district of South Cotabato, trails his rival.

Joseph Estrada won as mayor of Manila more than 12 years after being removed from the presidency by a popular uprising. Another son of Mr. Estrada, Joseph Victor, ran for a seat in the Senate and is among the 12 that will serve for six years until 2019. The mother of Joseph Victor won re-election bid as mayor of San Juan, the position that Mr. Estrada first held when he entered politics in 1967. The new mayor of Manila’s nephew, Emilio Ramon Ejercito, won a re-election bid as governor of Laguna, a neighboring province of Manila. Another son, Jose, is an incumbent senator.

Senator Alan Peter Cayetano is also in the top four spots in the preliminary count in the Senate race while his wife, Lani, is set to win a second term as mayor of Taguig City. A brother, Lino, is running as congressional district in Taguig City and is leading the count. Pia Cayetano is an incumbent senator, whose term ends in 2016.

Not everyone with a famous family name is a sure winner. Jack Enrile, son of Senate President Juan Ponce Enrile, is ranked 16th in the race for the Senate. Only the first 12 top vote-getters will win a six-year term.

A study by the Center for People Empowerment in Governance, a local public policy center founded in 2004, showed that 160 families have continuously served both houses of Congress from 1907 to 2004. After the 2010 elections, the policy center found that political dynasties have thrived and their membership even increased.

Philippines Named ‘Most Stupid Country to Elect a 20-Year OJT as a Senator’ by Time Magazine

Flag of PhilippinesMANILA, Philippines — The Philippines has been named as Time’s “Most STUPID Country to Elect a 20-Year OJT as a Senator”.

“The overwhelming victory of a self-professed on-the-job trainee-cum-Senator in the recently held election in the Philippines cemented the country’s fate,” wrote Time’s news director Marilou C. Martin.

She added, “Falling for the diversionary tactics of an inexperienced candidate that saw her steer the issue away from her credibility to her skin complexion to make herself look like the underdog; gave us no choice but to bestow such title to a country, who was destined for greatness before the elections.”

“And yes, we intentionally all-capped the word stupid for added emphasis,” according to Martin.

Time gave special attention to the country’s 11,789,643 registered voters (as of press time) who voted for Nancy Binay, as contributing to the country’s “overall stupidity rating index”.

“These are probably the same 11,289,648 people who had no access to the internet to witness the criticism their bet received for her lack political background or experience.”

The magazine didn’t wait for Comelec’s final and official number of votes Binay received before coming out with the latest issue saying that, “The amount of gullibility and the unprecedented level of idiocy forced us to go to press immediately.”

The article also noted that the country’s saving grace, namely its recent credit rating upgrade, Manny Pacquiao, Jessica Sanchez or Jada Pinkett-Smith asking for a copy of Jericho Rosales’ film did not help one bit.

“Those are only minor achievements as compared to the repercussions the sheer amount of stupidity the recent actions of the Filipino people entails.”

“It’s these kind of situations that not even Lou Diamond Philips winning the Oscars  or the Philippines winning the next Miss Universe can help with your country’s image,” said Martin.

All is not lost however, according to political analyst Mak Jendoza.

Ladies and gentlemen, your future Mayor, Vice Mayor, President, First Lady, Pope and Vice President.

Andyan na yan eh, ano pa magagawa natin (She’s already there, what else can we do)?” said Jendoza. “Siguraduhin nalang natin na hindi na mauulit ito pagdating ng 2016 (We just have to make sure that we shall not repeat this same mistake come 2016).”

Abe eh kung maging presidente ang tatay nyan at madagdagan pa ng isang kapatid sa Senado sa 2016, baka pati ang United Nations hirangin na din tayong mga inutil (If ever her dad became president and another one of her sibling became a senator in 2016, even the United Nations shall name us stupid),” warned Jendoza.

“I can’t say that I’m proud of this recent ‘achievement’ of our country,” said Johnny Manuel Ebola after learning about the magazine cover. “But at least I’m proud to say that I’m not one of those 11,789,643 nincompoops!”

Happy Father's Day

Some things are more important

SON: “Daddy, may I ask you a question?”
DAD: “Yeah sure, what is it?”
SON: “Daddy, how much do you make an hour?”
DAD: “That’s none of your business. Why do you ask such a thing?”
SON: “I just want to know. Please tell me, how much do you make an hour?”
DAD: “If you must know, I make $100 an hour.”
SON: “Oh! (With his head down).
SON: “Daddy, may I please borrow $50?”

The father was furious.

DAD: “If the only reason you asked that is so you can borrow some money to buy a silly toy or some other nonsense, then you march yourself straight to your room and go to bed. Think about why you are being so selfish. I work hard everyday for such this childish behavior.”

The little boy quietly went to his room and shut the door. The man sat down and started to get even angrier about the little boy’s questions. How dare he ask such questions only to get some money? After about an hour or so, the man had calmed down, and started to think: Maybe there was something he really needed to buy with that $50 and he really didn’t ask for money very often. The man went to the door of the little boy’s room and opened the door.

DAD: “Are you asleep, son?”
SON: “No daddy, I’m awake”.
DAD: “I’ve been thinking, maybe I was too hard on you earlier. It’s been a long day and I took out my aggravation on you. Here’s the $50 you asked for.”

The little boy sat straight up, smiling.

SON: “Oh, thank you daddy!”

Then, reaching under his pillow he pulled out some crumpled up bills. The man saw that the boy already had money, started to get angry again. The little boy slowly counted out his money, and then looked up at his father.

DAD: “Why do you want more money if you already have some?”
SON: “Because I didn’t have enough, but now I do.

“Daddy, I have $100 now. Can I buy an hour of your time? Please come home early tomorrow. I would like to have dinner with you.”

The father was crushed. He put his arms around his little son, and he begged for his forgiveness. It’s just a short reminder to all of you working so hard in life. We should not let time slip through our fingers without having spent some time with those who really matter to us, those close to our hearts. Do remember to share that $100 worth of your time with someone you love? If we die tomorrow, the company that we are working for could easily replace us in a matter of days. But the family and friends we leave behind will feel the loss for the rest of their lives. And come to think of it, we pour ourselves more into work than to our family.

A Cow-Based Economics Lesson

SOCIALISM
You have 2 cows.
You give one to your neighbor.

COMMUNISM
You have 2 cows.
The State takes both and gives you some milk.

FASCISM
You have 2 cows.
The State takes both and sells you some milk.

NAZISM
You have 2 cows.
The State takes both and shoots you.

BUREAUCRATISM
You have 2 cows.
The State takes both, shoots one, milks the other, and then throws the milk away.

TRADITIONAL CAPITALISM
You have two cows.
You sell one and buy a bull.
Your herd multiplies, and the economy grows.
You sell them and retire on the income.

ROYAL BANK OF SCOTLAND (VENTURE) CAPITALISM
You have two cows.
You sell three of them to your publicly listed company, using letters of credit opened by your brother-in-law at the bank, then execute a debt/equity swap with an associated general offer so that you get all four cows back, with a tax exemption for five cows.
The milk rights of the six cows are transferred via an intermediary to a Cayman Island Company secretly owned by the majority shareholder who sells the rights to all seven cows back to your listed company.
The annual report says the company owns eight cows, with an option on one more.
You sell one cow to buy a new president of the United States , leaving you with nine cows.
No balance sheet provided with the release.
The public then buys your bull.

SURREALISM
You have two giraffes.
The government requires you to take harmonica lessons.

AN AMERICAN CORPORATION
You have two cows.
You sell one, and force the other to produce the milk of four cows.
Later, you hire a consultant to analyze why the cow has dropped dead.

A FRENCH CORPORATION
You have two cows.
You go on strike, organize a riot, and block the roads, because you want three cows.

A JAPANESE CORPORATION
You have two cows.
You redesign them so they are one-tenth the size of an ordinary cow and produce twenty times the milk.
You then create a clever cow cartoon image called a Cowkimona and market it worldwide.

AN ITALIAN CORPORATION
You have two cows, but you don’t know where they are.
You decide to have lunch.

A SWISS CORPORATION
You have 5000 cows. None of them belong to you.
You charge the owners for storing them.

A CHINESE CORPORATION
You have two cows.
You have 300 people milking them.
You claim that you have full employment, and high bovine productivity.
You arrest the newsman who reported the real situation.

AN INDIAN CORPORATION
You have two cows.
You worship them.

A BRITISH CORPORATION
You have two cows.
Both are mad.

AN IRAQI CORPORATION
Everyone thinks you have lots of cows.
You tell them that you have none.
No-one believes you, so they bomb the ** out of you and invade your country.
You still have no cows, but at least you are now a Democracy.

AN AUSTRALIAN CORPORATION
You have two cows.
Business seems pretty good.
You close the office and go for a few beers to celebrate.

A NEW ZEALAND CORPORATION
You have two cows.
The one on the left looks very attractive.