Skip to content

Instantly share code, notes, and snippets.

View drgomesp's full-sized avatar
🏠
Working from home

Daniel Ribeiro drgomesp

🏠
Working from home
View GitHub Profile
@Bolinha1
Bolinha1 / TransformaCsvEmArray.php
Last active August 29, 2015 14:02
Classe que transforma arquivo csv em um array associativo formando um par de chaves e valor usando o cabeçalho como chave.
<?php
namespace Arquivo;
use Exception;
class TransformaCsvEmArray
{
private $arquivo;
private $cabecalho;
public function __construct($arquivo, TransformaCabecalhoCsvEmArray $cabecalho)
{
@mathiasverraes
mathiasverraes / TestFrameworkInATweet.php
Last active September 24, 2024 14:47
A unit testing framework in a tweet.
<?php
function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);}
@Sodaware
Sodaware / phing-call.el
Created November 8, 2013 17:44
Call a phing build target from within Emacs. Will use the build.xml in the directory of the current file. If no build.xml is found, it will search in the directories above until one is found. Base on Ant Call: http://www.emacswiki.org/emacs-en/AntCall
(defun phing-call (target)
"Call Phing's build.xml"
;; Ask for target to execute
(interactive "MPhing Target: ")
;; Open a new *phing-compilation* buffer & kill the old one
(let ((oldbuf (get-buffer "*phing-compilation*")))
(if (not (null oldbuf))
(kill-buffer "*phing-compilation*")))
@Bolinha1
Bolinha1 / Upload.php
Last active December 18, 2015 23:19
Classe upload, refatorada para fazer múltiplo upload.
<?php
namespace Upload;
class Upload
{
public $definePath = '';
private $path;
public function __construct($definePath, $path = 'arquivos/')
{
@aaronpk
aaronpk / gist:5846789
Last active July 2, 2025 12:16
Added WebFinger support to my email address using one rewrite rule and one static file.
[[email protected] www]$ cat .htaccess
RewriteEngine on
RewriteCond %{QUERY_STRING} resource=acct:(.+)
RewriteRule ^\.well-known/webfinger /profile/%1? [L]
[[email protected] www]$ cat profile/[email protected]
{
"subject": "acct:[email protected]",
"links": [
{
@Bolinha1
Bolinha1 / desvioPadrao.php
Last active July 8, 2021 19:59
Calcula o desvio padrão de uma amostra, tanto desvio padrão amostral, quanto desvio padrão populacional
<?php
class DesvioPadrao
{
private $amostra;
public function __construct($amostra)
{
$this->amostra = explode(',', $amostra);
}
@alganet
alganet / greppy.php
Last active August 30, 2017 13:38
Greppy
<?php
// Simple empty matching. Explains a lot of how the idea works:
//
// By default, expressions are delimited by a line, which
// implies /^$/. Everything goes inside that. Calling nothing
// else more matches any line.
//
// p() is a function call. Could be Pattern::create(), but I
// believe providing a function is sane. It can be provided
@alganet
alganet / greppy.php
Created March 6, 2013 19:50
Greppy
<?php
// Matches a single char. Equivalent to: /./
Pattern::char()->test('a'); //true
Pattern::char()->replace('a', 'b'); //b
Pattern::char()->match('a'); //array('a') (captures groups)
// Possible "steps":
@nikic
nikic / objects_arrays.md
Last active May 16, 2025 22:07
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

# Bash-Completion script for PHPUnit
#
# Created by Henrique Moody <[email protected]>
#
_phpunit()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"