Skip to content

Instantly share code, notes, and snippets.

Avatar

Leandro RR leandroruel

View GitHub Profile
@leandroruel
leandroruel / Select2Formatter.php
Last active May 11, 2020
trait that uses eloquent to convert any array to select2 plugin data source: https://select2.org/data-sources/formats
View Select2Formatter.php
<?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 Feb 27, 2020
Cyberpunk 2077 Buttons CSS
View cyberpunkbuttons.html
<!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 Sep 24, 2019
A js file to use Uppy file uploads with laravel-mix
View upload.js
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 Aug 19, 2019
creating a bootstrap 4 accordion component using laravel @component and @slot directive
View card.blade.php
<?php
<div class="card">
<div class="card-header"
@isset($cardHeadingId)
id="{{ $cardHeadingId }}"
@endisset
>
<h2 class="mb-0">
<button
@leandroruel
leandroruel / CloneController.php
Last active Jul 20, 2019
creates a clone of a model and his relationships
View CloneController.php
<?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 Jun 4, 2018
function to create dinamically a element, first parameter, the tag name and the second a object of attributes { key: value }
View createDinamicallyElement.js
// 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 — forked from TooTallNate/http-error.js
HTTPError class for JavaScript HTTP errors
View http-error.js
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 Jan 17, 2018
this gist constains the database.php and .env file example of multiple connections
View .env
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 Jan 12, 2018
App\Exceptions\Handler.php
View Handler.php
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
@leandroruel
leandroruel / gist:848370c0e133de40b9923b332b481bc3
Created Jun 22, 2016 — forked from tarciozemel/gist:1884583
JavaScript: incluir arquivos js/css dinamicamente
View gist:848370c0e133de40b9923b332b481bc3
/*
* 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' ) {