Skip to content

Instantly share code, notes, and snippets.

paths:
/healthcheck/ping:
get:
description: Returns the readiness of the service
operationId: ping
x-eov-operation-id: ping
x-eov-operation-handler: healthcheck
parameters:
- $ref: '#/components/parameters/x-correlation-id'
responses:
'use strict';
const express = require('express');
const cors = require('cors');
const path = require('path');
const { OpenApiValidator } = require('express-openapi-validator');
const config = require('./config');
const app = express();
const apiSpec = path.join(__dirname, `../definitions/${config.name}.yml`);
// ./src/handlers/healthcheck.js
'use strict'
function ping(_, res) {
res.status(200).json({ message: 'OK' });
}
module.exports = {
ping,
@nkhil
nkhil / smiley.md
Last active August 25, 2020 22:11

Given an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces. Rules for a smiling face:

  • Each smiley face must contain a valid pair of eyes. Eyes can be marked as : or ;
  • A smiley face can have a nose but it does not have to. Valid characters for a nose are - or ~
  • Every smiling face must have a smiling mouth that should be marked with either ) or D
  • No additional characters are allowed except for those mentioned.
  • Valid smiley face examples: :) :D ;-D :~)
  • Invalid smiley faces: ;( :> :} :]
@nkhil
nkhil / longest_palindrome.md
Last active September 14, 2020 13:58
Given a string, find the longest palindrome (JavaScript)

Find the longest palindrome (JavaScript)

This is my solution to the longest palindrome kata on Code Wars.

Solution

  function reverseString(st) {
    return st.split('').reverse().join('')
 }
@nkhil
nkhil / s3.md
Last active October 8, 2020 08:19
Creating copies of files

Create bucket 'test'

awslocal s3api create-bucket --bucket test --region us-east-1

Copy local file into S3

awslocal s3 cp test.txt s3://test/test.txt

Sum of Pairs

Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of appearance that add up to form the sum. CodeWars kata link

Note: The following solution is not by me. It was one of the first solutions in the showcase under 'Solutions'. Apologies for not attributing the authors.

var sum_pairs = function (ints, s) {
@nkhil
nkhil / logger.js
Last active February 2, 2021 20:52
testing logging to stdout in node - test setup
const logger = require('./logger.js');
logger.info({ foo: 'bar' }, 'param2');
// Outputs:
// {"level":30,"time":1612298595613,"msg":"param2","pid":3039,"hostname":"whatever","foo":"bar","v":1}
const path = require('path');
const { spawn } = require('child_process');
// Run using Jest
describe('logger behaviour', () => {
it('logs out multiple params - 2 strings', done => {
const testAppFilePath = path.join(
__dirname,
'../logger.js',

Agenda investigation spike

Attempt 1:

BEHAVIOUR: This enforces only one instance carrying out jobs at a time

const Agenda = require('agenda');