Skip to content

Instantly share code, notes, and snippets.

View andersonfraga's full-sized avatar
🧩
Focusing

Anderson Fraga andersonfraga

🧩
Focusing
View GitHub Profile
%%
/**
* Anderson Jean Fraga
* 13180375
* Compiladores - Trabalho 1 - Exercicio 1
*/
%public
%class Lexica_01
@andersonfraga
andersonfraga / index.php
Last active August 29, 2015 14:10
Busca a menor máscara possível em uma lista de CIDRs
<?php
class IPv4Subnet
{
private $address, $mask;
function __construct($ip)
{
list($this->address, $this->mask) = $this->toBin($ip);
}
@andersonfraga
andersonfraga / ques.sml
Created October 9, 2014 02:24
E em 30mins brincando com esse tal de AliceML...
(********************
Especifique a função mediaListaSemPares que recebe uma lista de inteiros umaLista e retorna a média dos elementos de umaLista, descartando os valores pares (listas com 1 ou nenhum elemento, retornam vazias)
********************)
fun listaSemPares umaLista = List.filter (fn x => x mod 2 <> 0) umaLista;
fun somaLista [] = 0
| somaLista (x::res) = x + somaLista res;
fun mediaListaSemPares [] = 0.0
| mediaListaSemPares umaLista =
@andersonfraga
andersonfraga / Main.java
Created September 2, 2014 13:43
BigDecimal?
class Conta
{
private BigDecimal saldo;
public Teste()
{
saldo = new BigDecimal(0.0);
}
# alias
alias la='ls -la --color=auto'
alias ..='cd ..'
alias .='pwd'
alias www='cd /www'
alias cntfiledir='ls -l | awk "!/^d/{print }" | wc -l'
alias g='git'
export PATH=$HOME/local/bin:$PATH
@andersonfraga
andersonfraga / wcs.php
Created July 30, 2014 15:10
Code watchers default
#!/usr/bin/php
<?php
require '../phpwatcher.php';
phpwatcher(['./tests/unit/', './module/'], '(.*)\.php', function ($file) {
echo ($exec = "php-cs-fixer fix {$file} --level=all") . PHP_EOL;
system($exec);
echo PHP_EOL;
});
@andersonfraga
andersonfraga / gist:04b9744f1f6e3a55e0dd
Created July 16, 2014 12:10
Tempo retroativo por extenso pt-br
<?php
function dateFormat($date) {
if (!$date) {
return '';
}
$nowDay = new DateTime('now');
$pastDay = new DateTime($date);
#!/usr/bin/php
<?php
require '../phpwatcher.php';
phpwatcher(['./module/','./tests/unit/'], '(.*)\.php', function ($_, $objfile) {
echo "\nChanged {$_}\n";
echo ($exec = 'cd ./tests/unit/ && phpunit .') . PHP_EOL;
system($exec);
echo PHP_EOL;
@andersonfraga
andersonfraga / gist:8603259
Created January 24, 2014 18:32
Bug ao usar array_diff_assoc?
<?php
$diff = array_diff_assoc(array(array('dsa' => '2')), array(array(),array()));
if (count($diff)) {
print_r($diff);
}
echo '<br />Gerou um "PHP Notice: Array to string conversion" na linha 3';
echo '<br />----';
@andersonfraga
andersonfraga / Module.php
Created November 8, 2013 11:59
Redirects HTTPS in Zend2
<?php
$request = $e->getRequest();
$needHttps = (preg_match($listNeedHttps, $request->getRequestUri()) != false);
$isHttps = ($request->getUri()->getScheme() == 'https');
$isGetMethod = ('GET' == $request->getMethod());
$url = new Http($request->getUri());
if ($needHttps and !$isHttps and $isGetMethod) {
$url->setScheme('https');