Delete all local git branches while retaining the master
After a sprint, all the local branches you have are useless and take up space. Below is a small command to remove them (except master) git branch | grep -v “master” | xargs git branch -D
Il n'y a pas de questions bêtes
After a sprint, all the local branches you have are useless and take up space. Below is a small command to remove them (except master) git branch | grep -v “master” | xargs git branch -D
When you start using PHPUnit, you often find yourself facing the need to simulate a method or object. Fortunately PHPUnit has some methods that can be very useful. How to simulate an object The easiest way to create a mocked object $product = $this->getMockBuilder(‘Product’) ->getMock(); or $product = $this->getMockBuilder(‘Product’) ->setMethods(array()) ->getMock(); This product is a … Read more
To list local and remote branches $ git branch -a remotes only $ git branch -r For the list to be up to date you can use $ git remote update $ git remote prune origin
With the newer version of Ubuntu, the built in function that creates a Hotspot may not work properly on a Lenovo laptop. The way around it is to use ap-hotspot. sudo add-apt-repository ppa:nilarimogard/webupd8 sudo apt-get update sudo apt-get install ap-hotspot To start or stop ap-hotspot sudo ap-hotspot start sudo ap-hotspot stop To configure it sudo … Read more
When we have to process a very large XML, it is unfortunately not possible to use SimpleXML. Fortunately for this, we can use DOMDocument. To do this, just load the desired file and initialize xpath on it with DOMXPath. $document = new DOMDocument(); $document->load($file); $xpath = new DOMXPath($document); If the XML in question has a … Read more
When you want to process an XML file in PHP, there are two possibilities: either we use SimpleXML or we go through DOMDocument. In this article I will deal more specifically with SimpleXML. To load a file, just use the simplexml_load_file method $xml = simplexml_load_file($file); By doing so, you get a SimpleXMLElement. If the XML … Read more
To find out how to load a file in PHP from a form, you have to start by formatting the form correctly. It is mandatory to use the post method as well as the multipart/form-data enctype, otherwise PHP will not receive the necessary data. <form action=”/” method=”post” enctype=”multipart/form-data”> <input type=”file” name=”namefile” /> <input type=”submit” value=”ok” … Read more
It can happen that a function is only callable from one interface (console, apache…). There is a function that returns exactly what we are looking for. In the following example, we are looking to know whether the call is from the console. if (php_sapi_name() != “cli”) { header(“Location: http://www.sadtrombone.com/”); die(); }
By default on WordPress we have TinyMCE and although this plugin is very powerful, there are far too many buttons. Fortunately with a few lines of code, it is possible to configure it. In your theme’s functions.php file or in your plugin, use the hook as follows: function configure_mce( $init ) { // nos options … Read more
When you create a javascript file, you may want to make sure you can use jQuery. To avoid having it twice and maybe introducing incompatibilities, just add this at the beginning of the javascript file: if (typeof jQuery == ‘undefined’) { var script = document.createElement(‘script’); script.src = ‘http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js’; script.type = ‘text/javascript’; document.getElementsByTagName(‘head’)[0].appendChild(script); }