Skip to content

Instantly share code, notes, and snippets.

View humbertodosreis's full-sized avatar

Humberto dos Reis Rodrigues humbertodosreis

View GitHub Profile
@humbertodosreis
humbertodosreis / remove-file-from-last-commit.sh
Last active September 17, 2019 19:07
Removing one file from last commit
# https://stackoverflow.com/a/15321456
git reset --soft HEAD~1
git reset HEAD path/to/unwanted_file
git commit -c ORIG_HEAD
@humbertodosreis
humbertodosreis / install-phantomjs.sh
Created September 3, 2019 18:53
Install phantomjs
sudo yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo mkdir -p /opt/phantomjs
bzip2 -d phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo tar -xvf phantomjs-1.9.8-linux-x86_64.tar \
--directory /opt/phantomjs/ --strip-components 1
sudo ln -s /opt/phantomjs/bin/phantomjs /usr/bin/phantomjs
@humbertodosreis
humbertodosreis / build_tree.php
Created August 1, 2018 18:48
Example to build tree with recursive algorithm in PHP
<?php
function build_tree($nodes, $parent=0)
{
$branch = [];
foreach($nodes as $node) {
if ($node['parent'] == $parent) {
$childrens = build_tree($nodes, $node['id']);
if (!empty($childrens)) {
<?php
namespace App\Infra;
class SwooleDaemon
{
/**
* @var int[]
*/
private $pipes = [];
@humbertodosreis
humbertodosreis / 1_usecase.php
Created July 6, 2018 15:00 — forked from makasim/1_usecase.php
Async non blocking process daemon. Stderr\Stdout proxy, Child reboot on exit, Graceful child exit on sigterm, reload on usr1 signal
<?php
use Symfony\Component\Process\PhpExecutableFinder;
require_once __DIR__.'/../vendor/autoload.php';
$phpBin = (new PhpExecutableFinder)->find();
if (false === $phpBin) {
throw new \LogicException('Php executable could not be found');
}
@humbertodosreis
humbertodosreis / symfony3-rest-api.md
Created June 14, 2018 20:44 — 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 :

Redux Selector Pattern

Imagine we have a reducer to control a list of items:

function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
  switch(action.type) {
    case 'SHOW_ALL_ITEMS':
      return action.data.items
    default:
@humbertodosreis
humbertodosreis / remote react bootstrap table example
Created February 6, 2018 20:07 — forked from xabikos/remote react bootstrap table example
An example of a react bootstrap table that fetches the data asynchronously when navigating between pages and when changing the page size
import React, {Component} from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';
import _ from 'lodash';
const dataTable = _.range(1, 60).map(x => ({id: x, name: `Name ${x}`, surname: `Surname ${x}`}));
// Simulates the call to the server to get the data
const fakeDataFetcher = {
fetch(page, size) {
return new Promise((resolve, reject) => {
@humbertodosreis
humbertodosreis / EmFactory.php
Created February 6, 2018 20:04 — forked from samsch/EmFactory.php
Symfony dynamic DB connection
<?php
namespace AppBundle\Services\Factories;
//Inject the EM and Connection for the configured em that needs to be dynamic.
//I think you can actually just inject the EM, and call ->getConnection() it.
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Connection;
//This service gets the dynamic DB creds from the request/user/whatever.
@humbertodosreis
humbertodosreis / ForcedLogoutListener.php
Created November 29, 2017 19:27 — forked from slavafomin/ForcedLogoutListener.php
Logging user out of Symfony 2 application using kernel event listener
<?php
namespace App\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;