salonanarchist | leunstoelactivist

Data

Embedding tweets in Leaflet popups

I just created a map showing where so-called Biro’s (small cars) are parked on the pavement and annoying people. Twitter has quite a few photos of the phenomenon. In some cases, finding their location took a bit of detective work.

First you’ll need the embed code for the tweet. You can get it manually from the Twitter website, but if you want to automate your workflow, use a url like the one below. It’ll download a bit of json containing the embed code:

https://publish.twitter.com/oembed?url=https://twitter.com/nieuwsamsterdam/status/958761072214896640

When trying to embed the tweets in Leaflet popups, I ran into a few problems:

  • When popups open, the markers didn’t properly move down. As a result, most of the popup would be outside the screen. The problem and how to solve it are described here.
  • Twitter embed code contains a script tag to load a widget. Apparently you can’t execute javascript by adding it directly to the html for the popup content, but you can add it using a selector (cf here).

Here’s the code that’ll solve both problems:

map.on('popupopen', function(e) {
    $.getScript("https://platform.twitter.com/widgets.js");
    var px = map.project(e.popup._latlng); 
    px.y -= e.popup._container.clientHeight;
    map.panTo(map.unproject(px),{animate: true});
});

You may also want to do something about the width of the popups, because otherwise they will obscure most of the map on mobile screens and it will be difficult to close a popup (which you can normally do by clicking outside of the popup). You can change the width of embedded tweets, but this will not change the width of the popup itself. A simple solution is to give popups a maxWidth of 215 (.bindPopup(html, {maxWidth: 215})).

Of course, you could also vary maxWidth depending on screen width, but I think 215px works well on all screens. Further, embedded tweets appear to have a minimum width of about 200px, so if you want popups narrower than 215px you’ll have to figure out a way to fix that.

If you embed tweets, Twitter can track people who visit your webpage. Add <meta name="twitter:dnt" content="on"> to your page and Twitter promises they won’t track your visitors. I wasn’t sure whether this should be put in the web page itself or in the html content of the popups (I opted for both).

If the popups have a somewhat spartan look and do not contain photos: Good for you! You’re probably using something like Firefox with tracking protection enabled. This blocks sites which have been identified as ‘engaging in cross-site tracking of users’ - including, apparently, platform.twitter.com.

New Year - time to delete your Facebook account?

Around New Year, people turn to Google for advice on how to accomplish their New Year’s resolutions. The chart below (an update of one I created earlier) illustrates this.

Around New Year, there’s is a peak in people googling ‘quit smoking’, but it appears that even more people to try to figure out how to delete their Facebook account. The parallel is not entirely surprising, given claims that platforms like Facebook are designed to be addictive.

Chart updated 1 January 2018

Van vloeken ga je harder fietsen

In een experiment lieten wetenschappers proefpersonen 30 seconden lang op een hometrainer fietsen. Elke drie seconden moesten ze ofwel vloeken, ofwel een neutraal woord uitspreken. Bij het vloeken produceerden ze gemiddeld 429W (met een piek van 570W). In de controlegroep was dat 417W (met een piek van 545W).

Deelnemers in de vloeken-conditie raakten wel sneller vermoeid. Blijkbaar ga je van vloeken wel wat sneller fietsen, maar is het effect van korte duur.

En 429W, is dat veel? Ik zou het niet weten, maar hier zijn wat cijfers om mee te vergelijken. Volgens Cyclist kan de Duitse sprinter André Greipel 30 seconden lang meer dan 1.000W volhouden, terwijl Cyclist’s resident crit racer 600W haalt. En voor wat het waard is, op deze pagina wordt opgeschept over meer dan 900W gedurende 30 seconden.

Terug naar het experiment: met zo’n onderwerp wil je weten hoe het onderzoek is uitgevoerd. Vooral ook wat voor krachttermen (no pun intended) ze hebben gebruikt. Dat vermelden de onderzoekers niet: de deelnemers werd gevraagd welk woord ze zouden gebruiken als ze per ongeluk hun hoofd stoten. In de controleconditie werd ze gevraagd met welk woord ze een tafel zouden omschrijven.

De deelnemers kregen als instructie dat ze niet moesten schreeuwen, maar wel een ‘krachtige en heldere stem’ moesten gebruiken en dat ze tijdens de hele test in het zadel moesten blijven zitten. Tijdens de test werden ze aangemoedigd door de onderzoekers.

Je zou denken dat dit wel een leuk experiment is om aan mee te doen, maar blijkbaar gold dat niet voor iedereen. Van de 35 oorspronkelijke deelnemers vielen er zes af: twee konden het experiment niet afronden, één werd ziek en drie trokken zich terug.

Richard Stephens, David K. Spierer, en Emmanuel Katehis, Effect of swearing on strength and power performance. Psychology of Sport & Exercise 35:111–117. Verschijnt in maart 2018.

Swearing will boost your cycling speed

In an experiment, scientists had people ride an excercise bicycle for 30 seconds. Every three seconds they had to either say a swearword, or say a neutral word. When swearing, participants produced an average power of 429W (peak power 570W), compared to 417W (peak power 545W) for the participants in the control condition.

However, participants in the swearing condition also were more fatigued. It appears that swearing will help you ride a bit faster, but only for a short while.

And 429W, is that a lot? I wouldn’t know, but here are some figures for comparison. According to Cyclist, German sprinter André Greipel can keep up over 1,000W for 30 seconds, while Cyclist’s resident crit racer can do 600W. For what it’s worth; this page has people bragging about producing more than 900W for 30 seconds.

Back to the experiment: with a topic like this, you want to know how the research was done. Especially which swearwords were used, but that’s not reported. Participants were asked for a word they might use when they bang their head accidentally. In the control condition, they were asked for a word they would use to describe a table.

Participants were instructed not to shout, but to use a ‘strong and clear voice’, and to remain seated in the saddle during the entire test. During the test, participants were encouraged by research staff.

You’d expect this to be a fun experiment to take part in, but apparently it wasn’t for everybody. Out of 35 original participants, six dropped out: two were unable to finish the protocol, one was taken ill and three withdrew.

Richard Stephens, David K. Spierer, en Emmanuel Katehis, Effect of swearing on strength and power performance. Psychology of Sport & Exercise 35:111–117. Due for publication March 2018.

Pages

Schrijf je in voor de wekelijkse nieuwsbrief