Skip to content

Instantly share code, notes, and snippets.

View Raidus's full-sized avatar

Wilhelm R. Raidus

View GitHub Profile
@Raidus
Raidus / DCOKER COMMANDS.sh
Last active March 17, 2019 14:43 — forked from bahmutov/Docker shell commands.sh
A personal cheat sheet for running local Node project in a Docker container
# See list of docker virtual machines on the local box
$ docker-machine ls
NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
# Note the host URL 192.168.99.100 - it will be used later!
# Build an image from current folder under given image name
$ docker build -t gleb/demo-app .
@Raidus
Raidus / loadcheerio.js
Last active February 6, 2019 17:56
Load cheerio parser in Puppeteer/Chrome
// Inspired by: https://docs.k6.io/docs/modules#section-npm-modules
// 1. Browserify cheerio module
/*
git clone git@github.com:cheeriojs/cheerio.git
cd cheerio
npm install
browserify index.js -s cheerio > cheerio.js
*/
@Raidus
Raidus / nginx.conf
Created December 7, 2018 09:32 — forked from v0lkan/nginx.conf
Configuring NGINX for Maximum Throughput Under High Concurrency
user web;
# One worker process per CPU core.
worker_processes 8;
# Also set
# /etc/security/limits.conf
# web soft nofile 65535
# web hard nofile 65535
# /etc/default/nginx
@Raidus
Raidus / nginx-tuning.md
Created December 7, 2018 09:25 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@Raidus
Raidus / redis_cheatsheet.bash
Created December 2, 2018 09:48 — forked from LeCoupa/redis_cheatsheet.bash
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.
require('dotenv').config()
const cors = require('cors')
const bodyParser = require('body-parser')
const express = require('express')
const expressJwt = require('express-jwt')
const cookieSession = require('cookie-session')
const jwt = require('jsonwebtoken')
const passport = require('passport')
const GoogleStrategy = require('passport-google-oauth20').Strategy
const jwtSecret = Buffer.from('Zn8Q5tyZ/G1MHltc4F/gTkVJMlrbKiZt', 'base64')
@Raidus
Raidus / amqplib-delayed-message.js
Created September 14, 2018 11:10 — forked from materkel/amqplib-delayed-message.js
Scheduling messages with RabbitMQ, using the rabbitmq_delayed_message_exchange plugin and amqplib in NodeJS
/**
* Install and enable the rabbitmq_delayed_message_exchange plugin as described by Alvaro Videla in this blogpost:
* https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq/
*/
const amqp = require('amqplib');
const exchange = 'yourExchangeName';
const queue = 'yourQueueName';
const queueBinding = 'yourQueueBindingName';
// Message consumer
@Raidus
Raidus / curl.js
Created August 30, 2018 08:51 — forked from schamane/curl.js
Curl vs http module for nodejs
var exec = require('child_process').exec,
url = "http://google.com/",
timeout = "3",
data="?q=test";
var time = process.hrtime();
exec('curl --max-time ' + timeout + ' -d \'' + data + '\' ' + url, function (error, stdout, stderr) {
var diff = process.hrtime(time);
//console.log('stdout: ' + stdout);
//console.log('stderr: ' + stderr);
const winston = require('winston');
const fs = require('fs');
const path = require('path');
const dir = path.resolve(__dirname, '../logs/');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
@Raidus
Raidus / getdates.js
Created June 29, 2018 13:13 — forked from miguelmota/getDates.js
Get dates in between two dates with JavaScript.
// Returns an array of dates between the two dates
var getDates = function(startDate, endDate) {
var dates = [],
currentDate = startDate,
addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
};
while (currentDate <= endDate) {