Skip to content. | Skip to navigation

Personal tools
Log in
You are here: Home - Blog

Combining lodash/fp with promise chains

Posted by admin |
const P = require('bluebird')

const f = require('lodash/fp')

Jul 15, 2016 06:15

Blockchains may bring truth back to the news landscape

Posted by admin |

When self-published hypertext went global with web pages and blogs, there were high hopes for a truly democratic news landscape. Many believe we have instead got:

  • populism
  • insularity
  • and paranoia.

How technology disrupted the truth | Katharine Viner | Media | The Guardian

However if one looks at it from a grander perspective, it was a given that the old model of mainly hierarchical trust had to go. Luckily, there is a new trust model in the works: Blockchains.

  • They allow signed reports to be time-stamped in a way that everybody agrees on. This gives agreed causality, i.e. you can agree that X was reported before Y.
  • They prevent the signing party to divulge different reports to different people, i.e. it enforces actors to be coherent. This is called solving the double spending problem.
  • They allow people to watch the message flow that builds up the blockchain, to detect if some stuff gets delayed and other stuff favored.


Blockchains are not all that easy to understand at first, but what they basically do is to assign different people to be notaries of what has happened, in a way that is hard to predict, a bit like in a lottery.

This will not be an easy path forward, there will be false starts and faulty blockchain models, different models need to be tested and people must get used to:

  • Signing stuff and
  • Learn how to use and trust a web of trust


We all must learn the skills of:

  • Weighing evidence,
  • Establishing causality chains and
  • Gauging the reputations of those who report the news


But I believe this is the way forward and it is given the confusion we live with on-line now, high time we get this baby rollin'!



Jul 12, 2016 12:50

Fixing Ubuntu 16.04 "Networking disabled" after sleep

Posted by admin |

This worked for me:

sudo service network-manager restart

These did not work for me:

  • Any invokation using nmcli
  • sudo service networking restart


Jul 11, 2016 12:14

Don't buy a universal charger for your laptop

Posted by admin |

Don't buy a universal charger for your laptop, it may end up damaging your laptop, so that it does not charge again. Instead have a spare original-brand charger that you store separately. If you are travelling, pack it e.g. in a different bag so you don't lose it at the same time as the charger you're using.

Update 2016-07-08: I now have an OEM charger and the flashing of the keyboard backlight has stopped, and charging seems to work. Last night, with the universal charger, it both flashed and refused to charge which made the OS shut down the laptop. However with the new OEM charger, no flashing and it seems to charge just fine. It could have been as simple as the universal charger not having enough juice to drive the laptop and charge it, when the battery is close to empty. In that case there was maybe no risk for damaging the laptop. However the OEM charger is only rated at 3.42A and the T'nB universal charger at 4.7A, so the universal charger should have no problem. Still something goes wrong.

Longer story

Last week I lost a charger for my Acer laptop at the Vivatech fair in Paris. Totally my own fault, just forgot it in the wall socket and it was never retrieved. I still needed my laptop so what to do on a Sunday in Paris? I went to fnac and got me a universal charger, that should work with Acer. Before buying it I searched the Internet for info on universal chargers and to my dismay I read that they have a history of destroying laptops, such as the charging circuitry part.


I bought one anyway and at first it seemed fine.

But I thought about it, and remembered that I did buy a universal charger for my previous laptop too, a Dell. And that worked fine. I had to change the battery shortly afterwards because the computer did not run without the power cable plugged in. So I bought a new battery. That did not work either. Oh my! I realised that it is quite likely that it was the universal power charger that put my previous laptop out of commission.

With my current laptop, I have noticed that the backlight of the keyboard has started flasing in pulses and the battery does not charge. An original charger should arrive tomorrow. I hope I have not destroyed one more laptop...


Jul 08, 2016 12:55

How to detect if a motor moves

Posted by admin |

I'm gonna copy a part of Reddit user gnorty's comment and paste here:

1- detect the physical rotation - you could use an encoder, a magnetic region on the rotor and a reedswitch, a high contrast colour change and a photodetector, a physical gap in the rotating part and a proximity switch/laser/other thing that "sees" the change. Any of these work essentially the same way - if you don't see the signal change in a set time you can assume no rotation.

2- Sense the current on the motor. Most types of motor will draw a higher current according to the torque it is applying. You can measure this current and if it rises significantly above "normal" you can again assume something is wrong with either the motor or the mechanical movement. Obviously the same if the current is too low. Most motors use this system to some extent, as the high current will trip the motor protection (fuse, breaker etc). Some breakers have very precise settings for exactly this purpose.

Read more: Link - How do you detect if a motor fails to move? : arduino

Jul 07, 2016 12:55

Brexit, Pax Americana & urholkningen av Europa

Posted by admin |

Det här (Brexit) var inte roligt. USA:s makt minskar i världen, och EU har vuxit fram för att axla ett ansvar efter Pax Americana. Men utan Storbritannien består EU bland annat av veliga västmakter (Tyskland), ett Frankrike som nu också kan tänkas gå ur och som har nog med sina egna problem, och ett antal för detta östländer där flera också går åt det nationalistiska hållet.

En bra grej med demokrati är att det är en lärande organisation, att man lär sig av de beslut man gör, korrigerar och fortsätter. Besluten och konsekvenserna blir ett slags institutionellt minne. Men ibland undrar man om det finns tid att lära; svängningarna går så fort.

