Skip to content

Instantly share code, notes, and snippets.

View mcuadros's full-sized avatar

Máximo Cuadros mcuadros

View GitHub Profile
@mcuadros
mcuadros / gist:6877641
Created October 8, 2013 00:45
99 bottles = 232 chars = 2 hours missed @ http://www.phpgolf.org/challenge/99-Bottles

http://www.phpgolf.org/challenge/99-Bottles

<?$w=' on the wall';$c=' bottle';$p=$c.s;$b=' of beer';for($v=99;$v>0;print"$r$w, $r.\n".(--$v?"Take one down and pass it around, $v".($v>1?$p:$c)."$b$w.":"Go to the store and buy some more, 99$p$b$w.")."\n\n")$r=$v.($v>1?$p:$c).$b;
@mcuadros
mcuadros / gist:5532049
Created May 7, 2013 11:55
#PHP odd: you can use any special char after a case like in PHP instead of ":", like a * a pipe, etc. Try it! "
<?php
//This is a valid PHP
switch (true) {
case 'semicolon'; //<-- Documented
false;
case 'asterisk'*
false;
case 'pipe'|
@mcuadros
mcuadros / gist:5427447
Created April 20, 2013 21:10
Just playing with Go Flags (http://godoc.org/github.com/jessevdk/go-flags) an example with Commands
package main
import (
"fmt"
"github.com/jessevdk/go-flags"
"os"
"strings"
)
func main() {
@mcuadros
mcuadros / gist:5344879
Last active December 16, 2015 00:08
Basic example in PHP of Mongo 2.4 Text Search feature.
<?php
$m = new MongoClient(); // connect
$db = $collection = $m->foo; // get the database named "foo"
$collection = $db->bar; // get the collection "bar" from database named "foo"
$collection->ensureIndex(
array(
'title' => 'text',
'desc' => 'text',
@mcuadros
mcuadros / gist:5240520
Last active December 15, 2015 09:39
Benchmark from Skeetr early alpha version, Skeetr is PHP Application Server based on Gearmand + Nginx.

Skeetr 0.0.1 Benchmark

Benchmark from Skeetr early alpha version, Skeetr is PHP Application Server based on Gearmand + Nginx.

Setup

We make random requests over a Symfony2/Sonata [https://github.com/sonata-project/sandbox] sandbox project, some pages with MySQL, other MongoDB or none

Standard PHP:

@mcuadros
mcuadros / gist:5212635
Last active December 15, 2015 05:59
How expensive is Reflection usage?

How expensive is Reflection usage?

Result:

  • Reflection 100000 iterations in 2.711766 secs
  • Sort of array(100) 100000 iterations in 1.949580 secs
  • Instance and Method call 100000 iterations in 0.284622 secs
@mcuadros
mcuadros / gist:5160940
Last active December 14, 2015 22:48
Benchmarking concatenation with heredoc, single-quoted and double-quoted

PHP 5.4.12 (cli) (built: Mar 8 2013 11:16:05)

Method heredoc 1000000 iterations in 1.970294 secs

$var = <<<EOT
<html><head><title>Benchmark Test Page</title></head><body bgcolor=
"$bgcolor" text="$textcolor" {$foo->bar()} link="$link"><p><font face="$fontface"
size="$fontsize"> Here is some test text for the web page.</font>

REST-HAL endpoints

Summary

Motivation

The requirement of expose the domain via HTTP to other applications.

Services

@mcuadros
mcuadros / gist:59209e4f47395828c297
Last active August 29, 2015 14:01
The Hitchhiker's Guide to the HHVM - Links
<?hh
type Example = (function(): string);
function main() {
$callback = function() {
return 'foo';
};