Skip to content

Instantly share code, notes, and snippets.

View mpj's full-sized avatar

Mattias Petter Johansson mpj

View GitHub Profile
@mpj
mpj / 1hello.md
Last active May 29, 2020 02:52
Arrow functions
@mpj
mpj / README.md
Last active December 12, 2020 00:15
REALLY quick and dirty static file dev server

Usage

node dirtyserve.js

The point your browser to

http://localhost:3000/myfile.xxx

and the server will try to serve that file from the local server.

machine:
services:
- docker
dependencies:
override:
- docker info
- docker build --tag='test_image' --file=Dockerfile.ci ..:
pwd:
backend
@mpj
mpj / monad-stream-example.js
Last active September 14, 2022 06:42
This is the code from Monads - episode #21 of FunFunFunction (https://www.youtube.com/playlist?list=PL0zVEGEvSaeFSwPn06GKArptSxiP1Gff8)
const fetch = require('node-fetch')
const Bacon = require('baconjs')
function getInPortuguese(word) {
// Google Translate API is a paid (but dirt cheap) service. This is my key
// and will be disabled by the time the video is out. To generate your own,
// go here: https://cloud.google.com/translate/v2/getting_started
const apiKey =
'AIzaSyB4DyRHIsNhogQXmH16YKbZfR-lTXrQpq0'
const url =

Prototypes

I'm mpj, and this is funfunfunction.

What are prototypes?

Let's say that you have a food type, and you want to make lots of different instances of that food, such as waffles, and I don't know why you'd want any other food than waffles, but maybe you like carrots or something. In that context, food is the prototype of waffles and carrots.

Some of you will be thinking - that reminds me of classes! You'd be right, but they are not the same thing, so try to put classes aside and think of prototypes as something completely new - if you try to shove prototypes into the same place in your brain where you keep classes you'll be very unhappy.

@mpj
mpj / temp.md
Created November 22, 2015 21:19
bah

5 tips to quickly understand a new code base

When you work as a programmer, it’s only a small percentage of your time that is spent on writing code. The vast majority of your time is spent trying to understand code that is already written. Either code of others, or code that you yourself wrote a last year.

It’s especially tricky to get into a completely new codebase. You might when you start a new job or perhaps your team takes ownership of a new system.

I have done this a couple of times now, and I have a process for it now, and I figure that it might be interesting to some people to hear about it, and that is what we are going to explore today.

In case you’re new - this is FunFunFunction, a weekly show where we try to become more confident and excited about programming by exploring old wisdom, wild ideas and having fun. At the end of this episode, I’m going to ask to subscribe.

Welcome to funfunfunction!

Today, we’re talking about Clojure, more specifically the syntax of Clojure. I’m doing this episode bit hung over because yesterday was Halloween. I was at a party with scary tales theme. This is my costume, it’s the three bears from goldilocks.

So why look at other languages? We mostly use JavaScript in this show, because it’s the lingua franca of the internet, but we really don’t want to learn JavaScript, we want to learn programming, and to do that we need to expand our horizons.

Clojure is cool because it has almost no syntax at all. Clojure really is to programming languages what the Star Wars lightsaber is to weapons. Let’s compare Clojure to JavaScript:

1 + 2 + 3;
@mpj
mpj / lol.md
Last active November 1, 2015 17:53
if(true) {
    console.log("You can have delicious soup.");
    console.log("… and a puppy!");
}
(if true 
	(do
@mpj
mpj / lol.js
Last active October 6, 2015 17:08
var bridge = require('spotify-bridge-request');
bridge.request('cosmos_request_create', [
12871287128327,
{
"action": "GET",
"uri": "sp:\/\/core-collection\/unstable\/@\/list\/tracks\/all?decorate=false&sort=addTime DESC,discNumber,trackNumber&",
"headers": {
},
"body": "{\"policy\":{\"list\":{\"link\":true}}}"
@mpj
mpj / fnuff.js
Last active October 5, 2015 21:26
const customerRevenueNode = (store) => {
return createNode({
accessMemory: {
'orderCancelled': (order) =>
_store.GetByOrderId(order.orderId)
.then((snapshot) => {
snapshot,
save: (nextState) => _store.save(nextState)