Skip to content

Instantly share code, notes, and snippets.

View adrianalonso's full-sized avatar

Adrián Alonso Vega adrianalonso

View GitHub Profile
@adrianalonso
adrianalonso / ImportCountriesCommand.php
Created January 22, 2016 12:10
Symfony Command Import CSV
<?php
namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@adrianalonso
adrianalonso / 0_reuse_code.js
Created April 11, 2016 07:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#%RAML 0.8
title: examle
version: 1.0
baseUri: http://example.local/api
traits:
- secured:
description: Some requests require authentication
headers:
X-User:
@adrianalonso
adrianalonso / myip.sh
Created September 5, 2016 15:22
Command for determining my public IP
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
wget http://ipinfo.io/ip -qO -
@adrianalonso
adrianalonso / BodyRequestListener.php
Last active April 24, 2017 16:14
JSON BodyRequestListener
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
@adrianalonso
adrianalonso / functions.php
Created April 6, 2017 08:25
Resize images on Wordpress
/**
* Image Resize
*
* @param $attachment_id
* @param $width
* @param $height
* @param bool $crop
* @return bool|string
*/
function rw_image_resize( $attachment_id, $width, $height, $crop = true )
@adrianalonso
adrianalonso / ArrayMergeUtil.php
Created May 20, 2017 11:40
Array Merge with Integer Keys
class ArrayMergeUtil
{
/**
* @param array $array
*
* @return array
*/
public static function flatArrayAndSumValues(array $array)
{
$result = [];
@adrianalonso
adrianalonso / docker.sh
Created May 20, 2017 12:32
Eliminar contenedores e imágenes Docker
Eliminar todos contenedores
$ docker rm $(docker kill $(docker ps -aq))
Eliminar todas imágenes
$ docker rmi $(docker images -qf "dangling=true")
@adrianalonso
adrianalonso / standard_layout.html.twig
Created May 26, 2017 08:56
Custom Menu Sonata Admin
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block side_bar_after_nav %}
YOUR CUSTOM MENU
{% endblock %}
@adrianalonso
adrianalonso / pagination_promise_chain.js
Created January 6, 2019 11:58
Pagination Promise Chain
function getPaginatedElements(getResourcePromise, progressFn, limit = 25, offset = 0, elements = []) {
return new Promise((resolve, reject) =>
getResourcePromise({limit, offset})
.then(response => {
const newElements = elements.concat(response.records);
if (response.records.length === 0) {
resolve(newElements);
} else {
progressFn && progressFn(elements);
getPaginatedElements(getResourcePromise, progressFn, limit, offset+limit, newElements)