Skip to content

Instantly share code, notes, and snippets.

View fob2257's full-sized avatar
🏠
Working from home

Saul Meneses fob2257

🏠
Working from home
View GitHub Profile
const reversea = (cadena) => {
cadena = (cadena) ? cadena : '';
return (cadena).split('').reverse().join('');
};
const countCaracteres = (cadena) => {
cadena = (cadena) ? cadena : '';
let total = 0;
let char = '';
const arr = cadena.split('').sort();
@fob2257
fob2257 / functional.js
Created October 3, 2018 00:48
Functional JS examples
/**
* High order function
*/
{ // using currying
const createScream = fn => message => fn(message.toUpperCase() + '!!!');
const scream = createScream(message => console.log(message));
scream('functions can be returned from other functions');
}
{ // using currying
@fob2257
fob2257 / jwt-pass.js
Created November 9, 2018 19:43
Auth con JWT en Express
// npm i -S dotenv uuid express cors bcryptjs jsonwebtoken body-parser
require('dotenv').config();
const fs = require('fs');
const http = require('http');
const cors = require('cors');
const uuidv4 = require('uuid/v4');
const express = require('express');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const bodyParser = require('body-parser');
#!/bin/bash
target_branch="master"
working_tree="/home/deploy/icdt-production"
git_tree="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then
const getTotalTime = seconds => {
let hh = Math.floor(parseInt(seconds) / 3600);
let mm = Math.floor((seconds - (hh * 3600)) / 60);
let ss = seconds - (hh * 3600) - (mm * 60);
if (hh < 10) { hh = `0${hh}`; }
if (mm < 10) { mm = `0${mm}`; }
if (ss < 10) { ss = `0${ss}`; }
return `${hh}:${mm}:${ss}`;
const memo = fn => {
const cache = {};
return function () {
// arguments belongs to our returned anonymous function
// fn is the function we wish to apply this arguments
const key = JSON.stringify(arguments);
if (!!!cache[key]) cache[key] = fn.apply(null, arguments);
console.log({ cache });
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
let sequelize = new Sequelize(
@fob2257
fob2257 / clip-image.js
Last active November 23, 2022 23:45
Made this with the intention of resizing & saving img url's
const path = require('path');
const fs = require('fs');
const Jimp = require('jimp');
const { v4: uuidv4 } = require('uuid');
const imagesDirPath = path.join(__dirname, './images/');
const writeFile = (dirPath, fileName, data, options) => {
if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath);
const joinedPath = path.join(dirPath, fileName);