Skip to content

Instantly share code, notes, and snippets.

View dorianneto's full-sized avatar
💪
Doing something great!

Dorian Neto dorianneto

💪
Doing something great!
View GitHub Profile
@dorianneto
dorianneto / example2.php
Created January 30, 2018 12:53
Post: Refatorando código com Extract Method
<?php
$products = [
'Geladeira' => 1500.99,
'Fogão' => 350,
'Celular' => 1190.90
];
function format_currency($value): string {
return 'R$ ' . number_format($value, 2, ',', '.');
@dorianneto
dorianneto / example1.php
Last active January 30, 2018 12:48
Post: Refatorando código com Extract Method
<?php
$products = [
'Geladeira' => 1500.99,
'Fogão' => 350,
'Celular' => 1190.90
];
function before_add_shopping_cart(array $products): array {
$output = [
@dorianneto
dorianneto / example2.php
Last active January 19, 2018 20:49
Post: Torne-se um ninja das funções com Early Return
<?php
public static function formatDate($date)
{
$format = DateTime::ATOM;
if ($date instanceof DateTime) {
return $date->format($format);
}
@dorianneto
dorianneto / example1.php
Last active January 19, 2018 20:49
Post: Torne-se um ninja das funções com Early Return
<?php
public static function formatDate($date)
{
$format = DateTime::ATOM;
if ($date instanceof DateTime) {
$d = $date->format($format);
} elseif (is_numeric($date)) {
$d = date($format, $date);
} else {
<?php
function abbreviate_name(string $name): string
{
if (strlen($name) <= 13) {
return $name;
}
// Removendo preposições do nome
$name_arr = explode(' ', preg_replace('/\s(de|da)\s/', ' ', $name));
$count = count($name_arr) - 1;
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir($root);
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
set_include_path(get_include_path().':'.__DIR__);
if(file_exists($root.$path))
{
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
$path = rtrim($path,'/').'/index.php';
if(strpos($path,'.php') === false) return false;
[
{
"latitude":"-3.738846",
"longitude":"-38.514562",
"estado":"Ceará",
"cidade":"Fortaleza",
"bairro":"Centro",
"endereco":"R. Rocha Lima - Centro, Fortaleza - CE",
"iframe":"https:\/\/www.google.com\/maps\/embed?pb=!1m0!3m2!1spt-BR!2sbr!4v1482411868444!6m8!1m7!1sF%3A-MZ3kPTyTOlY%2FWFvLAGGpucI%2FAAAAAAADIMo%2FdqrkI48arNgxImUcc6Qi5dY7jdVYLqC4QCLIB!2m2!1d-4.0304584!2d-38.3036892!3f200.16869339582473!4f42.366552188365546!5f1.8581960817441479",
"pano":null,