Skip to content

Instantly share code, notes, and snippets.

View selbekk's full-sized avatar
👨
Working dad

Kristofer Giltvedt Selbekk selbekk

👨
Working dad
View GitHub Profile
@selbekk
selbekk / date_article_6.js
Created June 12, 2018 19:31
Object arithmetic
const object = {};
object + object
// "[object Object][object Object]"
object - object
// NaN
object * object
// NaN
object / object
// NaN
@selbekk
selbekk / date_article_5.js
Created June 12, 2018 18:17
Not even cool bruh
const myBirthday = new Date('1987-07-22');
const myPartnersBirthday = new Date('1988-06-08');
const together = myBirthday + myPartnersBirthday;
// "Wed Jul 22 1987 02:00:00 GMT+0200 (CEST)Wed Jun 08 1988 02:00:00 GMT+0200 (CEST)"
const myBirthday = new Date('1987-07-22');
const rightNow = new Date();
const numberOfMsIHaveLived = rightNow - myBirthday;
// 974911520369 or thereabouts
const milliseconds = +new Date();
const milliseconds = Date.now();
@selbekk
selbekk / date_article_1.js
Created June 12, 2018 16:30
How to get the milliseconds since epoch
const aDateInstance = new Date();
const millisecondsSince1970 = aDateInstance.getTime();
@selbekk
selbekk / dispatcher-patterns-02-simple-usage.js
Created June 2, 2018 09:25
Simple usage of a dispatcher
import React, { Component } from 'react';
import { connect } from 'react-redux';
import * as dispatchers from '../dispatchers';
class ProfilePage extends Component {
componentDidMount() {
this.props.getUser();
}
render() {...} // Not really relevant here
}
import * as actions from '../actions';
const getUser = () => async dispatch => {
dispatch(actions.getUserRequested());
const response = await fetch('/api/user');
const user = await response.json();
dispatch(actions.getUserReceived(user);
};
@selbekk
selbekk / time_sensitive_timeproxy_tagged_template_literals_examples.js
Created April 26, 2018 16:54
Time sensitive timeproxy examples with tagged template literals
import tp from 'timeproxy';
const SESSION_EXPIRES = tp`in 30 seconds`;
const OLD_POST_TIMESTAMP = tp`two weeks ago`
@selbekk
selbekk / more_timeproxy_tagged_template_literals_example.js
Created April 26, 2018 16:52
More timeproxy examples with tagged template literals
import tp from 'timeproxy';
const TIME_UNTIL_NEXT_PUSH = tp`one week and a day`;
const SHOW_DONT_LEAVE_DELAY = tp`12 minutes 2 seconds`;
const WOW = tp`9 weeks twelve days and .5 seconds`;