Skip to content

Instantly share code, notes, and snippets.

@nelsonsar
nelsonsar / consumer.php
Last active August 29, 2015 13:56
Producer e consumer esperados como resultado no "hands on" da Dafiti Tech Conference 2014
<?php
$connection = new \AMQPConnection(
array(
'host' => '69.195.223.58',
'port' => 5672,
'vhost' => "/",
'login' => "dafitconf",
'password' => "dafiti",
)
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\\\$ ";'
@nelsonsar
nelsonsar / drop_tables_like.sql
Created March 12, 2014 17:05
Drop tables like
SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' )
AS statement FROM information_schema.tables
WHERE table_name LIKE 'myprefix_%';
@nelsonsar
nelsonsar / keybase.md
Created April 2, 2014 15:05
Keybase authenticity

Keybase proof

I hereby claim:

  • I am nelsonsar on github.
  • I am nelsonsar (https://keybase.io/nelsonsar) on keybase.
  • I have a public key whose fingerprint is 805C CAFC D0AF F667 5939 2B4B 7895 35B2 4BDA 90D6

To claim this, I am signing this object:

@nelsonsar
nelsonsar / maybe.php
Last active August 29, 2015 14:00
Maybe shit example...
<?php
abstract class Maybe
{
abstract public function isNothing();
abstract public function get();
public static function fromValue($value)
{
if (null === $value) {
@nelsonsar
nelsonsar / server.php
Created July 1, 2014 00:26
assync php
<?php
class Server
{
private $socket = null;
public function create()
{
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@nelsonsar
nelsonsar / gototest.vim
Created October 26, 2014 02:40
Abrir o arquivo de teste do arquivo aberto em PHP
function GoToTest(...)
let filename = expand('%:t:r')
let test_filename = filename."Test.php"
"You can use a folder to avoid tabf to open the wrong file
if a:0 > 0
execute "tabf **/".a:1."/".test_filename
else
execute "tabf **/".test_filename
endif
endfunction
<?php
class FibonacciValidator
{
public function isFibonacci($number)
{
$positiveVerification = (5 * pow($number, 2) + 4);
$negativeVerification = (5 * pow($number, 2) - 4);
return ($positiveVerification % 4 == 0 || $negativeVerification % 4 == 0);
@nelsonsar
nelsonsar / newtab.js
Created February 19, 2015 20:51
Firefox add-on for open all new tabs after the active tab
var tabs = require("sdk/tabs");
tabs.on('open', function(tab) {
tab.index = tabs.activeTab.index + 1;
});
@nelsonsar
nelsonsar / SitemapDecorator.php
Created March 16, 2015 18:11
SitemapPHP decorator
<?php
class SitemapDecorator extends Sitemap
{
private $decoratedClass = null;
public function __construct(Sitemap $sitemap)
{
$this->decoratedClass = $sitemap;
}