Skip to content

Instantly share code, notes, and snippets.

View brunocmoraes's full-sized avatar

Bruno C. Moraes brunocmoraes

View GitHub Profile
@brunocmoraes
brunocmoraes / .htaccess
Created February 10, 2020 19:20
Generic redirect from http to htaccess (without set domain)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
@brunocmoraes
brunocmoraes / send-phpmailer.php
Created April 6, 2020 19:25
Envio de e-mail na caixa de entrada com Php Mailer
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->setLanguage('pt_br');
$mail->SMTPDebug = 0;
$mail->isSMTP();
@brunocmoraes
brunocmoraes / formatar-telefone-php.php
Created April 19, 2020 04:41
Função PHP para formatar números de telefone
function telefone($n)
{
$tam = strlen(preg_replace("/[^0-9]/", "", $n));
if ($tam == 13) {
// COM CÓDIGO DE ÁREA NACIONAL E DO PAIS e 9 dígitos
return "+".substr($n, 0, $tam-11)." (".substr($n, $tam-11, 2).") ".substr($n, $tam-9, 5)."-".substr($n, -4);
}
if ($tam == 12) {
// COM CÓDIGO DE ÁREA NACIONAL E DO PAIS
@brunocmoraes
brunocmoraes / Category.php
Created August 9, 2020 20:14
Eloquent: Recursive hasMany Relationship with Unlimited Subcategories
<?php
class Category extends Model
{
public function categories()
{
return $this->hasMany(Category::class);
}
public function childrenCategories()
@brunocmoraes
brunocmoraes / Post.php
Created August 11, 2020 14:50
Append a slug number if aleardy exists on db
public function setTitleAttribute($value)
{
$slug = \Str::slug($value);
$count = static::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
$this->attributes['title'] = $value;
$this->attributes['slug'] = $count ? "{$slug}-{$count}" : $slug;
}
@brunocmoraes
brunocmoraes / .env
Created August 12, 2020 23:50
Single admin role to small projects
ADMIN_EMAILS=user1@example.com,user2@example.com
@brunocmoraes
brunocmoraes / app.js
Created August 20, 2020 03:01
vue form laravel
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
@brunocmoraes
brunocmoraes / replace.sql
Created September 6, 2020 19:56
replace url's in database
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
-> Vantagens de uso da nuvem:
- Trocar investimento em ativos por custos operacionais.
Custos tende a ser mais aderentes aos negócios.
- Benefício de escala massivo.
Quanto maior a estrutura, maior uso de uma estrutura robusta, mais barato deve se tornar o módulo.
- Parar de estimar/chutar a capacidade do data center.
Na nuvem, pela elasticidade, poderá escalar conforme a necessidade.
@brunocmoraes
brunocmoraes / ForkSyncOriginal.md
Created February 5, 2021 01:02
Mantendo um fork sincronizado com atualizações do original