Skip to content

Instantly share code, notes, and snippets.

View leandroruel's full-sized avatar

Leandro RR leandroruel

View GitHub Profile
@leandroruel
leandroruel / Select2Formatter.php
Last active May 11, 2020 00:18
trait that uses eloquent to convert any array to select2 plugin data source: https://select2.org/data-sources/formats
<?php
namespace App\Traits;
trait Select2Formatter
{
/**
* Format your array to the format used by select2 plugin using eloquent
*
* @param array $data
@leandroruel
leandroruel / cyberpunkbuttons.html
Created February 27, 2020 17:20
Cyberpunk 2077 Buttons CSS
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Cyberpunk 2077 Buttons CSS</title>
</head>
<body>
<button class="btn">
<span class="btn__content">Get your copy now_</span>
<span class="btn__glitch"></span>
@leandroruel
leandroruel / upload.js
Created September 24, 2019 19:26
A js file to use Uppy file uploads with laravel-mix
const Uppy = require('@uppy/core');
const XHRUpload = require('@uppy/xhr-upload');
const Dashboard = require('@uppy/dashboard');
const PortuguesBR = require('@uppy/locales/lib/pt_BR');
/**
* Cria uma instância do plugin Uppy
* @param {String|Object} options objeto com algumas opções do plugin
*/
window.uploadFiles = (options) => {
@leandroruel
leandroruel / card.blade.php
Last active August 19, 2019 18:19
creating a bootstrap 4 accordion component using laravel @component and @slot directive
<?php
<div class="card">
<div class="card-header"
@isset($cardHeadingId)
id="{{ $cardHeadingId }}"
@endisset
>
<h2 class="mb-0">
<button
@leandroruel
leandroruel / CloneController.php
Last active July 20, 2019 20:39
creates a clone of a model and his relationships
<?php namespace App\Http\Controllers;
use App\MyModel;
class CloneController extends Controller
{
/**
* Replicate a model and his relationships
*
* @param $id
@leandroruel
leandroruel / createDinamicallyElement.js
Last active June 4, 2018 15:07
function to create dinamically a element, first parameter, the tag name and the second a object of attributes { key: value }
// check if the attribute key is camelcase
const isCamelCase = (str) => {
return /[A-Z]/.test(str)
}
//change the attribute from camelcase to hyphen separator
const changeSeparator = (str) => {
return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
}
@leandroruel
leandroruel / http-error.js
Created May 21, 2018 17:08 — forked from TooTallNate/http-error.js
HTTPError class for JavaScript HTTP errors
import { format } from 'url';
import { STATUS_CODES } from 'http';
import uppercamelcase from 'uppercamelcase';
class HTTPError extends Error {
constructor(code, message, extras) {
super(message || STATUS_CODES[code]);
if (arguments.length >= 3 && extras) {
Object.assign(this, extras);
}
@leandroruel
leandroruel / .env
Created January 17, 2018 16:32
this gist constains the database.php and .env file example of multiple connections
DB_CONNECTION=mysql
DB_HOST=http://localhost
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION2=mysql
DB_HOST2=http://localhost
DB_PORT2=3306
@leandroruel
leandroruel / Handler.php
Last active January 12, 2018 19:28
App\Exceptions\Handler.php
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
@leandroruel
leandroruel / gist:848370c0e133de40b9923b332b481bc3
Created June 22, 2016 16:52 — forked from tarciozemel/gist:1884583
JavaScript: incluir arquivos js/css dinamicamente
/*
* Ex:
* include("http://mysite.com/bookmarklet.css");
* include("http://mysite.com/bookmarklet.js");
*/
let include = ( src, callback ) => {
let ext = src.split( /[\#\?]/ )[ 0 ].split( '.' ).pop().toLowerCase();
let inc;
if ( ext === 'css' ) {