Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env php
<?php
function restart_web($interface) {
passthru("ifconfig $interface down");
passthru("ifconfig $interface up");
sleep(5);
}
function ping($host) {
<?php
class BaseAdder
{
public function add($a, $b)
{
return $a + $b;
}
}
@MarcelloDuarte
MarcelloDuarte / decrease_and_print.php
Created April 9, 2013 07:13
Even wondered how to use recursion in PHP closures?
<?php
$decrease = function($self, $number) {
if ($number >= 0) {
echo $number . PHP_EOL;
$self($self, --$number);
}
};
$decrease($decrease, 10);
@MarcelloDuarte
MarcelloDuarte / dsl.php
Last active October 11, 2015 18:58
Building DSLs
<?php
function describe($testedClass, callable $tests) {
print ("$testedClass" . PHP_EOL);
$tests();
}
function it($testName, callable $test) {
print(" $test" . PHP_EOL);
$test();
@MarcelloDuarte
MarcelloDuarte / passing.php
Created October 17, 2012 08:18
Passing a closure to a function
trimAndLower($elem -> {
return trim(strtolower($elem));
});
$sayHi = { echo "hi"; };
$sayHi(); // prints: hi
$sayHello = $name -> { echo "hello, $name"; };
$sayHello("Chuck Norris"); // prints: hello, Chuck Norris
@MarcelloDuarte
MarcelloDuarte / alarm.php
Created November 2, 2011 06:24
My improvised PHP alarm
<?php
date_default_timezone_set('Europe/London');
$alarm = '06:00';
$musicFileToPlay = '~/Music/4\ non\ blondes/1-01\ Train.mp3';
$open = 'open'; // change this to what is the command in you OS. This works for MacOSX
while (true) {
<?php
namespace Behat\Mink\Driver\Selenium;
use \PHPUnit_Extensions_SeleniumTestCase as SeleniumTestCase;
class Client extends SeleniumTestCase
{
public function __construct($browser = '*firefox', $sid = null,
md@bossa:phpspec (develop) $ behat
Feature: Developer sees help
As a developer
In order to know which cammands are available in PHPSpec
I want a command line option that displays the help
Scenario: Long option # features/developer_sees_help.feature:6
When I use the command "phpspec --help" # CommandContext::iUseTheCommand()
Then I should see # CommandContext::iShouldSee()
"""
<?php
class AutoRun {
static public $lastTime;
public static function main($argc, array $argv = array()) {
chdir(".");
$lastTime = time();
$dir = new DirectoryIterator(".");
$autorun = new AutoRun($lastTime, $dir);