Simple WhoAmI for Loopback

Retrieving the currently authenticated user in a Loopback Application can be done in many ways, and one of them is the one I want to share in this post.

I wanted to be able to utilise the Angular SDK as well as the Explorer, so adding a routing manually in a boot script was not really an option, however simple that might be, so I decided to opt for implementing it as a custom Model.

The first thing to do is to create a whoami.json and whoami.js file in the commons directory.


  "name": "WhoAmI",
  "base": "Model",
  "plural": "whoami",
  "acls": [
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "DENY"
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW"


module.exports = function (WhoAmI) {

    WhoAmI.whoAmI = function (req, next) {
        var AccessToken = WhoAmI.app.models.AccessToken;
        AccessToken.findForRequest(req, {}, function (aux, accesstoken) {
            var UserModel = WhoAmI.app.models.User;
            UserModel.findById(accesstoken.userId, function (error, user) {
                next(error, user);

            accepts: {arg: 'req', type: 'object', http: {source: 'req'}},
            returns: {arg: 'user', type: 'object'},
            http: {path: '/', verb: 'get'}

Secondly, I make sure to add the model to the model-config.json

"WhoAmI": {
  "dataSource": null,
  "public": true

Now, when you restart the server, you will see the following endpoint having been added to your API


And because of the ACL’s we set in the model, all requests without an access-token are handled by the security of Loopback… so there you go, a nice and easy WhoAmI !

Alternatively… a bootscript

If you for some reason should be inclined to prefer putting it in a boot script, all you have to do is to create a file in the boot directory of the server with the following content

module.exports = function (server) {

    var router = server.loopback.Router();

    router.get('/whoami', function (req, res) {

        var AccessToken = server.models.AccessToken;
        AccessToken.findForRequest(req, {}, function (aux, accesstoken) {
            if (accesstoken == undefined) {
                    'Error': 'Unauthorized',
                    'Message': 'You need to be authenticated to access this endpoint'
            else {
                var UserModel = server.models.User;
                UserModel.findById(accesstoken.userId, function (err, user) {


Gist: https://gist.github.com/pmoelgaard/af6aa61146766f0e8551


Startup Advice… motivator list

1. Make something people want.
2. A great team and a great market are both critically important—you have to have both. The debate about which is more important is silly.
3. Write code, talk to users, and build the company (hire the best people you can find, get the culture right, fundraise, close sales, etc.) Most other things that founders do are a waste of time.
4. Set a clear, easy-to-understand vision for your company, and make it be a mission people believe in.
5. Stay focused and don’t try to do too many things at once. Care about execution quality.
6. You have to have an almost crazy level of dedication to your company to succeed.
7. In general, don’t start a startup you’re not willing to work on for ten years.
8. Be relentlessly resourceful.
9. In the current pivot-happy world, good ideas are underweight. It’s worth the time to think through a good one.
10. Growth solves (nearly) all problems.
11. While growth is critical and you should focus on it, occasionally consider where you’re going—you need both growth and to be growing towards something valuable.
12. Obsess about the quality of the product.
13. Overcommunicate with your team. For some reason most founders are really bad at this one. Transparency is your friend.
14. Move fast. Speed is one of your main advantages over large companies.
15. Hire slow; fire fast. Hiring is the most important thing you do; spend at least a third of your time on it.
16. Occasionally think about why the 20th person will join your company.
17. Hire smart and effective people that are committed to what you’re doing. The last five words there are important.
18. Hire friends and friends of friends. Go after these people like crazy to get them to join. Some other candidate sources are ok, but I always got bad results from technical recruiters.
19. Generally, value aptitude over experience.
20. Hire people that you could describe as animals.
21. Eliminate distractions.
22. Don’t die.
23. Be frugal.
24. You’ll often hear conflicting advice about everything but “build a great product”. This means you can go either way on much of the rest of it and it doesn’t really matter. Just make a decision and get back to work. Product/market fit is what matters. You can—and will—make a lot of mistakes.
25. You make what you measure.
26. Startups are very hard no matter what you do; you may as well go after a big opportunity.
27. Momentum is critical. Don’t lose it.
28. Keep salaries low and equity high.
29. Keep the organization as flat as you can.
30. When working on a deal—raising money, trying to get a partnership, etc.—it’s important to create a competitive situation.
31. Schleps are good.
32. Don’t forget to make money.
33. Journalists like hearing directly from founders. If you hire PR people, resist their desire to control all the contact.
34. It’s standard for founders to keep board control in the first round.
35. Listen to everyone. Then make your own decision.
36. Remember that you are more likely to die because you execute badly than get crushed by a competitor.
37. Get lucky.
38. Have a direct relationship with your customers.
39. Be formidable—do not be easy to push around.
40. Don’t let your company be run by a sales guy. But do learn how to sell your product.
41. Have a culture that rewards output.
42. Don’t hire professional managers too early.
43. Simple is good. Be suspicious of complexity.
44. Get on planes in marginal situations. In-person is still better than tele-anything.
45. Most things are not as risky as they seem.
46. Be suspect of anyone who says the word process too often.
47. Raise a bit more money than you think you need.
48. Ignore the fact that “the press loves [you]”.
49. Have great customer service.
50. You can create value with breakthrough innovation, incremental refinement, or complex coordination. Great companies often do two of these. The very best companies do all three.
51. The role of the board is advice and consent. If the CEO does not lay out a clear strategy and tries to get the board to set one, it will usually end in disaster.
52. Board observers are usually a headache.
53. If you pivot, do it fully and with conviction. The worst thing is to try to do a bit of the old and the new—it’s hard to kill your babies.
54. It’s better to make a decision and be wrong than to equivocate.
55. Set goals for the company and motivate people to get there.
56. Always praise good work.
57. Celebrate your wins as a company. Get t-shirts for big milestones.
58. Have a good operational cadence where projects are short and you’re releasing something new on a regular basis.
59. You can win with the best product, the best price, or the best experience.
60. Meetups and conferences are generally a waste of time.
61. If the founders of your company seem to care more about being founders than they care about your specific company, go join another company.
62. It’s easier to sell painkillers than vitamins.
63. Be suspicious of any work that is not building product or getting customers. It’s easy to get sucked into an infrastructure rewrite death spiral.
64. It’s better to have a few users love your product than for a lot of users to sort of like it.
65. Learn how to stay extermally optimistic when your world is melting down.
66. Startups should require as few miracles as possible, but at least one.
67. You have to have great execution—far more people have good ideas than are willing to roll up their sleeves and get shit done.
68. Don’t have a diverse culture in the early days.
69. Keep a to-do list every day. At the top of it, put the one or two big things you want to work on.
70. Being the CEO is miserable more often than it’s good. But when it’s good, it’s really good.
71. On the really bad days, remember that tomorrow will be better—it’s hard to see it being much worse!
72. Sleep and exercise.
73. Success in a startup is usually pass/fail. Worry more about making sure you pass than an extra point of dilution.
74. Good investors are worth a reasonable premium.
75. Give your investors something to do.
76. Go for a few highly involved investors over a lot of lightly engaged ones.
77. Raise money on promise. Raise money on clean terms.
78. Do reference checks on your potential investors. Ask other founders how they are when everything goes wrong.
79. Investors love companies other investors love.
80. A lot of the best ideas seem silly or bad initially—you want an idea at the intersection of “seems like bad idea” and “is good idea”. (It’s important to note you need to be contrarian and right, not simply contrarian.)
81. Surf someone else’s wave.
82. Sometimes you can succeed through sheer force of will.
83. All startups are fucked in at least one major way. Keep going.
84. Keep an eye on cash in the bank and don’t run out of it.
85. Pay a lot of attention to the relationship between cofounders, especially if both/all of you want to be CEO.
86. Stay small and nimble.
87. Have a staff meeting at least once a week.
88. Find a mentor that will teach you how to manage.
89. Keep burn low until you’re sure everything is working.
90. Be suspect about buying users.
91. Lead by example.
92. Have the right kind of office. The proper office for a very small company is an apartment or house.
93. Share results (financial and key metrics) with the company every month.
94. Have a table in your offer letters that shows how much the stock you’re granting a new hire could be worth in various scenarios.
95. The best startups are defined by exceptions; all of these rules are probably breakable, but probably not all at the same time.

JavaScript, Uncategorized

JQPLOT – A Versatile and Expandable jQuery Plotting Plugin

jqPlot is a plotting and charting plugin for the jQuery Javascript framework.


jqPlot produces beautiful line, bar and pie charts with many features:

  • Numerous chart style options.
  • Date axes with customizable formatting.
  • Up to 9 Y axes.
  • Rotated axis text.
  • Automatic trend line computation.
  • Tooltips and data point highlighting.
  • Sensible defaults for ease of use.

jqPlot is an open source project by Chris Leonello

Check it out…


Evernote’s New Home Screen

Now and then new User Interface patterns emerge… sometimes causing attention and other times just being accepted as natural evolutions of existing concepts…

Evernote just announced their new version with a couple of new User Interface patterns weaved in… one of them is the new Home Screen on their mobile applications…


This way of combining a set of shortcuts with a hierarchical navigator using 2.5D for imitating perspective will be interesting to try in real life…


Criticism ! Constructive ? We love it !

The next time you receive constructive criticism from your manager or a peer, use this six-step process to handle the encounter with tact and grace.

  1. Stop Your First Reaction
  2. Remember the Benefit of Getting Feedback
  3. Listen for Understanding
  4. Say Thank You
  5. Ask Questions to Deconstruct the Feedback
  6. Request Time to Follow Up

Constructive criticism is often the only way we learn about our weaknesses—without it we can’t improve. When we’re defensive, instead of accepting and gracious, we run the risk of missing out on this important insight. Remember, feedback is not easy to give and it’s certainly not easy to receive, but it will help us now and in the long run.

The recipe is inspired from this great article… http://nxg.li/XeQMAb


Introducing Web Platform Docs… a unified approach

On the 8. October 2012 something historically happened… W3C, in collaboration with Adobe, Facebook, Google, HP, Microsoft, Mozilla, Nokia, Opera, and others, announced the alpha release of Web Platform Docs (docs.webplatform.org), a new community-driven site that aims to become a comprehensive and authoritative source for web developer documentation.

In the past, developers who use HTML5, CSS and other technologies of the Open Web Platform have had to consult multiple sites to understand how to use these technologies in a way that works across browsers, operating systems and devices. This was time-consuming and in many cases increased development costs.

With Web Platform Docs, the vision is that web professionals will save time and resources by consulting a single site for current, cross-browser and cross-device coding best practices, including:

  • How to use each feature of the Open Web Platform, with syntax and examples;
  • The interoperability of various technologies across platforms and devices;
  • The standardization status of each technology specification;
  • The stability and implementation status of features.

The project is implemented as a Wiki, which means that anyone can contribute content to Web Platform Docs. The organizations mentioned above – collectively known as the “stewards” – have launched this new site with initial documents contributed as raw material for the community to shape. The W3C will serve as the site’s convener. As the Open Web Platform evolves, the entire community, including the original stewards and new stewards, will help maintain and improve the content. All materials on the site will be freely available and licensed to foster sharing and reuse.

“People in the web community — including browser makers, authoring tool makers, and leading edge developers and designers — have tremendous experience and practical knowledge about the web,” said Tim Berners-Lee, W3C Director. “Web Platform Docs is an ambitious project where all of us who are passionate about the web can share knowledge and help one another.”

The W3C and the stewards envision webplatform.org as the home of future collaboration with developers and designers. Those interested in contributing to this effort as a steward or as an editor can visit docs.webplatform.org

Tools, Uncategorized

Trello… now with an API (Beta)

Trello is not only a very useful task management system, incorporating SCRUM board approach with HTML5 and an exceptional nice look and feel… now it also has a very elegant REST API.

Check it out…

Here is a quick sample on how to retrieve the cards for the current user… using the Client.js JavaScript class that Trello is providing asn easy way to get started…

They have opened up their development plans in the form of their internal development board…