Skip to content

Instantly share code, notes, and snippets.

Mattias Petter Johansson mpj

Block or report user

Report or block mpj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View functional.js
const fetch = require('node-fetch')
const fs = require('fs')
require('dotenv').config();
const accessToken = process.env.PATREON_ACCESS_TOKEN
const pageCount = 100
const url = `https://www.patreon.com/api/oauth2/api/campaigns/1137737/pledges` +
`?type=pledge&sort=created&page%5Bcount%5D=${pageCount}&access_token=${accessToken}`
const getPatreonData = function (url, pledges = []) {
View snippet.js
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 =
View 1headers.txt
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
View di-app.js
let createGetUserName = require('./di-lib.js')
const getUsername = createGetUserName(database)
getUserName(1).then(name => console.log('the name of user 1 is', name))
View not-di-app.js
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 Sep 4, 2017
di example
View di-app.js
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 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
}
@mpj
mpj / client.js
Created May 22, 2017
minimal json forwarder with socket io
View client.js
const socket = window.io('http://localhost:3001')
socket.on('events', message => console.log('events', message) )
@mpj
mpj / maketree.js
Created May 14, 2017
Maketree for recursion episode, more functional and with better time complexity
View maketree.js
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
x is a pronoun
View example.md

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)
You can’t perform that action at this time.