Skip to content. | Skip to navigation

Personal tools
Log in
You are here: Home - Blog


Posted by admin |

"It's amazing China's finding out that its financial and capital control policy boils down to its firewall policy" said Ravikant

Sep 05, 2018 02:55

Turn off closing brackets in VS code

Posted by admin |

This was driving me nuts, with VS code from my perspective randomly adding a closing bracket with complete disregard to context. And moving the cursor to boot. Add this to your preferences:

"editor.autoClosingBrackets": false

Adding a closing bracket while the user is typing, only seems to be a moderately good idea when you're typing new code. When editing code, which is by a factor of at least 5 more common that typing new code, adding a closing bracket makes no sense.

For example, say that you have a javascript one-line arrow function that should return an object. This below does not work because javascript assumes that the curlys brackets delimit a function:

foo => {'bletch':foo.blam}

Easy fix, just add brackets around the curlies:

foo => ({'bletch':foo.blam})

But of course VS code will do this when you type the "(":

foo => (){'bletch':foo.blam}

So you might end up with this:

foo => (){'bletch':foo.blam})

and that will not run and you wonder how you could have put in unbalanced brackets. But of course you didn't, VS code put one in for you.


Aug 19, 2018 12:50

How to call a promisified function in-page with Nightmare/mocha/chai

Posted by admin |

