Skip to content

Instantly share code, notes, and snippets.

Mattias Petter Johansson mpj

View GitHub Profile
@mpj
mpj / 1hello.md
Last active May 29, 2020
Arrow functions
View 1hello.md
@mpj
mpj / example01.js
Created Aug 14, 2017
Code for the async/await episode of Fun Fun Function.
View example01.js
const response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`)
const data = await response.json()
return data.imageUrl
}
View classless.md

The future is here: Classless object-oriented programming in JavaScript.

Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.

Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.

I think it's really, really sleek, and this is what it looks like:

function dog(spec) {
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Intro to XState</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="box"></div>
@mpj
mpj / order-total.js
Created Nov 26, 2017
Code from Unit testing in JavaScript Part 3 - Test runners
View order-total.js
function orderTotal(order) {
return order.items.reduce((prev, cur) => cur.price * (cur.quantity || 1) + prev, 0)
}
module.exports = orderTotal
@mpj
mpj / draft.md
Last active Apr 23, 2020
Feedback for episode draft: 7 critical traits for a normal programmer
View draft.md

7 critical traits for a normal programmer

EARLY DRAFT FOR NEXT EPISODE, PLEASE PROVIDE FEEDBACK

This week I tweeted and tooted this question:

”What do you think are critical traits in a programmer? NOT to be super 10x or anything - just to feel good and function well professionally.”

Link to full threads here: [https://twitter.com/mpjme/status/855691565460848640]

@mpj
mpj / code2.jsx
Last active Mar 24, 2020
code2.jsx
View code2.jsx
import React, { useEffect, useState } from 'react';
import logo from './logo.svg';
import './App.css';
import { Map, TileLayer, Marker, Popup, Tooltip } from 'react-leaflet'
import tmi from 'tmi.js'
// https://nominatim.openstreetmap.org/search?format=json&q=stockholm,sweden
// Firebase App (the core Firebase SDK) is always required and must be listed first
import * as firebase from "firebase/app"
@mpj
mpj / code.jsx
Created Mar 23, 2020
Code for episode
View code.jsx
import React, { useEffect, useState } from 'react';
import logo from './logo.svg';
import './App.css';
import { Map, TileLayer, Marker, Popup, Tooltip } from 'react-leaflet'
import tmi from 'tmi.js'
// !<command> <args> ? !register Sweden ?
// !checkin SE I am streaming
@mpj
mpj / remoteworking.md
Last active Mar 23, 2020
Resources and ideas for remote workers
View vanillahofs.js
const numbers = [ 2, 4, 8, 9 ]
const addTwo = number => number + 1
const isMoreThan5 = number => number > 5
const result =
//numbers.filter(isMoreThan5)
filterArray(isMoreThan5, numbers)
//mapArray(addTwo, numbers
result
function filterArray(predicate, array) {
You can’t perform that action at this time.