Skip to content

Instantly share code, notes, and snippets.

View ccmelas's full-sized avatar
🎯
Focusing

Chinedum Chiemela ccmelas

🎯
Focusing
View GitHub Profile
@ccmelas
ccmelas / click-outside.js
Created October 18, 2019 14:54
Directive for Handling outside clicks for Vue Components
function findElement(element, vnode = null) {
if (vnode) {
return vnode.context.$refs[element];
}
return document.querySelector(`#${element}`);
}
function elementContainsEvent(event, element, vnode = null) {
const domElement = findElement(element, vnode);
return domElement && domElement.contains(event.target);
<?php
/**
* Paystack payment service.
*/
namespace App\Payments;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
@ccmelas
ccmelas / contactTest.js
Created March 9, 2019 06:54
Test for a certain "contact" feature 🤓
const chai = require('chai');
const chaiHttp = require('chai-http');
const app = require('../../index');
const { User, Contact } = require('../../database/models');
chai.use(chaiHttp);
const should = chai.should();
let userData, contactData, user, token, otherUserData, otherUser;
@ccmelas
ccmelas / ErroHandler.js
Created March 9, 2019 06:49
Generic error catching method for async functions. Allows you write async functions without the try/catch blocks. You instead wrap calls to those functions with the catchErrors method
/**
* Handles application errors
*/
class ErrorHandler {
/**
* Wrapper for catching async/await errors
* @param {function} fn
* @returns {function} [Composed function with error handler attached]
*/
static catchErrors(fn) {