Skip to content

Instantly share code, notes, and snippets.

View buddyeorl's full-sized avatar

Alex Lizarraga buddyeorl

View GitHub Profile
@buddyeorl
buddyeorl / typing.js
Created October 6, 2020 06:52
Typing Effect
import React, { useState, useEffect } from 'react'
const Typing = ({ label, showCursor = true, error = false, cb = () => { return true } }) => {
const [text, setText] = useState([''])
const [cursor, setCursor] = useState([''])
useEffect(() => {
let tempText = ['']
let timer1;
//set new text every 100ms
@buddyeorl
buddyeorl / machineRoutes.js
Created October 7, 2020 06:56
Why I choose Express and Express router
// declare machine router files
const machines = require('./api/machines');
//Machine Routes
app.use('/machines', machines.add);
app.use('/machines', machines.update);
app.use('/machines', machines.remove);
app.use('/machines', machines.get);
app.use('/machines', machines.sort);
const add = require('./add');
const update = require('./update');
const remove = require('./remove');
const get = require('./get');
const sort = require('./sort');
module.exports = { add, update, remove, get, sort };
@buddyeorl
buddyeorl / sort.js
Last active October 7, 2020 08:03
Middlewares are awesome
const router = require('express').Router();
//middlewares
const auth = require('../pathToAuth'); // <- not the actual code, placed for presentation purposes
const validate = require('../middleware/validation').validateQuery;
const sort = require('../middleware/dbActions').sort;
//returns all equipments sorted as requested
//endpoint: /machines/sort
router.get('/sort',auth, validate, sort , (req, res) => {
@buddyeorl
buddyeorl / documentWithExpiration.js
Last active October 7, 2020 18:24
Adding expiration to mongodb collection using mongo 4.0
const collection = db.collection('shortTerm');
// Create a new document with an expiration date, create an Index for expireAt field and specify the expireAfterSeconds value of 60:
const addShortTerm = (data, cb = ()=>{return}) => {
newData = {
type: data.type,
category: data.category,
make: data.make,
model: data.model,
rent: data.rent,
@buddyeorl
buddyeorl / fileToUrl.js
Created October 8, 2020 06:13
Convert images into readble URL
//=============convert file to readable URL: good for image previews before uploads=====
const fileToUrl = (files, result = [], index = 0) => {
let reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onerror = () => {
reader.abort();
reject(new DOMException("Problem parsing input file."));
};
reader.onload = () => {
@buddyeorl
buddyeorl / Gallery.js
Last active October 8, 2020 06:20
Touchable gallery
@buddyeorl
buddyeorl / Buff.js
Last active October 8, 2020 06:21
Buff a button
import React from 'react';
import Buff from './pathToBuff';
//add some styles to the components
const Example =()=>{
styles{
div:{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
@buddyeorl
buddyeorl / uploadImg.js
Last active October 8, 2020 06:22
Using Multer and MulterS3 to upload files to AWS S3 buckets
//upload image files to aws s3 bucket with multerS3, and use SHA256 for naming purposes.
const upload = multer({
storage: multerS3({
s3: s3,
bucket: bucket,
acl: 'public-read',
key: function (req, file, cb) {
cb(null, SHA256(Date.now() + path.basename(file.originalname, path.extname(file.originalname))) + '1');
@buddyeorl
buddyeorl / RangeSlider.js
Last active October 8, 2020 18:56
Add buffs to your buttons, spans, divs etc.
import React from 'react';
import RangeSlider from './pathToRangeSlider';
//There is a prop 'cb' which can be used to retrieve the data from the range slider, by default the cb is the following:
//cb={(startValue, endValue) => { console.log('Start=', startValue, ' End=', endValue); }}
// Check the console to see the cb in action.
// options:
// range: [startValue, endValue]
// label: string on the left
// colorButtonLeft: string