Skip to content

Instantly share code, notes, and snippets.

View TiagoSilvaPereira's full-sized avatar
💻
Always coding...

Tiago S. P. Rodrigues TiagoSilvaPereira

💻
Always coding...
View GitHub Profile
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
@extends('layouts.app')
@section('content')
<table class="table">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
@foreach ($users as $user)
@TiagoSilvaPereira
TiagoSilvaPereira / app.js
Created October 24, 2019 20:55
BabylonJs Scene - PBR - Example
var app = {
init() {
this.createScene();
},
createScene() {
this.scene = new BABYLON.Scene(this.engine);
this.scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
@TiagoSilvaPereira
TiagoSilvaPereira / Select02.php
Created March 14, 2019 20:19
KISS aplicado ao código 02
<?php
// Código mais simples gerada pela restruturação, focada na simplicidade
$currentLabels = $this->getCurrentLabels();
$labels = Label::where('company_id', $company->id)
->whereNotIn('labels.id', $currentLabels);
@TiagoSilvaPereira
TiagoSilvaPereira / Select01.php
Last active March 14, 2019 20:18
KISS aplicado ao código
<?php
// Código complexo gerado pela falta de simplicidade na estrutura
$labels = DB::table('labelables')
->select(['labelables.*', 'labels.id as label_id', 'labels.slug', 'labels.title'])
->join('labels', 'labels.id', 'labelables.label_id')
->where('labels.title', 'like', '%'.$search.'%')
->where('labelables.labelable_type', $request->labelable_type)
->whereRaw('(SELECT count(id)
FROM labelables AS count_labelables
@TiagoSilvaPereira
TiagoSilvaPereira / Collection.php
Created February 21, 2019 19:04
Laravel Collection - Problema com filter() e chaves de arrays
<?php
$collection = collect(['um', 'dois', 'tres', 'quatro', 'cinco']);
@TiagoSilvaPereira
TiagoSilvaPereira / Monster.js
Last active January 12, 2019 19:11
Cube Endless Runner - 3D WebGL Game code examples (BabylonJS)
class Monster {
// ...
moveAwayFromPlayer() {
this.statuses.CLOSE_TO_PLAYER = false;
this.level.interpolate(this, 'distanceBeetweenPlayer', 1.5, 1500);
}
// ... more methods here
@TiagoSilvaPereira
TiagoSilvaPereira / Wrong.php
Created November 19, 2018 15:15
Laravel: get the correct model on morphTo relationships (Wrong way)
<?php
public function project()
{
return $this->belongsTo(Project::class, 'commentable_id', 'id');
}
public function task()
{
return $this->belongsTo(Task::class, 'commentable_id', 'id');
}
@TiagoSilvaPereira
TiagoSilvaPereira / Correct.php
Last active November 19, 2018 15:14
Laravel: get the correct model on morphTo relationships
<?php
public function getTaskAttribute()
{
if($this->commentable_type == 'App\Task') return $this->commentable;
return null;
}
public function getProjectAttribute()
{
@TiagoSilvaPereira
TiagoSilvaPereira / TextView.js
Last active April 7, 2018 23:58
Component "zuado" feito na mão
import View from '../base/View.js';
export default class TextView extends View {
init() {
this.setElement('text-editor');
this.setData({'mode': 'insert'});
}
initElements() {