Skip to content

Instantly share code, notes, and snippets.

View mauricionobrega's full-sized avatar
:shipit:
Focusing

Mauricio Nobrega mauricionobrega

:shipit:
Focusing
View GitHub Profile
@mauricionobrega
mauricionobrega / create-tables-locally.js
Created June 5, 2022 16:11 — forked from adieuadieu/create-tables-locally.js
Using DynamoDB Locally in a Serverless Framework Project
const fs = require('fs')
const DynamoDB = require('aws-sdk/clients/dynamodb')
const yaml = require('js-yaml')
const cloudformationSchema = require('@serverless/utils/cloudformation-schema')
const SERVERLESS_CONFIG = __dirname + '/serverless.yml'
const ddb = new DynamoDB({
accessKeyId: 'fake-key',
endpoint: 'http://localhost:8001',
@mauricionobrega
mauricionobrega / .gitconfig
Created November 1, 2019 17:51 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
username = pksunkara
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
@mauricionobrega
mauricionobrega / .gitattributes
Created November 1, 2019 17:51 — forked from Voonder/.gitattributes
Sample of git config file (Example .gitconfig, .gitattributes, .gitignore)
# Auto detect text files and perform LF normalization
* text=auto
# Documents
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
@mauricionobrega
mauricionobrega / async.js
Created September 27, 2018 20:36 — forked from herrkessler/async.js
simple node async / await multiple requests with axios
const axios = require('axios');
const locations = ['London', 'San Francisco', 'Tokyo', 'Berlin'];
const apiURL = 'http://api.openweathermap.org/data/2.5/weather';
const token = 'xxxxx';
const logPosts = async () => {
try {
let allLocations = locations.map(town => axios(`${apiURL}?q=${town}&APPID=${token}`));
let weather = await Promise.all(allLocations);
@mauricionobrega
mauricionobrega / git-tag-delete-local-and-remote.sh
Created July 4, 2018 19:30 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
// List all files in a directory in Node.js recursively in a synchronous fashion
var walkSync = function(dir, filelist) {
if( dir[dir.length-1] != '/') dir=dir.concat('/')
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
@mauricionobrega
mauricionobrega / tuning_nginx_nodejs
Created June 26, 2018 20:24 — forked from carlessistare/tuning_nginx_nodejs
Tuning Nginx for heavy loading with nodejs as upstream. Short requests and a lot of concurrence.
# This number should be, at maximum, the number of CPU cores on your system.
# (since nginx doesn't benefit from more than one worker per CPU.)
worker_processes 8;
# Determines how many clients will be served by each worker process.
# (Max clients = worker_connections * worker_processes)
# "Max clients" is also limited by the number of socket connections available on the system (~64k)
# run ss -s and u'll see a timewait param
# The reason for TIMED_WAIT is to handle the case of packets arriving after the socket is closed.
@mauricionobrega
mauricionobrega / index.js
Created June 23, 2018 00:26 — forked from marcusgadbem/index.js
Middleware to minify HTML output for express template render engines in which supports callbacks
/* app/controllers/index.js */
module.exports.index = function(req, res) {
res.render('index.html');
};
@mauricionobrega
mauricionobrega / fullParallel.js
Created June 17, 2018 20:35 — forked from telekosmos/fullParallel.js
Asynchronous control flow in node.js
// FullParallel businessLogichronous engine
function fullParallel(callbacks, last) {
var results = [];
var result_count = 0;
callbacks.forEach(function(callback, index) {
callback( function() {
results[index] = Array.prototype.slice.call(arguments);
function getSubdomain(h) {
var parts = h.split(".");
if(parts.length == 2) return "www";
return parts[0];
}
//later on...
exports.index = function(req, res) {
var subdomain = getSubdomain(req.headers.host);
res.render('index', { title: 'Express', subdomain:subdomain });