Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Saul Meneses fob2257

🏠
Working from home
View GitHub Profile
@fob2257
fob2257 / clip-image.js
Last active Dec 11, 2020
Made this with the intention of resizing & saving img url's
View clip-image.js
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);
View sequelize-index.js
'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(
View memoization.js
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 });
View getTime.js
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}`;
View post-receive
#!/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
@fob2257
fob2257 / jwt-pass.js
Created Nov 9, 2018
Auth con JWT en Express
View jwt-pass.js
// 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');
@fob2257
fob2257 / functional.js
Created Oct 3, 2018
Functional JS examples
View functional.js
/**
* 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
View examen-gaytis.js
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();