Skip to content

Instantly share code, notes, and snippets.

@janneh
janneh / binding.gyp
Created January 15, 2017 11:41
node-gyp go
{
"targets": [
{
"target_name": "calculator",
"sources": [
"calculator.cc"
],
"libraries": [
"../calculator.a"
],
@janneh
janneh / output.js
Last active December 28, 2016 23:06
dispatch logic
function output(a, b, format = 'text') {
const dispatchTable = {
"text": textOutput,
"html": htmlOutput
}
if (dispatchTable[format] === undefined) {
throw new Error(`unknown format ${format}`)
}
@janneh
janneh / jwt-auth.js
Last active November 29, 2016 10:52
Auth middleware for JWT:s
// `jwt` is the encoded JSON Web Token
// `token` is the decoded jwt
// jwtFromRequest(req: Request): String
// algorithmFromToken(token: Object): String
// keyFromToken(token: Object): Promise<key: string>
const auth = fucntion({ jwtFromRequest, keyFromToken, algorithmFromToken }) {
return (req, res, next) => {
const jwt = jwtFromRequest(req)
@janneh
janneh / parse.js
Created November 28, 2016 21:01
Parse Authorization Bearer Header
const parseAuthorizationBearer = req => {
if (!req.headers.authorization) return
const headerParts = req.headers.authorization.split(' ')
if (headerParts[0].toLowerCase() === 'bearer') return headerParts[1]
}
@janneh
janneh / flux-standard-action.ts
Created October 30, 2016 20:16
Flux standard action interface
interface FluxStandardAction {
type: string | symbol | any;
payload?: any;
error?: boolean | any;
meta?: any
}
@janneh
janneh / index.html
Created October 28, 2016 06:57
Base playing around with testing redux-observable
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/redux@^3.5.2/dist/redux.min.js"></script>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.0-beta.12/dist/global/Rx.js"></script>
<script src="https://unpkg.com/redux-observable/dist/redux-observable.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
@janneh
janneh / unit-test.js
Created July 1, 2016 07:52
Unit test template for JS
import test from 'tape';
test('What component aspect are you testing?', assert => {
const actual = 'What is the actual output?';
const expected = 'What is the expected output?';
assert.equal(actual, expected, 'What should the feature do?');
assert.end();
});
@janneh
janneh / package.json
Created June 10, 2016 09:24
Node with async await using babel-node
{
"babel": {
"plugins": [
"transform-es2015-modules-commonjs",
"syntax-async-functions",
"transform-async-to-generator"
]
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "6.8.0",
@janneh
janneh / cache.js
Created June 1, 2016 05:15
Simple cache
const cache = new Map()
service.get = uri => {
if (!cache.has(uri)) {
cache.set(uri, fetch(uri))
}
return cache.get(uri)
}
@janneh
janneh / generate-icons.md
Created May 13, 2016 08:52
OS X - generating .incs from 1024 x 1024 png file
mkdir icons.iconset
sips -z 16 16     icon1024.png --out icons.iconset/icon_16x16.png
sips -z 32 32     icon1024.png --out icons.iconset/icon_16x16@2x.png
sips -z 32 32     icon1024.png --out icons.iconset/icon_32x32.png
sips -z 64 64     icon1024.png --out icons.iconset/icon_32x32@2x.png
sips -z 128 128   icon1024.png --out icons.iconset/icon_128x128.png
sips -z 256 256   icon1024.png --out icons.iconset/icon_128x128@2x.png
sips -z 256 256   icon1024.png --out icons.iconset/icon_256x256.png
sips -z 512 512 icon1024.png --out icons.iconset/icon_256x256@2x.png