Skip to content

Instantly share code, notes, and snippets.

View marcosfreitas's full-sized avatar
🔥
Looking forward

Marcos Freitas marcosfreitas

🔥
Looking forward
View GitHub Profile
const useAuth = (): AuthContextInterface => {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within a AuthProvider');
}
return context;
};
@marcosfreitas
marcosfreitas / array_to_object.php
Last active May 20, 2022 04:25
Convert a multidimensional array to object recursively
<?php
/**
* Convert a multidimensional array to an object recursively.
* For any arrays inside another array, the result will be an array of objects.
*
* @author Marcos Freitas
* @param array|any $props
* @return array|any
*/
@marcosfreitas
marcosfreitas / m3.sh
Last active March 30, 2019 19:27
press key to continue
function PressKeyToContinue() {
printf "\n";
question="Pressione S para continuar ou qualquer outra tecla para pular essa parte execução do script";
expected_key_pressed='s';
abort_script=false;
if [ ! -z "$1" ]; then
question="${1}";
@marcosfreitas
marcosfreitas / isAlmostPalindrome.php
Created July 9, 2018 19:03
#training Is A Palíndrome word
<?php
# check for palindrome words
# if the word have almost 1 letter to be changed to be a plindrome, it will be a palíndrome.
function isAlmostPalindrome($word) {
$count_diference = 0;
$word_reverse = strrev($word);
$word_as_array = str_split($word);
<?php
namespace App\Controllers\Site\Ads;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Silex\Api\ControllerProviderInterface;
class AdsControllerProvider implements ControllerProviderInterface {
@marcosfreitas
marcosfreitas / wp-title.php
Created July 10, 2017 22:22
combinação de títulos para o title do html
<title>
<?php
if(is_home()):
bloginfo('name');
elseif( is_category() || is_tag() ):
single_cat_title(); echo ' &bull; '; bloginfo('name');
elseif( is_single() || is_page() ):
single_post_title();
else:
@marcosfreitas
marcosfreitas / get_date.php
Last active June 2, 2017 18:49
Abstraction to get date e anyone formats
<?php
/**
* Check if a string is a valid based on $formats['input'], then format an output based on $formats['output']
* @author Marcos Freitas
* @param string $value The string of the date
* @param array $formats The given input and wanted output formats of the date.
* @return string|boolean
*/
public static function getDate($value, $formats){
@marcosfreitas
marcosfreitas / mf-pagination.php
Created January 12, 2017 00:40
Create a custom pagination based on total of pages received
<style>
.mf-pagination {
display: block;
list-style: none;
margin: 2em 0 0 0;
width: 100%;
padding: 1em;
text-align: right;
font-size: 1.2em;
}
@marcosfreitas
marcosfreitas / .htaccess
Created October 29, 2016 22:04
rewrite folder "web/" inside silex
# Project'a Structure
# localhost/projects/myProject/
# -- .htacess
# | -- RewriteEngine On
# | -- RewriteBase /projects/myProject/
# | -- DirectoryIndex web/index.php
# -- src/
# ----- App/
# -- web/
<?php
namespace App;
/**
* Esta classe é apenas um Wrapper para a classe SoapClient e realiza as requisições e recebe as respostas de forma padrão.
*/
class Soap {
public
$__client,