Skip to content

Instantly share code, notes, and snippets.

View MorenoMdz's full-sized avatar
🎯
Focusing

MorenoMdz

🎯
Focusing
  • Self
  • Florianópolis
View GitHub Profile
@MorenoMdz
MorenoMdz / filterVirtual.js
Created November 19, 2018 00:30
Mongoose JS filter a virtual field by its length
exports.getNewProblemsList = async (req, res, next) => {
const page = req.params.page || 1;
const limit = 10;
const skip = page * limit - limit;
const problemPromise = Problem.find()
.populate('author hardware repairsV', 'name')
.skip(skip)
.limit(limit)
.sort({ created: 1 })
@MorenoMdz
MorenoMdz / es2018.js
Created October 19, 2018 18:07
ES2018 Examples
// Spread to remove field
const user = {
firstName: 'John',
lastName: 'Doe',
city: 'Here'
}
const { city, ...userWIthoutCity} = user
city // here
userWIthoutCity // {firstName: 'John', lastName: 'Doe'}
@MorenoMdz
MorenoMdz / validateEmails.js
Created September 20, 2018 02:35
Email validation util.
// It splits by comma then map and trim each emai, then check each email pass the test, keeping the ones that do not pass the test.
// If any email do not pass the regex test show it to the user, otherwise continue (return)
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
export default emails => {
const invalidEmails = emails
.split(',')
.map(email => email.trim())
.filter(email => re.test(email) === false);
@MorenoMdz
MorenoMdz / all
Created September 6, 2018 20:30
Git versioning
Start my project at 1.0.0 in package.json
Initial dev work
Push to develop branch
Push to master branch
Tag as v1.0.0
Dev
Push to 'feature/name-of-feature' or 'bug/name-of-bug' branches
Merge pull request of feature and bug branches into develop
When it's ready for release, determine the version number (1.0.1 or 1.1.0) and update package.json
Push package.json to develop branch
@MorenoMdz
MorenoMdz / aws.js
Created September 6, 2018 02:41
Image upload, resize and rename with AWS S3 with node and Multer S3
const multer = require('multer');
const multerS3 = require('multer-s3');
const uuid = require('uuid');
const AWS = require('aws-sdk');
const sharp = require('sharp');
AWS.config.update({
accessKeyId: process.env.AWS_ACCESS,
secretAccessKey: process.env.AWS_SECRET_KEY
});
@MorenoMdz
MorenoMdz / gist:f8f30ef941680e94647b99e86e764925
Created August 5, 2018 18:13
HackerRank day 1 Data Types
// Declare second integer, double, and String variables.
let secondInteger, secondDouble, secondString
// Read and save an integer, double, and String to your variables.
/* Using readline and parsing the input into the variables declared previously */
secondInteger = parseInt(readLine());
secondDouble = parseFloat(readLine());
secondString = readLine();
@MorenoMdz
MorenoMdz / max 25char javascript
Created July 22, 2018 02:19
ES6 Limit to 25 char display.
p= store.description.split(' ').slice(0, 25).join(' ')
@MorenoMdz
MorenoMdz / bematech.js
Created July 4, 2018 15:44
Bematech termal printer USB driver for NodeJS with serialport module
const serialport = require('serialport');
/* serialport.list(function(err, result) {
console.log('error: ', err);
console.log('result: ', result);
});
*/
const port = new serialport('COM9');
@MorenoMdz
MorenoMdz / zombie.js
Created June 28, 2018 22:43
Quick zombie text adventure js game
/**
* 1. Zombie Game
* -------------
* A. Write Scenarios
* B. Store a list of possible scenarios
* C. Alert a random scenario from the list
*
* A. Create a list of weapons
* B. Save a list of weapons
* C. Alert which weapon the player finds