Brexit, Trump, Erdogan, Polens nya regering, Fidesz, Front National i Frankrike och sverigedemokraterna ser jag som symtom på samma sak:  Elitens misslyckande att förankra sig i folklagren. Jag tror den ekonomiska politiken med QE och annat har ställt till det mycket på en kognitiv nivå: Det har uppstått en desorientering ( se ) . Och när desorienteringen sätter in så försvinner förtroendet för eliten.

Jag vet inte om det är bara jag som fast jag inte levde då ändå på något sätt har den omedelbara tiden efter 2:a världskriget i minne. Jag är inte alls säker på att man kommer att kunna bygga upp något nytt ur spillrorna av EU. De demokratiska instinkterna är inte så starka över kontinenten utan har ofta påbjudits av USA. Sveriges totala oförmåga att försvara sig, inkompetens vad gäller polis mm visar på en institutionell urholkning.  I USA har partierna föga makt över de nya politikerna: Trump, Cruz, Sanders:

Klaus Mann råkade på en svensk intellektuell efter kriget och deras konversation säger en del om tillståndet då:
Glad midsommar! :D

Jun 24, 2016 12:08

A new generation of hashing algorithms

Posted by admin |

A competition was held and Argon2 was selected as winner:

Password Hashing Competition

It seems one of the traits they were looking at was resistance to ASIC optimization.

Honorable mentions of Catena, Lyra2, Makwa and Yescrypt.

Jun 23, 2016 03:52

Some languages that compile to javascript

Posted by admin |

Most of these untested by me.

Scala.js Scala.js

Clojurescript clojure/clojurescript: Clojure to JS compiler


    ClojureScript currently only supports integer and floating point literals that map to JavaScript primitives
        Ratio, BigDecimal, and BigInteger literals are currently not supported
        Equality on numbers works like JavaScript, not Clojure: (= 0.0 0) => true

Kotlin JavaScript Interop | Kotlin Blog

Nim Nim Backend Integration

Features or modules that the JavaScript platform does not support are not available. This includes:

    manual memory management (alloc, etc.)
    casting and other unsafe operations (cast operator, zeroMem, etc.)
    file management
    most modules of the Standard library
    proper 64 bit integer arithmetic
    unsigned integer arithmetic




Jun 22, 2016 10:07

Error control flow in javascript promise chains (bluebird)

Posted by admin |

You can catch an error, but what does that mean for the control flow?

Consider this test script:

const P = require('bluebird')
function bad(){
return sdfffsf // this will throw an error
P.resolve(8).then(x=>x).then(bad).catch(e=>console.log('We got an error' + e)).then(x=>console.log('We got here' + x))

That script will print "We got here". The chain was not terminated early due to the error, because we put an error handler in between the function that threw the error and the function that printed to the console.

However, this will not print "We got here" because the error handler is after the print statement.

const P = require('bluebird')
function bad(){
return sdfffsf
P.resolve(8).then(x=>x).then(bad).then(x=>console.log('We got here' + x)).catch(e=>console.log('We got an error' + e))


So in a nutshell, .catch allows you to skip from the point of error and resume execution in the pipeline at an arbitrary point down the line. Remember to rethrow the error unless you want the rest of the pipeline after the catch handler to get executed.

Jun 18, 2016 01:00

Making find ignore directories or other stuff with -prune

Posted by admin |

(Warning: correct syntax with faulty explanations follow)

This was a real head scratcher for me. There is a -prune flag you can add to the find command on e.g. the Linux command line. It prunes stuff. So my first thought was that it takes an argument after itself for what needs to be pruned. It does not.

Instead it takes arguments before itself and uses them for what to prune out of the find results. But wait, it gets weirder: -prune returns true, which means that the stuff in front of -prune will still be there. What you need is to put an -o flag after prune. Now what is that? The total amount of documentation in the find man page about -o on my Ubuntu 16.04 is this:

       The POSIX standard specifies parentheses `(', `)', negation `!' and the `and' and `or' operators ( -a, -o).

So -o is the or operator. And -prune returns true. I don't know what programming languages you are used to, but in the ones I am used to, if the left hand side returns true with the or operator, the right hand side is not evaluated at all. If you want the right hand side to be evaluated too, you would stick an and operator in between.

So anyway, here is the way to do it

find [stuff you do not want to find] -prune -o [stuff you want to find] -print

You also need the -print flag at the end, because reasons. I guess the implicit -print you usually get in find, gets lost somewhere. Without an explicit -print, it prints. Everything.

Incidentally, if you change the -o to an -a, nothing gets printed.

Actually I think I just got it, one should think like this:

find [path] - "I'm gonna find anythyng in my path. Anything"

[stuff you do not want to find] - find all this stuff, yeah  this is what matched

-prune - "Return true! Because reasons"

-o - Ignore that shit, just terminate it, let's instead talk about this:

[stuff you want to find] - The stuff I really want. It magically got here because -prune did not return true for it. Or whatever.

-print - Hi, I'm print. I crowd out implicit prints, maybe. And I bind tight to the right hand side, so never heard of the left hand stuff.

So the or operator gets false for the files and dirs not matched by -prune, so it tries the right hand side. But wait, if this is the way it works, maybe -prune is kind of redundant. Yup, on my machine these give the same results back:

$ find -path "*/node_modules/*" -prune -o -name "*.js" -print
$ find -path "*/node_modules/*" -o -name "*.js" -print

Go figure. Maybe they are not always equivalent.


Jun 16, 2016 11:05