Two important things to keep in mind:

  1. You have to return from inside the "it" function (boldfaced below)
  2. You need to list parameters to evaluate three times, the third time as a list of parameters after the function argument to evaluate (also boldfaced below)

    it(`Keystretching ${clearTextPassword} with ${hexNonce} with current params should give ${theExpectedDerivedKey}`, function () {
      return Nm()
        .evaluate((clearTextPassword, hexNonce, keyStretchFactor) => {
          return stretch(clearTextPassword, hexNonce, keyStretchFactor)
        }, clearTextPassword, hexNonce, keyStretchFactor)
        .then(res => expect(res.derivedKey).to.equal(theExpectedDerivedKey))



Aug 17, 2018 07:23

Will crypto-currency driven insurance replace the concept of objective truth?

Posted by admin |

Imagine a future where everybody believes in their own subjective "truth" and people cannot agree on facts. Some say that is where we are heading. Without facts, words don't mean much, whether in parliament or in law.

How would such a world be ruled? I can think of two ways. One is violence. Whatever you believe in, if you are threatened with violence you have no choice but to comply. It does not matter what you believe in. A kind of mafia driven governance. Probably in a hierarchy since otherwise it would be hard to channel.

But there is another way I think that a world could operate without people being able to agree on truth. And that is markets. First there needs to be a currency for the market. Even if people want to believe in let's say different currencies, some currencies will be clearly better than others. In fact with the aid of blockchains and crypto currencies we may get close to consensus on what currency to use, since believing in the "wrong" currency will be punished as that currency falls in value. So we have step one in consensus: We believe in the same currency.

Secondly, on a blockchain you can have a kind of insurance system, where money is staked, and vouched for something. And if that something misbehaves, the insurance may be triggered and that money being sent to someone else. This is essentially what is called a Third-party insurance.  Imagine for example if every person travelling needs to have a terrorist insurance, so that if they do something bad, their insurance company needs to pay out possibly on the order of billions of dollars to victims and next of kin of victims. This would mean that an insurance company would need to do due diligence assessing the risk of an individual before they give that person an insurance cover.

For a high-risk individual insurance premium might run in the vicinity of millions of dollars per week. And you can't travel without it. So such a person would be unable to move.

So truth comes from if someone is willing to vouch for you, and entities who have bad judgment about vouching will run out of money.

I'm not saying this is a desirable future scenario, but it may be a way to work around the fact that the future may not believe in facts.

Aug 14, 2018 11:35

Applying functions to parts of data in a promise chain using JSONPath

Posted by admin |

When working with promise chains, you sometimes pipe through a bit more complex data than just a value, and would like to apply a pipeline stage to just subparts of that complex data. I used to have a function that did just that in python, but now it is time for javascript!

Here is one way of doing that in javascript that I just came up with. First what it looks like in practice, here we're are calling an uppercase transformation on just part of the data structure being passed through:

.then(forPaths('$', uppity)).then(

The above uppercases the value of any property named "author". With JSON path syntax we could have selected other parts too.

We are using a library called JSONPath to specify what parts of the data structure we would like to apply the function too. Here is a complete working example, using an example data structure from JSONPath's documentation:

const jp = require('jsonpath')

// Here is the general function for applying anything to any
// part of a data structure going through a promise chain.
// It is curried, so the data comes first when the pipeline is executed:

const forPaths = (pathExpr, fun) => data => {
  jp.apply(data, pathExpr, fun)
  return data

// some test data, taken from the docs for JSONPath:
var data = {
  "store": {
    "book": [
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      }, {
        "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      }, {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      }, {
         "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
    "bicycle": {
      "color": "red",
      "price": 19.95

// An example function for doing some kind of transformation, in this case convert to uppercase
const uppity = text=>text.toUpperCase()

// Finally, an example promise chain:
Promise.resolve(data).then(forPaths('$', uppity)).then(JSON.stringify).then(console.log)




Aug 09, 2018 03:50

Temperature/humidity over which we cannot exist

Posted by admin |

There is a temperature/humidity threshold over which human life even at rest, isn't possible. It's 35°C at 100% RH, according to The Economist . The limit to what conditions we can live is can be measured with wet-bulb temperature. When it goes above 35° we cannot dissipate heat from our bodies fast enough, so we start to overheat. The temperature is measured with a thermometer wrapped in wet cloth, but can also be calculated/approximated from heat, humidity, sunlight and air pressure:

The wet-bulb temperature is probably not a very good predictor of the "feels-like" temperature for most common conditions, which is why it is not used for this. However, it can be used to establish an absolute limit on metabolic heat transfer that is based on physical laws rather than the extrapolation of empirical approximations. That is why we focused on it instead of the usual measures.

See:  What is Wet Bulb temperature?

The conditions under which humans cannot exist even in permanent shade, correspond pretty well to the bottom right empty white area in the chart below from :

Click to view full-size image…
Size: 221.1 kB

The reason they list temperatures above 35°C wet-bulb in the chart earlier, is I believe because they also factor in radiation from the Israeli sun, that is you're not in the shade. Obviously this is approximate, I'm not a specialist, but this chart for hikers seems quite handy. The black area indicates forbidden conditions for even healthy & relatively fit hikers. Go to their web site to get full information!

Calculate the wet-bulb temperature:

Today the highest wet-bulb temperatures recorded in the wild, are around 31° C. If we get up to 35°C or higher in some areas, those areas are likely to be depopulated.

The maths is simple: a 4°C increase in wet bulb values creates intolerable outdoor conditions, even in the shade in some areas. The Amazon and parts of India would be first, with northern Australia and other regions with very humid summers not too far behind. Simulations of warmer climates show that this happens if the average global surface temperature rises by 6°C

See: Heat Stress in a Warming World.

Here are maps showing max heat-bulb temperatures today, and if warming goes up 10 degrees Celsius. These images published in:
Sherwood, S. C. and M. Huber, An adaptability limit to global warming due to heat stress, Proceedings of the National Academy of Sciences, Vol. 107, 2010, 9552-9555, doi:10.107/pnas.0913352107. Reprint

Pictures taken from here.

twmax highresmap sm
Click to view full-size image…
Size: 373.3 kB

twmax highresmap hot sm
Click to view full-size image…
Size: 76.8 kB


Jul 28, 2018 06:20

How to get in-page attributions semi-automatically out of Flickr

Posted by admin |

This is a stop gap solution.

First, add this to your CSS:

.attribution:hover .attribution-info {
    display: block;

.attribution-info:hover {
    display: block;
.attribution-info {
    display: none;
    background: #C8C8C8;
    margin-left: 28px;
    padding: 10px;
    position: absolute;
    z-index: 1000;


Secondly, execute this scipt on a Flickr photo page. I use tha javascript console, but I wonder if there is a way of making this into a bookmarklet:

window.prompt('Info', '<span class="attribution">(Attribution) <span class="attribution-info">Author: ' + $('.attribution-info>.owner-name').text+'<br>Source: ' + document.documentURI+'<br>License ' + $('.photo-license-url').href + '</span></span>')

Take the resulting html, and paste into your web page next to the photo.


Jun 24, 2018 03:24

Field watches is where it's at

Posted by admin |


I recently pondered if it would be time to wear a watch again…

In practice the adventurers, aviators, divers and soldiers that rendered credibility to certain watches and designs have now all but migrated to digital watches and computers. But analog watches tend to look better on your wrist.

5372909422 0d7f2cc5ba b
Click to view full-size image…
Size: 184.2 kB

A Seiko military watch (Attribution) Author: Brandon Cripps

When it comes to analog watches, there is basically two styles:

  • Dress/impress watches. Watches made to be aestethically pleasing and/or containing advanced functionality of a mostly useless nature. Although this may sound like a bit of a letdown, all analog watches fall into this group really, it's just that some pretend not to.
  • And for the second group: Watches once made for professional use. These are watches that once were the best you could have to help you in your work, whether you were a diver, an aviator, astronaut, adventurer or car racer. Today, you can get a watch model that used to fulfill one of these roles, or something that is inspired by such watches.

Strictly speaking, there is one group of analog watches that stay relevant from e.g. a prepper perspective: Mechanical watches that can withstand strong electromagnetic pulses (EMPs) such as caused by nuclear explosions. Interestingly, many of the more advanced dress-to-impress watches fall into the EMP tolerant category. It might be that even electronic watches would escape at east some EMPs; it's hard to find good info on the Internet.

3116404826 2c6aa0a6a9 b
Click to view full-size image…
Size: 404.2 kB

A Luminox field watch

I started browsing through the offerings online and in stores. Soon it became to clear to me what I wanted from an analog wristwatch:

Quickly readable

Quickly readable — A readable watch face, that is a watch face that gives you the time with the least amount of attention needed to know the time. This means:

  • Readable in darkness — Glow in the dark markings or glow in the dark watch face
  • Arabic numerals — The markings should be numbers, otherwise I could just use a compass and the sun, thank you very much (slightly exaggerated)!
  • Uncluttered — No extra decorations such  as:
    • No outer ring with diver's markings
    • No complications (complications are extra dials)
    • No date indicator, I can get that from my phone more reliably


19309888151 26a1267776 z
Click to view full-size image…
Size: 131.2 kB
A very readable Laco "1925" (Attribution) Author: Daniel Zimmermann

Other requirements

Some other things crept in to make the watch practical for me.

  • A watch body made out of titanium
  • A battery operated quartz movement, preferrably solar so I do not need to change batteries
    • Mechanical watches on the other hand get mechanical problems and hence need maintenance
  • I'm not going to spend a fortune, the threshold being around $250
  • As I learnt more, and realized that analog is all for show, I actually softened a bit on the design side. The watch I finally purchased is perfectly readable, but a bit in a 1940s retro style. There is a picture of it near the end of this post.

Field watches, aviator watches and diving watches

It turned out that there is genre of watches that ticks most of the above criteria: Field watches. Field watches belong to a category of watches for people who need to get the time quickly and reliably under field conditions. In this category you can also find diver's watches which have a rotating bezel for keeping tabs on oxygen supply and aviators' watches which have an outer ring for, for, I'm not actually sure what that ring is for (update: It is a slide rule!)


3948376935 dd847ee351 b
Click to view full-size image…
Size: 549.4 kB

A Luminox watch with a rotating bezel traditionally used for diving


5519978030 3da8e0afdd b

A Luminox watch with three complications (extra dials) and date. The stopwatch dials could come in handy for racing.
That is if you did not know that digital watches exist, or if you just want to pay hommage to old time racing

Field watches on the other hand are more targeted to infantry men, who as a rule do not need to calculate oxygen remaining or a flight path so these watches tend to be no-nonsense. Many watches at least in the aviation and field genres tend to be retro-styled, and hark back design-wise to a time where analog watches made sense for professionals in these, ehrm, fields.

Diving watches tend to focus on minutes elapsed, which dictates a lot of the design of the watch, including a rotating bezel and very clear marking of minutes. One good thing with diving watches is that they work well in darkness, and that they take pains in communicating during such conditions that the watch is still working and in distingushing the hour and minutes hands even when overlapping. Still, diving watches are being replaced by computers. The more finely marked red part of a diving watch's bezel is for ascent to the surface, although computers can now do these calculations safer and with better precision.

Click to view full-size image…
Size: 38.2 kB

Speaking about emphasizing minutes, this Oris Regulateur der Meistertaucher has nothing but a minute hand on the big dial, no hour or seconds hands; you have to look at the small dials for those

Aviator's/Pilot's/Astronaut's watches cater for the other extreme, being up in the atmosphere or even above it. At lower speeds the minutes are emphasized, at jet speeds time zones become important and for astronauts there is a logarithmic bezel on e.g. the Omega Speedmaster professional. The bezel may be used as a slide rule for doing calculations on e.g. fuel consumption.

These guys, Bremont, know how to make gorgeous looking pilot inspired watches:

5923677732 18965418df b
Click to view full-size image…
Size: 472.1 kB

This one is called "P-51", no doubt named after the  US WWII fighter plane

Ironically, aviators still seem to use and appreciate analog watches, While infantry men and divers now rely on digital computers on their wrists, many aviators already have a big honking computer in the form of a glass cockpit in front of them. So having a feeble such on the wrist may not add much.

The specialized brands — and a couple of general ones

There at least four brands that specialize in affordable field watches, and a couple of general brands that have watches in this category. The four specialized ones I've found are:

Momentum and Bertucci are most commonly of titanium, while Luminox and Timex have few offerings here. There are some more specialized brands here that I found via Ebay such as watches from Swiss army knife brands and a brand called Messerschmitt.

11244234635 d2bdaf04b6 b
Click to view full-size image…
Size: 196.0 kB

A Timex field watch

I also found nice-looking affordable field watches from general watch brands such as:

  • Citizen
  • Seiko
  • Alba (Seiko)

Citizen has the very nice Eco drive movement, which seems to last for decades without ever changing the battery.

3249931880 ba87c59f63 z
Click to view full-size image…
Size: 92.5 kB

A Citizen titanium watch in field watch style (Attribution) Author: Brent C


A Momentum titanium field watch


Aviator's and astronaut's watches

The original astronaut's watch seems to be the Omega speedmaster professional. However the movement of the newly produced watches is not the same as in those that actually went to space.

1200px Omega Speedmaster Automatic (reduced)
Click to view full-size image…
Size: 126.6 kB

An Omega Speedmaster

Aviator's watches have several roots, in France, Switzerland, Brazil, Germany, Italy, the UK and USA. The German variety seems popular and you can find watches in that design style by including the word Flieger ("pilot" in German) in your searches.

A Flieger watch claimed to be from around 1941

Here is a nice series of articles on the history of the pilot watch. It turns out that the original pilot watch brand is Cartier, for Santos-Dumont maybe as early as 1906. It is a rectangular watch with roman numerals. The next step was the brand Zenith already in 1909 setting the look of a pilot watch that we still know today.

One cool thing with some of the pilot watches is that they have a slide rule bezel. Here's how to use a slide rule bezel on an aviator's watch:

Alternatives to Titanium

If you want to avoid nickel, a nifty way of being able to wear any watch, nickel or not, is to use what is called a bund strap. Bund straps were initially made for German pilots to thermally insulate the metal watch from the wrist of the pilot. A bund strap is wider than the watch under the watch body, and then tapers off into a normal strap.

3589589735 8f6fbfd3af b
Click to view full-size image…
Size: 315.7 kB

 Sinn pilot's watch with a matching Jürgens bund strap

Another brand for Bund straps besides Jürgens, is Fluco. If you want a strap that keeps the generous width all the way round, it's called a cuff strap. Beware that the metal parts of straps may well contain nickel though!

Another option is to wear a plastic watch, but make sure it does not actually have a stainless steel back plate. Plastic is sometimes referred to as "resin".

The German Damasko brand makes its own nickel-free steel. Another German brand, Sinn, may also be nickel free.

Reading Sinn's glossary, they point out that nickel may not necessarily be released even from a nickel containing steel based alloy:

The level of nickel release is not determined by the nickel content of a metal, rather by its corrosion resistance. Only through corrosion processes can nickel escape from a steel alloy in the form of ions or complexes. In highly corrosion-resistant steel, the nickel therefore remains stably bonded in the steel even if it has a relatively high nickel content.

What I actually bought

I had done my research quite thoroughly, and here comes the problem when you've done that: You are getting so good at finding what you want that the deal you find is likely to not be around for long… I've learnt this the hard way through years of scoping out and finally deciding on a piece of merchandise. But come on, one hour!

After having looked at many Bertucci watches I finally set my eyes on a Bertucci watch with a crimson red clock face. said they only had one watch left, and so said I pondered for an hour, and then I decided to pull the trigger.

Gone. From the face of the Internet. Could not find it anywhere. I decided to stay around for a week to see if it would get re-stocked anywhere. Nope.

So after a week I decided to go for my second best choice, a classic model with a yellow/khaki clock face. I found a vendor that actually delivered to Sweden: . I pulled the trigger and they charged me, bam! I got the last one, they were now out of it. Except, that three days later they sent me an e-mail that they never had it in the first place!

Was this a sign that I should buy something else or none at all? Eventually I ordered the same watch from Long Island watch:

Click to view full-size image…
Size: 71.0 kB

And here it is!
It's chunkier, bigger and more contemporary military than I thought, and the watch face is more khaki than yellow in daylight. But overall it looks really nice.
One reason it looks so contemporary military I guess is because the sand color scheme makes it look like a watch for desert-like environments where unfortunately a lot of action has been seen recently.


One thing to look out for is if the minute hand is unaligned with the minute markings. That is, as the seconds hand strikes twelve, the minute hand is right in between two minute markings.  You can see in the picture above that — compensating for the angle of the shot — the minute hand is pretty much aligned with a minute marking on the watch face. Unfortunately the seconds hand is straight down at this point in time.

This means that in practice the precision of the resolution of telling the time is about one minute.

It's easy to fix — you can adjust the precise alignment relationship between the seconds and minute hands with the crown: Just pull out the crown when the seconds hand hits twelve and then carefully turn the crown and make the minute hand align with the desired minutes marking. Then push the crown in to make the watch start to tick again. Now the minute hand will be aligned with a marking as the seconds hand strikes twelve.

Incidentally, getting the alignment correct was a huge boost in confidence in the watch! Such a simple thing to do with a big usability/trust payoff.

Image credits/links

Jun 22, 2018 12:55

How to change a video to have one still image and all keyframes & resize it

Posted by admin |

So I wanted to produce a very small video in size, where the imagery would be meaningless but the sound ok. I needed this for testing that it actually does what it should, that is to correctly analyze how offset in time video files are that are filming the same event. I also wanted all frames to be keyframes, but since it is analyzing sound, that may not have been needed actually.

Make a video only display a static image on every frame (but still have many frames)

ffmpeg -i invideo.mp4 -i still_image.png -filter_complex "[1][0]scale2ref[i][v];[v][i]overlay" -c:a copy out.mp4

Scale the size of the video:

ffmpeg -i invideo.mp4 -filter:v scale=10:-1 -c:a copy out.mp4

The above sets the height proportinally to the width in pixels

Make a video only have keyframes

-force_key_frames 'expr:gte(t,n)'

(I think this works, haven't verified)


Jun 20, 2018 07:55