Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Vagner Luz do Carmo vluzrmos

🏠
Working from home
View GitHub Profile
@vluzrmos
vluzrmos / multipart.php
Created Apr 30, 2020
PHP Multipart array to Guzzle Client or other ...
View multipart.php
<?php
/**
* Turns associative arrays into multipart [['name' => 'key[0][deep]', 'contents' => 'value']]
*/
function array_multipart(array $data = [])
{
$dots = array_dot($data);
$multipart = [];
@vluzrmos
vluzrmos / docker-compose.yml
Created Aug 2, 2019
Docker-compose replace command
View docker-compose.yml
# ...
services:
# ...
service-name:
# ...
command: >
bash -c "
php artisan cache:clear &&
php artisan config:clear &&
@vluzrmos
vluzrmos / remote-ssh-write.sh
Created May 8, 2019
Write into a SSH Remote File
View remote-ssh-write.sh
#!/bin/bash
echo 'Some Text' | ssh user@remotehost -T "cat > /remotefile.txt"
# The -T disables pseudo-terminal allocation and stops you from getting the message,
# Pseudo-terminal will not be allocated because stdin is not a terminal.
# @see https://superuser.com/a/400720/341320
@vluzrmos
vluzrmos / guzzle_v6_resolve_http_redirection.php
Last active Sep 26, 2018
PHP URL Resolve HTTP Redirection Recursively
View guzzle_v6_resolve_http_redirection.php
<?php
/*
* Resolver using Guzzle
*/
if (!function_exists('resolve_http_redirection')) {
/**
* @param string $url
* @param int $limit
* @return mixed
@vluzrmos
vluzrmos / phpstorm.cmder.md
Last active Sep 13, 2021
Configurar o Laragon CMDER dentro do PHPSTORM
View phpstorm.cmder.md

1- Adicionar a variável de ambiente CMDER_ROOT com o caminho para C:\laragon\bin\cmder (local do cmder no computador)

2- Abrir o phpstorm, ir em File (Menu) > Settings > Tools > Terminal e alterar o caminho padrão "cmd.exe" para:

"cmd.exe" /k ""%CMDER_ROOT%\vendor\init.bat""

3- Pode acontecer de a variável CMDER_ROOT não estar pronta, você pode precisar reiniciar sua máquina.

@vluzrmos
vluzrmos / HasWithCountScope.php
Last active Sep 23, 2021
Laravel 5.1 withCount(relation) method.
View HasWithCountScope.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression;
@vluzrmos
vluzrmos / unnacent.php
Created Jul 11, 2017
PHP-Unnacent.php
View unnacent.php
<?php
function to_ascii($str, $removeUnsupported = true)
{
foreach (ascii_chars() as $key => $value) {
$str = str_replace($value, $key, $str);
}
if ($removeUnsupported) {
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
@vluzrmos
vluzrmos / paginate.php
Created Jul 20, 2016
Laravel Paginate Collection or Array
View paginate.php
<?php
/**
* Gera a paginação dos itens de um array ou collection.
*
* @param array|Collection $items
* @param int $perPage
* @param int $page
* @param array $options
*
* @return LengthAwarePaginator
@vluzrmos
vluzrmos / Laravel_Response_Streamed.php
Created May 11, 2016 — forked from langemike/streamed.php
Laravel response macro for streamed responses with seeking support (with bug fixes & usage example)
View Laravel_Response_Streamed.php
<?php
Response::macro('streamed', function($type, $size, $name, $callback) {
$start = 0;
$length = $size;
$status = 200;
$headers = [
'Content-Type' => $type,
'Content-Length' => $size,
@vluzrmos
vluzrmos / add.sh
Created Feb 20, 2016
Configurar o SSL CERT para o CURL em todos os apps
View add.sh
# Adicione a seguinte variável ao seu sistema:
SSL_CERT_FILE=/path/to/curl-ca-bundle.crt
# Você pode pegar uma cópia desse certificado no diretório bin do GIT