Skip to content

Instantly share code, notes, and snippets.

View vluzrmos's full-sized avatar
🏠
Working from home

Vagner Luz do Carmo vluzrmos

🏠
Working from home
View GitHub Profile
@vluzrmos
vluzrmos / multipart.php
Created April 30, 2020 19:54
PHP Multipart array to Guzzle Client or other ...
<?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 August 2, 2019 14:08
Docker-compose replace command
# ...
services:
# ...
service-name:
# ...
command: >
bash -c "
php artisan cache:clear &&
php artisan config:clear &&
@vluzrmos
vluzrmos / remote-ssh-write.sh
Created May 8, 2019 12:16
Write into a SSH Remote File
#!/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 September 26, 2018 17:28
PHP URL Resolve HTTP Redirection Recursively
<?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 September 13, 2021 03:30
Configurar o Laragon CMDER dentro do PHPSTORM

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 September 23, 2021 09:00
Laravel 5.1 withCount(relation) method.
<?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 July 11, 2017 18:33
PHP-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 July 20, 2016 14:31
Laravel Paginate Collection or Array
<?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 18:05 — forked from langemike/streamed.php
Laravel response macro for streamed responses with seeking support (with bug fixes & usage example)
<?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 February 20, 2016 01:02
Configurar o SSL CERT para o CURL em todos os apps
# 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