Skip to content

Instantly share code, notes, and snippets.

View mpj's full-sized avatar

Mattias Petter Johansson mpj

View GitHub Profile
someOrder = {
items: [
{ name: 'Dragon food' , price: 8, quantity: 8 },
{ name: 'Dragon cage (small)', price: 800, quantity: 2 },
{ name: 'Shipping', price: 40, shipping: true }
]
}
orderTotal = (order) => {
totalNormalItems =
@mpj
mpj / 1headers.txt
Created October 16, 2017 19:04
pledge
X-Patreon-Event: pledges:create
Cf-Ray: 3aed45fb2c8851b2-SJC
User-Agent: python-requests/2.5.2 CPython/3.6.2 Linux/3.13.0-132-generic
Content-Type: application/json
Cf-Visitor: {"scheme":"https"}
Accept-Encoding: gzip
Accept: */*
Total-Route-Time: 0
Content-Length: 25417
Via: 1.1 vegur
let createGetUserName = require('./di-lib.js')
const getUsername = createGetUserName(database)
getUserName(1).then(name => console.log('the name of user 1 is', name))
@mpj
mpj / not-di-app.js
Created September 4, 2017 14:46
no di example
let getUserName = require('./not-di-lib.js')
getUserName(1).then(name => console.log('the name of user 1 is', name))
@mpj
mpj / di-app.js
Last active September 4, 2017 14:48
di example
let createGetUserName = require('./di-lib.js')
const getUsername = createGetUserName(database)
getUserName(1).then(name => console.log('the name of user 1 is', name))
@mpj
mpj / example01.js
Created August 14, 2017 07:38
Code for the async/await episode of Fun Fun Function.
const response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`)
const data = await response.json()
return data.imageUrl
}
@mpj
mpj / client.js
Created May 22, 2017 14:44
minimal json forwarder with socket io
const socket = window.io('http://localhost:3001')
socket.on('events', message => console.log('events', message) )
@mpj
mpj / maketree.js
Created May 14, 2017 12:56
Maketree for recursion episode, more functional and with better time complexity
const createChildLookupTable = categories =>
categories.reduce((lookup, child) =>
Object.assign({}, lookup, {
[child.parent]: (lookup[child.parent] || []).concat(child)
}), {})
const makeTree = (childLookup, parent) =>
(childLookup[parent] || []).reduce((node, child) =>
Object.assign({}, node, {
[child.id]: makeTree(childLookup, child.id)
@mpj
mpj / example.md
Last active May 24, 2017 13:26
x is a pronoun

X is a pronoun

Syntax Sunday Snobbery!

Some people are annoyed when I use x as a parameter name in the functions passed to functions such as filter, map or find:

let kittens = animals.find(x => x.type === 'cat' && x.ageMonths < 12)
@mpj
mpj / draft.md
Last active April 23, 2020 16:49
Feedback for episode draft: 7 critical traits for a normal programmer

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]