Skip to content

Instantly share code, notes, and snippets.

View jbutko's full-sized avatar

Jozef Butko jbutko

View GitHub Profile
@jbutko
jbutko / The shortest way to conditional insert properties into an object literal.ts
Created May 30, 2019 11:49
The shortest way to conditional insert properties into an object literal
const obj = {
...condition && { prop: value },
};
// via From https://dev.to/jfet97/the-shortest-way-to-conditional-insert-properties-into-an-object-literal-4ag7
@jbutko
jbutko / prerender-pm2-config.json
Created May 2, 2019 14:30
Prerender.io server pm2 config
{
"apps" : [{
"name" : "prerender.io",
"script" : "./server.js",
"watch" : false,
"node_args" : "--max_old_space_size=12288",
"NODE_ENV" :"prod",
"env": {
"PORT": 12345
},
@jbutko
jbutko / mongodb-force-primary-node.MD
Last active April 24, 2019 11:48
MongoDB: How to force rs slave to become primary

In a mongo shell, run rs.status() to ensure your replica set is running as expected.

In a mongo shell connected to the mongod instance running on mdb2.example.net, freeze mdb2.example.net so that it does not attempt to become primary for 120 seconds.

rs.freeze(120)

In a mongo shell connected the mongod running on mdb0.example.net, step down this instance that the mongod is not eligible to become primary for 120 seconds:

rs.stepDown(120)

@jbutko
jbutko / digitalocean-setup-private-networking.md
Last active April 19, 2019 19:28
DigitalOcean: Enable private networking between multiple droplets
@jbutko
jbutko / letsencrypt-remove-certificates.md
Created March 11, 2019 12:37
LetsEncrypt: Remove old/unused certificates

made a backup first though JIC, sudo cp /etc/letsencrypt/ /etc/letsencrypt.backup -r

Delete the ‘no longer needed domains’ in the three folders…

rm -rf /etc/letsencrypt/live/${DOMAIN}
rm -rf /etc/letsencrypt/renewal/${DOMAIN}.conf
rm -rf /etc/letsencrypt/archive/${DOMAIN}
@jbutko
jbutko / mongodb-index-size-collection.MD
Last active March 7, 2019 08:09
MongoDB: Check size of indexes in collection

list collection stats and check indexSizes

mongo
use collectionName
db.collectionName.stats()

copy indexSizes and assign it to variable (in devtools)

get sizes and total sizes:

@jbutko
jbutko / nginx-prerender-io-setup.md
Last active May 2, 2019 14:30
Nginx Prerender.io setup

1. configure nginx config (or virtual host config) which is serving your local react (or any js framework) app via this official prerender.io nginx config:

https://gist.github.com/thoop/8165802

2. install local prerender server following this tutorial

https://prerender.io/documentation/test-it

Note: if the server won't run because of missing chrome installed, then install it. On ubuntu follow this instructions: https://www.ubuntuupdates.org/ppa/google_chrome?dist=stable -> the final command is sudo apt-get install google-chrome-stable

3. start your local prerender.io server:

@jbutko
jbutko / index.tsx
Created February 19, 2019 16:56
React: Winston logger
import { createLogger, format, transports } from 'winston';
import { LOGGER_LEVEL, LOGGER_LEVELS, DEVELOPMENT_MODE } from './config';
const formatTemplate = (message, ...data) => `(${message}) ${data}`;
export default class Logger {
constructor() {
this.logger = createLogger({
format: format.simple(),
level: LOGGER_LEVEL,