Skip to content

Instantly share code, notes, and snippets.

@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: ;( :> :} :]
// ./src/handlers/healthcheck.js
'use strict'
function ping(_, res) {
res.status(200).json({ message: 'OK' });
}
module.exports = {
ping,
'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`);
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:

Quick reference for using node-scheduler

Every 5 seconds

const x = schedule.scheduleJob('*/5 * * * * *', function() {
  console.log('The answer to life, the universe, and everything!');
});
{
"window.zoomLevel": 0,
"terminal.integrated.shell.osx": "zsh",
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"editor.minimap.enabled": false,
"workbench.iconTheme": "material-icon-theme",
"workbench.editor.enablePreview": false,
"editor.tabSize": 2,
"editor.rulers": [100],
@nkhil
nkhil / mongodb_cheat_sheet.md
Last active May 31, 2020 19:35 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

const property = obj[key];
// obj[key] here will be '1991'.
acc[property] = acc[property] || [];
// At this point acc['1991'] doesn't yet exist, so it will be an empty array. This step is important as it checks if acc['1991'] exists, and if not, creates it and assigns a value of an empty array.
acc[property].push(obj);
// Here, all we're doing is pushing our object into the right group
function groupBy(key) {
return function group(array) {
return array.reduce((acc, obj) => {
const property = obj[key];
acc[property] = acc[property] || [];
acc[property].push(obj);
return acc;
}, {});
};
}
{
'Pearl Jam': [
{
artist: 'Pearl Jam',
album: 'Ten',
year: '1991',
},
{
artist: 'Pearl Jam',
album: 'Yield',