Skip to content

Instantly share code, notes, and snippets.

View flavioespinoza's full-sized avatar
😎

Flavio Espinoza flavioespinoza

😎
View GitHub Profile
@flavioespinoza
flavioespinoza / PascalsTriangles.js
Created June 7, 2018 14:16 — forked from kgates-github/PascalsTriangles.js
Two ways to create a Pascal's Triangle in JavaScript.
var numTiers = 100,
triangle,
start,
stop;
/**
*
* First version uses recursion
*
*/
const express = require('express')
const app = express()
const port = process.env.PORT || 9001
const http = require('http')
const index = require('./routes/index')
const server = http.createServer(app)
const socketIo = require('socket.io')
const io = socketIo(server)
const BitGoJS = require('bitgo')
const log = require('ololog').configure({locate: false})
@flavioespinoza
flavioespinoza / es2015-reduce-find-includes.js
Created June 20, 2018 23:08
ES2015 Reduce, Find, Includes
"use strict";
var myArray = [{ "shop": "shop1", "item1": "my apple 1", "item2": "my carrot 1" }, { "shop": "shop1", "item1": "my apple 1", "item2": "my carrot 1" }, { "shop": "shop2", "item1": "my apple 0", "item2": "my carrot 0" }, { "shop": "shop2", "item1": "my apple 0", "item2": "my carrot 1" }];
var MyArrayDefinition = [{ "item": "my apple 0", "color": "red", "group": "fruit", "score": 0 }, { "item": "my carrot 1", "color": "orange", "group": "vegetable", "score": null }, { "item": "my apple 1", "color": "red", "group": "fruit", "score": 1 }, { "item": "my carrot 0", "color": "orange", "group": "vegetable", "score": 0 }];
var k = Object.keys;
var items = MyArrayDefinition.reduce(function (o, v) {
return o[v.item] = v, o;
}, {});

Client/Server POST request example in pure Node.js

File server.js:

var http = require('http');
var querystring = require('querystring');

var server = http.createServer().listen(3000);

server.on('request', function (req, res) {
@flavioespinoza
flavioespinoza / secure-websockets
Created June 26, 2018 17:52 — forked from casecode/secure-websockets
Basic Config for SSL with Secure Websockets using Nginx 1.6.0 + Puma + Thin
=========================
# /etc/nginx/nginx.conf
=========================
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
@flavioespinoza
flavioespinoza / nginx-socketio-ssl-reverse-proxy.conf
Last active June 30, 2018 00:47 — forked from gmanau/nginx-socketio-ssl-reverse-proxy.conf
How to setup nginx as nodejs/socket.io reverse proxy over SSL
upstream upstream-ubuntu {
server 127.0.0.1:8080;
}
upstream upstream-nodejs {
ip_hash;
server 127.0.0.1:6001;
server 127.0.0.1:6002;
server 127.0.0.1:6003;
server 127.0.0.1:6004;
@flavioespinoza
flavioespinoza / index.html
Created July 1, 2018 22:16 — forked from RiseupDev/index.html
D3.js draw a polygon with mouse
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3 Drawing</title>
<script src="https://cdn.jsdelivr.net/d3js/3.5.9/d3.min.js"></script>
</head>
<body>
<h3>Draw a polygon :D</h3>
<script>
@flavioespinoza
flavioespinoza / .gitconfig
Created July 28, 2018 12:21 — forked from johnpolacek/.gitconfig
My current .gitconfig aliases
[alias]
co = checkout
cob = checkout -b
coo = !git fetch && git checkout
br = branch
brd = branch -d
brD = branch -D
merged = branch --merged
dmerged = "git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
st = status
@flavioespinoza
flavioespinoza / load-balancer.js
Created September 15, 2018 06:29 — forked from Zaggen/load-balancer.js
Node.js load balancer with
/*
* Author: Zaggen - 2017
* version: 0.1
* github: https://github.com/Zaggen
* Free to use and modify
* */
const httpProxy = require('http-proxy')
const http = require('http')
const proxy = httpProxy.createProxyServer({})
@flavioespinoza
flavioespinoza / async-foreach.js
Last active October 24, 2018 05:48 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)