Skip to content

Instantly share code, notes, and snippets.

function isSubset(arr, subArr) {
return subArr.every(function(value) {
return arr.includes(value)
})
}
console.log(isSubset(['A', 'D', 'E'], ['A', 'A', 'D', 'E']));
@artze
artze / multithreading.java
Last active October 4, 2018 11:04
Multi-threading with ExecutorService
public void runMultiThread() {
// Creates and makes ready a pool of 5 threads to wait for tasks
ExecutorService executorService = Executors.newFixedThreadPool(5);
// Define task for each Runnable which will be submitted to executorService for assingment to threads
Runnable task1 = () -> {
System.out.println("Inside task1 on thread: " + Thread.currentThread().getName());
try {
TimeUnit.SECONDS.sleep(10);
@artze
artze / post-receive.sh
Last active September 21, 2018 14:45
post-receive hook with npm install, build, and copying operations
#!/bin/sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "POST RECEIVE hook triggered" \
echo "POST-RECEIVE: git checkout ..."
git --work-tree=/var/repos/project --git-dir=/var/repos/project/project.git checkout -f
cd /var/repos/project
@artze
artze / ecosystem.config.js
Created September 24, 2018 16:24
PM2 config
module.exports = {
apps : [{
name : "my-app",
script : "./path/to/app/entry/point.js", // path needs to be relative from ecosystem.config.js
watch : true, // any changes to app folder will get pm2 to restart app
env : {
"NODE_ENV": "development", // define env variables here
}
}]
}
@artze
artze / export-app.js
Created October 3, 2018 11:28
Export app variable to a module
// app.js file
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = module.exports = express();
// someModule.js
const app = require('../path/to/app.js');
FROM node:8-alpine
# prepare project directory within container
RUN mkdir -p /opt/nats-streaming-console/
# Specifies the current working directory. RUN or cd commands will use this directory as reference point
WORKDIR /opt/nats-streaming-console/
# Copy source code into container
COPY <insert/source/code/path> /opt/nats-streaming-console/
# install dependencies, build application
version: '3'
services:
nats-mon:
container_name: nats-mon
image: nats-mon:latest
ports:
- 8282:8282
environment:
- STAN_URL=nats://db01.d2sphere.com:4222
let promises = [query1(), query2(), query3(), query4(), query5()]
Promises.all(promises)
.then(function(result)) {
// result here will be an array of results in the same order as promises arr
res.status(200).json(result);
}
let directorsArr = [
['Thomas', 220000],
['Michael', 200000]
]
let managersArr = [
['Robert', 100000],
['Sandra', 105000]
]
function updateSalaryPerEmployee(type, employee, grossSalaryChange) {
let updatedEmployee = employee.slice()
switch(type) {
case 'director':
updatedEmployee[1] = employee[1] + (grossSalaryChange * 0.55);
break;
case 'manager':
updatedEmployee[1] = employee[1] + (grossSalaryChange * 0.65);
break;