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 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) {
View client.html
<style>
.buttons div {
border: 2px solid black;
margin: 10px;
padding: 1rem;
font-size: 3rem;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
text-align: center;
}
View snake2.js
<title>hello!!</title>
<canvas
name=canvas
width=300 height=300 style="border: solid 2px red">
</canvas>
<script>
canvas = document.body.children[0]
context = canvas.getContext('2d')
@mpj
mpj / afternoon.html
Last active Oct 25, 2019
Neural Vanilla Workshop
View afternoon.html
<html>
<!-- http://bit.ly/vanillaneural -->
<head>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div class="legend legendX">Scariness</div>
<div class="legend legendY">Actual power</div>
<canvas id="mycanvas" width="1000" height="1000"></canvas>
View hello.html
<html>
<head>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h3>Graph: Dragons</h3>
<div class="legend legendX"><div>Scariness ️→</div></div>
<div class="legend legendY"><div>Actual Power →</div></div>
<!-- http://bit.ly/neuralvanilla -->
<canvas id="wowacanvas" width="1000" height="1000"></canvas>
View curryingetc.js
const Pusher = require('pusher')
const secrets = require('./secrets')
const Encryptor = require('simple-encryptor')
const R = require('ramda')
const encrypt = R.curry((secret, data) => Encryptor(secret).encrypt(data))
const encryptWithSecret = encrypt(secrets.e2eSecret)
const trigger = R.curry((secrets, channel, event, message) => {
const client = new Pusher({
appId: secrets.appId,
View obs.js
const delay = require('delay')
async function* makeCountingObservable() {
let count = 0
while(true) {
if (count > 4) return
await delay(1000)
yield count++
}
}
const counter = makeCountingObservable()
View sniffix.js
//@ts-check
const util = require('util')
const fs = require('fs')
const path = require('path')
const writeFile = util.promisify(require('fs').writeFile)
const readFile = util.promisify(require('fs').readFile)
function createSniffer({
fixtureDirectory,
dummy = false
@mpj
mpj / stream-speech.js
Created Oct 8, 2018
Most simple example I could find for ongoing listening of microphone using the google cloud speech api.
View stream-speech.js
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech')
const record = require('node-record-lpcm16')
const client = new speech.SpeechClient({
// generated service key downloaded from cloud console
credentials: require('./admin-key.json')
})
const sampleRateHertz = 16000
View hello.js
const fs = require('fs')
fs.readFile('hello.txt', 'utf8', (error, content) =>
content
.split('\n')
.filter(line => line.includes('dog'))
.forEach(line => console.log(line))
)
You can’t perform that action at this time.