Vagrant da riga di comando, come un ninja

Se sei pigro almeno quanto me, non hai proprio voglia di dover scrivere e riscrivere sempre gli stessi comandi dal terminale. E allora cerchi delle App come Vagrant manger che ti forniscano una Interfaccia Utente in grado di farti risparmiare quel continuo battere sui tasti.

Il problema è che tu adori battere sui tasti, lo fai anche a occhi chiusi, e il solo pensiero di avere un’altra applicazione installata e residente in memoria ti urta.

E allora come si può evitare di perdere energie, soprattutto con ‘sto caldo, e massimizzare la produttività di Vagrant? Semplicissimo. Usa pure questo Gist.


alias vu="vagrant up"
alias vup="vagrant up –provision"
alias vh="vagrant halt"
alias vd="vagrant destroy"
alias vs="vagrant status"
alias vgs="vagrant global-status"
alias vsh="vagrant ssh"

view raw

vagrant.sh

hosted with ❤ by GitHub

Prego 😉

PS: Se non sai come usare il Gist qua sopra, non farti chiamare ninja dai tuoi amici, è ancora troppo presto.

Using your API across domains

Learning is a very tight journey that never ends. Recently I faced an error never met before, on accessing a resource on a different domain via HTTP.

The error was about a browser block because of a missing header in the response, so digging about this thing I came up with its explanation, that you can find here .

This involves CORS (Cross-Origin Resource Sharing) and it restricts access to resource on the server, if they are made from scripts in different domains, for security reasons.

So if you are building an API and you want to consume it from a different domain, you must place an additional header in the response to allow the browser to get the data.

Fairly simple you should put header('Access-Control-Allow-Origin', '*') in your response headers, and replace * with the domain(s) you want to allow, if you want to enable only a few domains (* means anyone can access it).

Replace in a serialized array string

When you need to replace some values in a serialized array string, you can use the following Gist:


<?php
/**
* This function will replace a given text with a new value
* in a serialized string
*
* @param string $input serialized value to seek
* @param string $search text to be replaced
* @param string $replace replacement text
* @return string new serialized string
*/
function serialize_replace($input, $search, $replace) {
$ua = unserialize($input);
$replace_callback = function (&$value, $key, $data) {
if(!is_int($value))
$value = str_replace($data['search'], $data['replace'], $value);
};
array_walk_recursive($ua, $replace_callback , ['search' => $search, 'replace' => $replace]);
$b = serialize($ua);
return $b;
}