Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Renan Coelho sayhicoelho

🏠
Working from home
View GitHub Profile
@sayhicoelho
sayhicoelho / DelayedJob.php
Created Dec 30, 2020
Laravel: Run only latest delayed job
View DelayedJob.php
<?php
namespace App\Support;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Facades\Redis;
class DelayedJob
{
/**
View Validator.js
class Validator {
constructor(data, rules) {
this.data = data
this.rules = rules
this.errors = {}
}
get validations() {
return {
required(field) {
@sayhicoelho
sayhicoelho / AccordionGroup.svelte
Created Aug 1, 2020
Svelte accordion based on Bootstrap Collapse.
View AccordionGroup.svelte
<script>
import { setContext } from 'svelte';
export let multiple = false
export let header = true
const items = new Set()
setContext('accordion', {
getMultiple: () => multiple,
@sayhicoelho
sayhicoelho / AccordionGroup.vue
Last active Nov 2, 2020
Vue.js Accordion base on Bootstrap Collapse.
View AccordionGroup.vue
<template>
<div class="accordion-group">
<slot />
</div>
</template>
<script>
export default {
name: 'AccordionGroup',
props: {
@sayhicoelho
sayhicoelho / pure-js-bootstrap-accordion.html
Last active Aug 1, 2020
Pure JS accordion based on Bootstrap Collapse.
View pure-js-bootstrap-accordion.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
@sayhicoelho
sayhicoelho / bankRoutes.js
Created Jul 2, 2020
ACL with Nodejs and MongoDB.
View bankRoutes.js
const { Router } = require('express')
const ensureAuth = require('../middleware/ensureAuth')
const ensureHasPermissions = require('../middleware/ensureHasPermissions')
const bankController = require('../controllers/bankController')
const router = Router()
router.use('/', ensureAuth)
router.get('/', ensureHasPermissions('banks.read'), bankController.getAll)
router.get('/:id', ensureHasPermissions('banks.read'), bankController.getOne)
@sayhicoelho
sayhicoelho / getCssSelector.js
Created May 20, 2020
Get element CSS selector using JS
View getCssSelector.js
// ref: https://stackoverflow.com/a/57503796/4158755
// Thanks to Yassine!
function getCssSelector(el) {
const names = []
do {
let index = 0
let cursorElement = el
@sayhicoelho
sayhicoelho / event_emitter.dart
Last active May 9, 2020
Custom EventEmitter for Dart
View event_emitter.dart
class Listener {
final String eventName;
final void Function([Object]) callback;
Listener(this.eventName, this.callback);
}
class EventEmitter {
final _listeners = <Listener>[];
@sayhicoelho
sayhicoelho / EventEmitter.js
Last active May 9, 2020
Custom EventEmitter for Javascript
View EventEmitter.js
class EventEmitter {
constructor() {
this.listeners = []
}
addListener(event, listener) {
this.listeners.push({ event, listener })
}
removeListener(event, listener) {
@sayhicoelho
sayhicoelho / ensureFileIsPresent.js
Created May 6, 2020
Node.js & Multer check if file is present in the request.
View ensureFileIsPresent.js
module.exports = (req, res, next) => {
if (!req.file) {
res.status(422).json({ message: 'The file is required.' });
} else {
next();
}
}