Skip to content

Instantly share code, notes, and snippets.

View kettuniko's full-sized avatar

Niko Kettunen kettuniko

View GitHub Profile
@kettuniko
kettuniko / citybike-distance.js
Created April 8, 2018 19:33
Helsinki city-bike distance calculator
// Calculates yearly distances you pedaled with Helsinki city bikes.
// Paste to browser console at https://kaupunkipyorat.hsl.fi/fi/activity
[...document.querySelectorAll('.activity-feed-item')].reduce((memo, current) => {
const departureText = current.querySelector('.departure-date').innerText
const [date] = departureText.split(' ')
const [,,year] = date.split('.')
const yearDistance = memo[year] || 0
const distanceText = current.querySelector('.covered-distance').innerText
const [distance] = distanceText.split('km')

Keybase proof

I hereby claim:

  • I am kettuniko on github.
  • I am kettuniko (https://keybase.io/kettuniko) on keybase.
  • I have a public key ASC4QB4KkLBLnkPAB0wAr7kxREwh0Xw_OnEAIRiOt_LgPwo

To claim this, I am signing this object:

module.exports = nodeCallbackFn => (...args) =>
new Promise((resolve, reject) =>
nodeCallbackFn(...args, (err, data) =>
(err ? reject(err) : resolve(data))));
@kettuniko
kettuniko / randomcolors.js
Last active October 5, 2023 20:32
Random RGBA colors with javascript
const randomNumber = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
const randomByte = () => randomNumber(0, 255)
const randomPercent = () => (randomNumber(50, 100) * 0.01).toFixed(2)
const randomCssRgba = () => `rgba(${[randomByte(), randomByte(), randomByte(), randomPercent()].join(',')})`