Documentation, Uncategorized

Multiple Environments with Loopback 4

When configuring multiple environments for a Loopback 4 Application, it can appear less straight forward than with Loopback 3, so here is a quick fix for how to get over this obstacle as elegantly as possible in 5 minutes.

  1. Import dotenv and create a .env file in the root of the app.
  2. Put your database configuration in this file.
  3. Empty the existing datasource file so it contains an empty JSON (file is required by compiler and the bootstrapping).
  4. Add the code below to the application.ts file in the src directory.
  5. Don’t forget to require the dotenv from the run command.
this.bind('datasources.default').to(new DefaultDataSource());
this.dataSource(new DefaultDataSource());
this.bind('datasources.config.default').to({
  name: 'default',
  connector: 'mongodb',
  hostname: process.env.DB_DEFAULT_HOSTNAME,
  port: process.env.DB_DEFAULT_PORT,
  user: process.env.DB_DEFAULT_USER,
  password: process.env.DB_DEFAULT_PASSWORD,
  database: process.env.DB_DEFAULT_DATABASE,
  useNewUrlParser: process.env.DB_DEFAULT_USENEWURLPARSER,
  authSource: process.env.DB_DEFAULT_AUTHSOURCE
});
this.bind('datasources.default').toClass(DefaultDataSource);

This is a quick fix intended to help move on if in a pickle, I will refine this further so the application will check the process.env.NODE_ENV variable instead and load the corresponding file.

For the original inspiration to this post, head over here: https://medium.com/p/8f085399268/responses/show

 

Advertisements
Uncategorized

Keyboard Shortcut for Inserting Comment in Word for Mac

If you have come to this post, chances are you like me found yourself tired of adding comments by using the mouse and was surprised that the “Insert Comment” didn’t feature a keyboard shortcut… but dispair not, the solution is here…

Very intuitively (not really), the keyboard shortcut to insert comment is

Command + Alt + A

If you want to see for yourself or set it to something else, you can find the setting here:

Tools > Customize Keyboard > Insert > InsertAnnotation

Now, you can enjoy the thrill of being able to review documents galore without having to let your fingers leave your keyboard… what a production boost, eh !?

Uncategorized

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.

whoami.json

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

whoami.js

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);
            });
        });
    }

    WhoAmI.remoteMethod(
        'whoAmI',
        {
            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

2015-03-01_23-05-18

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) {
                res.status(401);
                res.send({
                    '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) {
                    res.status(200);
                    res.send(user);
                });
            }
        });
    });

    server.use(router);
}

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

Uncategorized

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.

Image

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…
http://www.jqplot.com/

Uncategorized

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…

Image

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…