Skip to content

Instantly share code, notes, and snippets.

View rodrigopedra's full-sized avatar

Rodrigo Pedra Brum rodrigopedra

  • São Carlos, Brazil
View GitHub Profile
@rodrigopedra
rodrigopedra / gist:a4a91948bd41617a9b1a
Last active June 1, 2024 15:42
Laravel 5 Middleware for Database Transactions
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class DBTransaction
{
/**
* Handle an incoming request.
*
@rodrigopedra
rodrigopedra / Article.php
Created March 25, 2015 14:58
Localize Carbon::diffForHumans in Laravel Models
<?php namespace App;
use App\Carbon\LocalizedDiffForHumansTrait;
use Illuminate\Database\Eloquent\Model;
// example model
class Article extends Model
{
use LocalizedDiffForHumansTrait;
<?php namespace App\Services;
use App\User;
class AclPermitted
{
public static function verify( $permission )
{
/** @var User $user */
$user = app( 'auth' )->user();
@rodrigopedra
rodrigopedra / dados.csv
Last active August 29, 2015 14:18
CSV -> banco
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Matemática;;;;;
Nome;RA;B1;B2;B3;B4
Gabriel Nasciemento;654321;10;10;10;10
Gabriel Nascimento;12345678999;;;;
Matheus Menezes;223344;7;8;6;5
Thiel Caique;123456;;;;
@rodrigopedra
rodrigopedra / marco.php
Last active August 29, 2015 14:18
retornando JSON
<?php
function resposta( $resultado, $erro = FALSE )
{
if ( $erro )
{
$resultado = array(
'erro' => $resultado
);
// envia cabeçalho de erro
@rodrigopedra
rodrigopedra / Role.php
Created April 1, 2015 15:17
Laravel: Manage many-to-many relationship - with view
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
protected $table = 'roles';
protected $fillable = [ 'name' ];
}
@rodrigopedra
rodrigopedra / counter.html
Last active August 29, 2015 14:18
jQuery Counter
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Counter</title>
</head>
<body>
<!-- declarative markup -->
<div class="my-counter">
<h1>Counter: <span class="counter-output"></span></h1>
@rodrigopedra
rodrigopedra / 2015_04_07_204252_create_articles_table.php
Last active October 24, 2019 21:41
Laravel - Edit Article only if user is the owner
<?php
// database/migrations/2015_04_07_204252_create_articles_table.php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration
{
public function up()
@rodrigopedra
rodrigopedra / AppServiceProvider.php
Last active February 11, 2016 06:02
Laravel Russian Doll Caching
<?php
namespace App\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
@rodrigopedra
rodrigopedra / luhn.js
Created October 25, 2016 07:38 — forked from ShirtlessKirk/luhn.js
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,