Skip to content

Instantly share code, notes, and snippets.

View vinyvicente's full-sized avatar
🎯
Focusing

Vinicius vinyvicente

🎯
Focusing
View GitHub Profile
@vinyvicente
vinyvicente / array_sort_column.php
Last active March 4, 2016 17:41
Array Sort Column
<?php
/**
* @param string $column
* @param array $pieces
* @param int $direction (SORT_ASC | SORT_DESC)
* @return mixed
* @throws Exception
*/
function array_sort_column($column, $pieces, $direction = SORT_ASC)
@vinyvicente
vinyvicente / setters_dynamic.php
Created November 2, 2016 12:31
Setters create objects dynamically
<?php
public function __call($name, $arguments)
{
echo '
/**
* @var string
*/
protected $' . lcfirst(mb_substr($name, 3, mb_strlen($name) - 3)) . ';' . PHP_EOL;
return $this;
<?php
namespace App\Listeners;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
@vinyvicente
vinyvicente / nginx-tuning.md
Created September 10, 2017 19:33 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@vinyvicente
vinyvicente / compile-nginx-from-source.sh
Created September 14, 2017 19:55 — forked from nurrony/compile-nginx-from-source.sh
All configuration files needed to install nginx on Ubuntu 16.04 Compile Nginx from source with nginx-rtmp-module, pagespeed and cache-purge module.
#change it to latest version
NPS_VERSION=1.11.33.0;
echo "Changing Directory to $HOME..."
cd $HOME;
echo "Nginx version to install: " && \
read NGINX_VERSION && \
echo "Downloading nginx-$NGINX_VERSION..." && \
wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \
echo "Installing Nginx Dependencies..." && \
@vinyvicente
vinyvicente / symfony3-rest-api.md
Last active March 19, 2018 08:13 — forked from diegonobre/symfony3-rest-api.md
Basic RESTful API with Symfony 3 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 3 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authenticationu
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 3 framework. The following SF2 bundles are used :

<?php
$json = json_decode('[
{
"id":1,
"descricao":"Tipo de Registro 01",
"status_op":"status de op 01",
"status_atividade":"status de atividade 01",
"exige_atividade":false,
"acao_op":"Nenhum",
@vinyvicente
vinyvicente / 1_Laravel_state-machine.md
Created February 6, 2018 18:23 — forked from iben12/1_Laravel_state-machine.md
Laravel: State-machine on Eloquent Model

Implementing State Machine On Eloquent Model*

* Update (12.09.2017): I have improved the trait so that it can be used with objects other than Eloquent Models.

Some days ago I came across a task where I needed to implement managable state for an Eloquent model. This is a common task, actually there is a mathematical model called "Finite-state Machine". The concept is that the state machine (SM) "can be in exactly one of the finite number of states at any given time". Also changing from one state to another (called transition) depends on fulfilling the conditions defined by its configuration.

Practically this means you define each state that the SM can be in and the possible transitions. To define a transition you set the states on which the transition can be applied (initial conditions) and the only state in which the SM should be after the transition.

That's the theory, let's get to the work.

@vinyvicente
vinyvicente / results.md
Last active May 15, 2019 17:05
Benchmark PHP 7.3.5 vs Node 12.1.0

PHP

Last login: Wed May 15 10:34:29 on ttys001
Vinicius-MacBook:~ vinyvicente$ wrk -t4 -c400 -d10s http://127.0.0.1:1337/
Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.78ms    1.55ms  23.47ms   82.95%
    Req/Sec     0.90k   458.32     1.57k    69.44%
@vinyvicente
vinyvicente / references_go.txt
Created January 26, 2021 18:04
Go path references
https://golang.org/
https://go.dev/
https://pkg.go.dev/
https://go-proverbs.github.io/
https://golang.org/doc/effective_go.html
https://blog.golang.org/errors-are-values
https://github.com/golang/go/wiki/CodeReviewComments
https://golang.org/doc/faq
https://golang.org/ref/spec
https://blog.golang.org/constants