Skip to content

Instantly share code, notes, and snippets.

@nelsonsar
nelsonsar / example.php
Created September 10, 2015 17:59
Where traits may be useful
<?php
interface InputStream
{
public function close();
public function read($numberOfBytes);
public function skip($numberOfBytes);
}
interface MarkableStream
@nelsonsar
nelsonsar / distance_between_head_commit.sh
Created September 4, 2015 21:10
Calculate distance between HEAD and a given hash
#!/bin/bash
COUNTER=1
for i in $(git log --oneline | cut -d" " -f 1); do
let COUNTER+=1
if [ "$i" = "$1" ]; then
echo "$COUNTER"
fi
done
@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;
}
@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 / PosixErrorCodes.php
Created February 11, 2015 01:59
Posix error codes as class of constants. From here: http://fxr.watson.org/fxr/source/sys/errno.h
<?php
class PosixErrorCode
{
const EPERM = 1; /* Operation not permitted */
const ENOENT = 2; /* No such file or directory */
const ESRCH = 3; /* No such process */
const EINTR = 4; /* Interrupted system call */
const EIO = 5; /* Input/output error */
const ENXIO = 6; /* Device not configured */
<?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 / 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