Skip to content

Instantly share code, notes, and snippets.

View pedrovasconcellos's full-sized avatar

Pedro Vasconcellos pedrovasconcellos

View GitHub Profile
@pedrovasconcellos
pedrovasconcellos / Email-Trigger-PhpScript.php
Created September 27, 2018 22:35
Email Trigger In Php
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set('default_charset','UTF-8');
function acentuacao_assunto($string){ return '=?UTF-8?B?'.base64_encode($string).'?='; }
//https://vasconcellossolutions.com
//https://vasconcellos.site
$emailrecipient = "contact@corporation.com";
$senderemail = $_POST['email'];
$sender = $emailrecipient;
$name = $_POST['name'];
@pedrovasconcellos
pedrovasconcellos / MySQL_Wordpress_Migration_Script.sql
Created September 30, 2018 06:00
MySQL Wordpress Migration Script
UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://EnderecoAntigo.com', 'http://EnderecoNovo.com')
WHERE option_name = 'home'
OR option_name = 'siteurl';
UPDATE wp_posts
SET guid = REPLACE (guid, 'http://EnderecoAntigo.com', 'http://EnderecoNovo.com');
UPDATE wp_posts
SET post_content = REPLACE (post_content, 'http://EnderecoAntigo.com', 'http://EnderecoNovo.com');
@pedrovasconcellos
pedrovasconcellos / VerificarPlacaMercoSul.cs
Created October 5, 2018 21:01
Verifica se a Placa do Veículo é aderente as características da Placa do Merco Sul
static class VerificarPlacaMercoSul
{
public int VerificarPlacaMercoSul(string placa){
if(placa?.Count() != 7) return -1;
//Verifica se o último caractere é um número;
if(!Regex.IsMatch(placa[placa.Count()-1].ToString(), @"^(|[0-9])+$")) return -2;
//Verifica se a placa contempla apenas letras e números;
if(!Regex.IsMatch(placa, @"^([a-zA-Z]|[0-9])+$")) return -3;
return 1;
}
@pedrovasconcellos
pedrovasconcellos / ExemploTaskContinueWith.cs
Created October 9, 2018 20:36
Exemplo de continuação de Task
void Main()
{
Task<DayOfWeek> tarefa = new Task<DayOfWeek>(delegate() { return DateTime.Today.DayOfWeek; });
// A continuacao. Seu delegate toma a tarefa antecedente
// como um argumento e pode retornar um tipo diferente
Task<string> continuacao = tarefa.ContinueWith((antecedent) =>
{
return String.Format("Hoje é {0}.",antecedent.Result);
});
@pedrovasconcellos
pedrovasconcellos / EnumExtension.cs
Last active December 3, 2018 11:53
EnumToDictonary [int, string]
//Programmed in LINQPad 5
void Main()
{
var result = EnumExtension.EnumToDictonary<CivilStatusEnum>();
Console.WriteLine(result);
}
public static class EnumExtension
{
public static Dictionary<int, string> EnumToDictionary<T>() where T : struct
@pedrovasconcellos
pedrovasconcellos / ErrorDictionary.cs
Last active November 30, 2018 19:53
DictionaryError Equals FluentValidation.AspNetCore
/// <summary>
/// DictionaryError
/// </summary>
/// <remarks>
/// Classe responsável por gerar o dicionário de erro da regra de negócio igual ao dicionário de erro do FluentValidation.AspNetCore.
/// </remarks>
internal static class ErrorDictionary
{
internal static Dictionary<string, string[]> GenerateError(string parameter, string message, Dictionary<string, string[]> dictionaryErrors = null)
{
@pedrovasconcellos
pedrovasconcellos / ErrorDetails.cs
Last active October 31, 2018 22:00
Error details
//using System.Collections.Generic;
public class ErrorDetails
{
public ErrorDetails(Dictionary<string, string[]> errorsDictionary, string instance)
{
this.Errors = errorsDictionary;
this.Type = "Business Rules";
this.Title = "One or more validation errors occurred.";
this.Status = 422;
this.Detail = "Please refer to the errors property for additional details.";
@pedrovasconcellos
pedrovasconcellos / DelegateExamples.cs
Last active November 8, 2018 20:58
Delegate examples
void Main()
{
Process();
}
delegate double MathAction(double num);
private static void Process()
{
//--DELEGATE - COMMON--INITIAL
@pedrovasconcellos
pedrovasconcellos / Result.cs
Created November 30, 2018 20:02
Result<T>
using System.Collections.Generic;
using System.Linq;
public class Result<T>
{
public Result()
{
this.Errors = new Dictionary<string, string[]>();
}
@pedrovasconcellos
pedrovasconcellos / ExampleDocumentedEndPoint.cs
Created December 3, 2018 06:56
Example of a documented endpoint
/// <summary>
/// Realiza a consulta por id do carro
/// </summary>
/// <param name="id"></param>
/// <response code="200">Ok</response>
/// <response code="400">Bad Request</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
[HttpGet("{id}")]
[ProducesResponseType(typeof(IList<CarModel>),200)]