Skip to content

Instantly share code, notes, and snippets.

@markmur
markmur / now.json
Last active August 17, 2018 11:45
Now: deploy, alias latest and remove old deployments
{
"name": "app-name",
"alias": "app-name.now.sh"
}
@markmur
markmur / index.js
Last active August 17, 2018 16:05
Express server
// Tell "now" to look for a now-secrets.json file
// (where we'll store our local secrets - NOT production secrets)
require('now-env')
const path = require('path')
const express = require('express')
const session = require('express-session')
const bodyParser = require('body-parser')
const morgan = require('morgan') // optional
const passport = require('passport')
@markmur
markmur / cmds.sh
Created September 10, 2018 14:42
Handy Terminal Commands
# 'cat' after first line
cat {filename} | tail -n+2
# (CSV) Get every value of first column (separated by comma)
cat {filename} | awk -F',' '{printf $1","}'
# (CSV) Get every value of first column (one per line)
cat {filename} | awk -F',' '{print $1}'
# Only print first x lines (4 in this case)
@markmur
markmur / custom-express-responses.js
Created October 17, 2018 19:36
Custom Express Responses
/**
* Create custom response
* @param {Object} res - express response object
* @param {Number} status - status code
* @param {String} defaultMessage - default response
* @returns {Function} returns function which access response message
*/
const createResponse = (res, status, defaultMessage) => data => {
// Set status code
res.status(status)
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
@markmur
markmur / settings.json
Created April 15, 2019 12:23
Set prettier as default linter in vscode (CMD + Shift + P - "Preferences: Open Settings (JSON)")
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
@markmur
markmur / sequential.js
Last active February 16, 2020 14:49
Execute async functions in series
/**
* Execute an array of async functions in series
*/
const sequential = async fns => {
const AsyncFunction = (async () => {}).constructor
// Use "some" rather than "every" here to abort faster
if (!fns.some(fn => fn instanceof AsyncFunction)) {
throw new TypeError('`fns` argument should be an array of Async functions')
}
@markmur
markmur / binary-tree-oop.js
Last active June 10, 2019 21:40
Binary Search Tree Implementation
class Node {
constructor(value, left = null, right = null) {
this.value = value;
this.left = left;
this.right = right;
}
}
class BinarySearchTree {
constructor() {
@markmur
markmur / docker-compose.yaml
Created May 21, 2019 14:01
Run Grafana & Prometheus through Docker
version: '3'
services:
grafana:
image: "grafana/grafana"
ports:
- "3000:3000"
prometheus:
image: "prom/prometheus"
ports:
- "9090:9090"
@markmur
markmur / tsconfig.json
Created January 14, 2020 13:12
TSConfig
{
"compilerOptions": {
/* Basic Options */
"target": "es5",
"module": "commonjs",
"lib": ["es2015"],
/* Strict Type-Checking Options */
"strict": true,
"typeRoots": [