hjertnes.blog

Promise Functions.

06.12.2017 01:00

I have talked a lot about promises before. Some people think they are a unnesseary complcation of simple callbacks. I disagree, because async await makes it possible to make code a lot more readable, especially if you need to do a lot of stuff that would have callbacks. But I have not talked that much about two methods that live in the Promsie prototype: all and race.

Promise.all is a method you can use to resolve any number of promises, and it will not resolve until all of them are resolved. The result is a iterable of the result from all of the promises, in the order they were in the array to passed to Promise.all.

Promise.race on the other hand also takes an array, but will resolve when the first promise resolves. Useful if you for example have multiple ways to fetch some kind of data, and you just want the any of them.

Pug

05.12.2017 01:00

Pug is a template language for Javascript that I have grown to enjoy a lot. My impression is that a lot of people use it, if they use a templating engine for server side rendering using Node. The big question is if you need it or not in 2017. I personally believe that there is a place for it, when you just want to put to gether something really simple, where the interactivity of a full fledged front end system like React or Angular would be overkill. But you could probably make something similar yourself with template literals if your needs are really simple.

But I personally just go with pug, because the syntax is elegant and easy to learn. It performs well. And it is really easy to use it with Express.

#

04.12.2017 01:00

👌 Liked: 1Password CLI

Filling the Vanishing Point

04.12.2017 01:00

I do love my Vanishing Point. AndI guess it is the pen I use the most. But there is one thing about it I’m not that fun of. And that is how much of a pain in the ass it is to fill it when your ink bottle gets low.

Like I have said many times before, the Pilot Vanishing Point is a pen with a lot of compromises that are necessary to get a good, reliable, retractable fountain pen. sing that converter I hate.

This problem on the other hand has to do with the nib design, which I assume is that way because it was needed by the mechanism. Anyways. The problem is that the place where the ink are sucked into the pen, is very high on the nib; much higher than most pens. That means that the point where you can problems filling your pens from a bottle of ink will be much sooner with a VP than any other pen I own.

Review of my iPhone 8 Plus.

04.12.2017 01:00

My iPhone buying strategy have always been to use them until they break or the battery is useless. How much time that takes varies, but it is always between two and two and a half years. What happened this time was much more dramatic. I broke the screen of my 6 Plus a year agp. And then I started to see some signs of watar damage after I waled the dog.

The result was that the phone slowly died over that night. And I ordered the best possible replacement the morning after. It wasn’t without compromises.

My original plan was to wait until the iPhone X was available. But going without a phone for a few weeks or months wasn’t an option; because everything from two factor authentication for banking to my train season ticket is on my phone.

My revised plan was to get a either a 8 Plus or a 7 Plus; basically the best one available to be sent “now”. I went with a 8 Plus Space grey. The 64 GB model.

It’s kind of strange that I’m on the lowest storage option now. On one side is it good that Apple have phones, where the cheapest one is usable. But on the other side I realize that it might just be that my needs are going up much slower than the rest of the world.

What do I think about it? I love it, it is more or less the same as my 6 Plus. Just faster, newer and better. But everything feels familiar. There is a little bit more “grip” to the surface of the 8 and X phones compared to the previous models (excluding the JetBlack). But I would still recommend getting either a Apple leather or silicone case; I got the latter.

This is the kind of upgrade where I would be fine with a faster version of what I had. But there are also some new stuff. Like for example the extra camera lens. I love that my phone now has both a 28mm and 50mm equivalent lenses; meaning that what you see is more or less the same as you would with a 50mm and 28mm lens on a full frame or a 35mm camera.

I’m not sure how I feel about the lack of a headphone jack. There have been times where it bothered me. My PowerBeats were on repair, and I had to charge my phone and I wanted to listen to podcasts. But I use my bluetooth PowerBeats most of the time. So, not being able to charge while using headphones isn’t something that affects me a lot.

Anyways. A great upgrade, if you want a new phone fast. Or if you just want a better version of what you had.

Spread

04.12.2017 01:00

Spread is a very powereful expression that both makes some stuff easier, and makes other things possible that were close to impossible without it. What it does is to extract the content of either a array or an object. Below is an example showing how to use spread on objects and arrays to make a copy of them and to pass the content (not the array or object itself) as parameters to a functions. The object spread is also a very elegant way to pass dynamic data to React components.

I know I say this a lot, but this is one of my favourite modern Javascript features. One side note: the object version of spread is currently in draft stages.

#

03.12.2017 01:00

When I observe people discuss Net Neutrality I think back on the most important skill I got out of my philosophy degree. And that is to look for an understanding of all the different sides and to identify the different layers of opinion.

In this case you have those who think NN is a good idea, and you have those who don’t. And for those who think NN is the way to go you have different opinions regarding how to do it. Some think Title 2 is the best option, while others think that approach is a little bit too heavy handed.

I don’t have any particular opinions on how we get there. But I think that there shouldn’t be any differences. All traffic is treated equal. And ideally no transfer cap. You pay for a certain speed, and that’s it.

One of those typical “deals” I see from certain carriers that really annoy me is that “Spotify or Netflix doesn’t count against your data cap”.

It is a bad idea to have it if it is only limited to one service for music and one for movies. But would it be a problem if it was all music and movie streaming? As long as it was easy enough to be approved as either.

Import and Export

01.12.2017 01:00

A important note: this article is intended to be a explaination of how you can import and export code using ES6 modules. It doesn’t deal with how the various other schemes work or how you should do it in node. And it doesn’t deal with how to make sure the different schemes interact with each other. This is simply put how I do it in my Webpack + Babel based projects.

The way we are going to deal with modules in Javascript in the future is by the import and export pattern. You are probably used to it, if you are using babel and or webpack as a pair of your tool chain. There are some support for it in node, but the support are rather limited, and I haven’t looked much on it, except for seeing in the change log that some support were addeed.

The basic idea is that the code in one Javascript file, is not visible to be imported into another Javascript file, unless you tell it “hey you can import this”. Each file can have one thing that is the default one, and any number of other exports. If you are using React the default export might be your compoenent connected to Redux, but you might also want export the component without that; then the connected might be prefixed with “export default” and the other prefixed with just “export”.

For example:

The code above is intended as a demostration only, it doesn’t work because it is missing some imports and so on.

If you have some piece of code, that is marked with export default then you import it with import WhatEverYouWantToCallIt from './Filename', and if you prefix it with just export then you import it like this `import {theNameInTheModule} from ‘./Filename’.

The biggest difference is that the default is imported without {}, and you can call it what the hell you want; while the rest need to be imported with their actual name and you need to place {} around it or them. The import export syntax introduced in ES6 is far superior to what we had before it, and is very intuitive as soon as you get a grasp on {module} vs module and export vs export default. This is without one of the “Javascript starts to feel like a real programming language” moments.

#

30.11.2017 01:00

You reap what you sow

#

30.11.2017 01:00

Should I connect the feeds of my blogs into micro.blog? 🤔