Skip to content

Instantly share code, notes, and snippets.

@andrIvash
andrIvash / node-setup-pm2-nginx.md
Created June 17, 2018 12:02 — forked from tomysmile/node-setup-pm2-nginx.md
Setup NodeJS Production with PM2, Nginx in Ubuntu 16.04

How To Set Up a Node.js Application for Production on Ubuntu 16.04

with PM2 & Nginx

Create User

as a root, run below commands on server:

# adduser tomy
@andrIvash
andrIvash / formDataToJSON.js
Created April 25, 2018 14:55
formDataToJSON
export default function formDataToJSON(formData) {
const data = {};
for (const key of formData.keys()) {
data[key] = formData.get(key);
}
return data;
}
@andrIvash
andrIvash / main.scss
Created April 14, 2018 12:25
css features
html {
font-size: calc(1vw + 1em)
}
@andrIvash
andrIvash / hw-node-2_1.js
Created March 6, 2018 14:26
hw-node-2_1
const http = require('http');
const time = 20;
const interval = 1;
const port = 8080;
const server = http.createServer(function(req, res){
if (req.method === 'GET' && req.url !== '/favicon.ico') {
console.log('********START timer***********');
const inttime = setInterval(() => {
console.log('echo time = ', Date());
@andrIvash
andrIvash / hw-node-2.js
Last active March 5, 2018 20:43
hw-node-2
const http = require('http');
var INTERVAL = process.argv[2] || 1000;
var TIME = process.argv[3] || 10000;
let clientId = 0;
async function consoleDateAndTime (id) {
let clock = setInterval(() => {
console.log(`Client: ${id}, Clock: `, new Date());
@andrIvash
andrIvash / direction.js
Created February 19, 2018 10:32
get direction of mouse
var getDirection = function (ev, obj) {
var w = obj.offsetWidth,
h = obj.offsetHeight,
x = (ev.pageX - obj.offsetLeft - (w / 2) * (w > h ? (h / w) : 1)),
y = (ev.pageY - obj.offsetTop - (h / 2) * (h > w ? (w / h) : 1)),
d = Math.round( Math.atan2(y, x) / 1.57079633 + 5 ) % 4;
return d;
};
@andrIvash
andrIvash / node-npm-install.md
Created January 17, 2018 11:15 — forked from rcugut/node-npm-install.md
Install node & npm on Mac OS X with Homebrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

@andrIvash
andrIvash / multiple_ssh_setting.md
Created January 11, 2018 08:25 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@andrIvash
andrIvash / pr-waterfall2.js
Last active January 7, 2018 17:19
promise waterfall2
getJSON(url) // response.results - array of urls
.then(response => Promise.all(response.results.map(getJSON)))
.then(arrayOfPlanetData => arrayOfPlanetData.forEach(planet => createPlanetThumb(planet))
.catch(error => console.log(error));
@andrIvash
andrIvash / pr-waterfall.js
Created December 21, 2017 20:23
promise waterfall
function delay(ms) {
return () => {
return new Promise(resolve => setTimeout(() => {
resolve();
console.log('!!!');
}, ms));
}
}
function waterfall(list) {