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
@TiagoSilvaPereira
TiagoSilvaPereira / BukCalendarComponent.vue
Created October 26, 2017 21:27
Problema, quando adiciono qualquer File Picker dentro do BukCalendar ou de algum componente dentro dele, o FullCalendar não funciona corretamente
<template>
<div>
<buk-event-modal @save-event="sendEvent" v-if="buildModal"></buk-event-modal>
<full-calendar ref="calendar" :config="config" :events="events" :editable="false"></full-calendar>
</div>
</template>
<script>
import BukEventModal from './BukEventModalComponent.vue';
@TiagoSilvaPereira
TiagoSilvaPereira / GoogleApiWrapper.php
Last active November 29, 2017 21:15
Get an access_token with the Google API Client to authenticate your PHP Backend with google services, like Firebase, Cloud Storage, etc
public function getServiceAccountAccessToken() {
// put the serviceAccount credentials in the env variable
putenv('GOOGLE_APPLICATION_CREDENTIALS=../resources/json/serviceAccount.json');
// Add the scopes (here are the scopes to Firebase Auth)
$scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database"
];
@TiagoSilvaPereira
TiagoSilvaPereira / removeDir.php
Created February 16, 2018 02:04
PHP - Removing a folder and all sub folders and files (including hidden files) - this method is better than using glob
<?php
function removeDirectory($dirPath) {
if (! is_dir($dirPath)) {
return false;
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
@TiagoSilvaPereira
TiagoSilvaPereira / Cendi.php
Created February 27, 2018 18:13
Cendi Example
<?php
use Cendi\App;
$app = new App();
$app->setTitle('Cadastro de Pessoas');
$app->addInput('nome');
$app->addInput('tipo', 'select', ['fisica' => 'Pessoa Física', 'juridica' => 'Pessoa Jurídica']);
$app->addInput('descricao', 'text');
@TiagoSilvaPereira
TiagoSilvaPereira / Template.php
Created February 27, 2018 19:31
PWC Template Engine Example
<?php
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class RolesAndPermissionsSeeder extends Seeder
{
public function run()
{
@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() {
@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 / 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 / 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 / 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']);