This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildObject(str) { | |
var newObj = {}; | |
var len = str.length; | |
var at = 1; | |
if (str[0] != "{") | |
return null; | |
if (len < 1) | |
console.log('broke out'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This is a bad example: | |
*/ | |
const helper = require('./helper'); | |
const { user } = require('./fixture'); | |
const accounts = require('../lib/accounts'); | |
const Should = require('should'); | |
it('should work', async () => { | |
await Should(accounts.create(user.admin.registerData).be.rejected(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This is a better example that does a better job both in testing and in communicating the test-intent. | |
(with some skipped parts to keep things short) | |
*/ | |
const helper = require('./helper'); | |
const { user } = require('./fixture'); | |
const SUT = require('../lib/accounts'); | |
const Should = require('should'); | |
describe('lib/accounts - accounts service', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Consider the language did not provide us with `.indexOf` and we had to implement it ourselves. | |
Given that the factory is already implemented, how easy is it to add a new case. | |
Mind how hoisting helps keep the higher levels above, while implementation details are below. | |
*/ | |
const Should = require('should'); | |
const SUT = require('./index-of'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code concerns | |
//------------------------------------------------------------------- | |
console.log('starting greeter'); //binary+logging | |
require('http').createServer((req, res) => { //binary+app | |
const [action] = req.url.slice(1).match(/[^\/]+/); //route | |
switch(true) { //route | |
case action == 'status': //webCtrl | |
return res.end('i\'m alive'); //view+webCtrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code concern | |
//------------------------------------------------------------------- | |
const conf = () => { //config | |
views: { //config | |
status: 'i\'m alive', //config | |
greet: 'hello, %s', //config | |
help: 'supports: /greet or /status', //config | |
}, //config | |
web: { port: 3000 }, //config | |
}; //config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This demo uses an alpine sandbox in a docker container in | |
# interactive mode. ran with: | |
# docker run --rm -it alpine | |
# | |
# if you run it on your own system: | |
# 1. you should use your own package manager instead of `apk` | |
# 2. expect the following left overs: | |
# - installed binaries (age, age-keygen, sops) | |
# - $HOME/.config/sops/age/keys.txt | |
# - demo files: source.env, encrypted.env, decrypted.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:alpine-lts | |
WORKDIR /app | |
COPY packge.json . | |
RUN npm i --production | |
FROM alpine | |
RUN apk update \ | |
&& apk upgrade --no-cache \ | |
&& apk add --no-cache nodejs \ | |
&& rm -r /**/apk /**/**/apk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG TAG_NODE_BASE=lts | |
FROM node:$TAG_NODE_BASE | |
WORKDIR /app | |
RUN apk update --no-cache \ | |
&& apk upgrade --no-cache \ | |
&& apk add --no-cache \ | |
build-base \ | |
openssh \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG TAG_ALPINE_BASE=latest | |
FROM alpine:$TAG_ALPINE_BASE | |
RUN apk update --no-cache \ | |
&& apk upgrade --no-cache \ | |
&& apk add --no-cache nodejs | |
WORKDIR /app | |
RUN addgroup -S service \ | |
&& adduser -S service -G service |
OlderNewer