Skip to content

Instantly share code, notes, and snippets.

View andersonfraga's full-sized avatar
🧩
Focusing

Anderson Fraga andersonfraga

🧩
Focusing
View GitHub Profile
@andersonfraga
andersonfraga / noticia.php
Created February 22, 2011 17:16
Controller para CRUD e com suporte à XML e JSON um tanto quanto minimalista...
<?php
class NoticiaConteudoController extends RestritoController {
function dependency() {
return Array(
'noticia' => '@NoticiaConteudoModel',
'autor' => '@AutorModel',
);
}
@andersonfraga
andersonfraga / sieve.php
Created June 26, 2011 03:18
Eratostenes Sieve
<?php
function eratostenes_sieve($number) {
$num_max = floor(sqrt($number));
$list = range(2, $number);
for($x = 2; $x <= $num_max; $x++) {
foreach($list as $_k => $_val) {
if($_val != $x and $_val % $x == 0) {
unset($list[$_k]);
@andersonfraga
andersonfraga / float_a.php
Created September 15, 2011 20:38
PHP e suas comparações
<?php
$x1 = (float) "111111111111111111111111111111111111111111111111111111112";
$x2 = (float) "111111111111111111111111111111111111111111111111111111111";
var_dump($x1);
var_dump($x2);
if($x1 == $x2){
echo "iguais";
}
@andersonfraga
andersonfraga / controller.php
Created October 26, 2011 17:19
Proposal Bundle Restful for Symfony
<?php
namespace App;
use Restsym/Controller;
use Restsym/Controller/RespondTo;
use App/News/Repository as DataNews;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@andersonfraga
andersonfraga / static.js
Created December 6, 2011 17:19
Troca uma imagem em background de segundos em segundos
$j(document).ready(function() {
counter_img = 1;
setInterval(function() {
if(++counter_img > 4) {
counter_img = 1;
}
$j('#topo > h1').animate({
opacity: '0.8'
export PATH=$HOME/local/bin:$PATH
#colors
export CLICOLOR=1
export LSCOLORS=GxFxCxDxegedabagaced
#customize output shel
parse_git_branch () {
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)#(git \1)#'
}
@andersonfraga
andersonfraga / gist:1901838
Created February 24, 2012 16:17
CentOS - php + git
sudo yum install php53u php53u-cli php53u-gd php53u-common php53u-devel php53u-mbstring php53u-mysql php53u-pdo php53u-pecl-apc php53u-pecl-apc-debuginfo php53u-xml php53u-xmlrpc php53u-intl git-all
@andersonfraga
andersonfraga / IndexController.php
Created February 29, 2012 19:55
Firewall Symfony2
<?php
namespace App\BackendBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
@andersonfraga
andersonfraga / gist:2311122
Created April 5, 2012 13:48
Calcula a quantidade de moedas a sairem de um caixa, dado determinado valor
<?php
function calcular_moedas($valor) {
$moedas_disponiveis = array(0.5, 0.25, 0.1, 0.05, 0.01);
$quantidade_moedas = array();
$soma = 0.0;
foreach($moedas_disponiveis as $moeda) {
while($valor > ($soma + $moeda)) {
if(!isset($quantidade_moedas["{$moeda}"])) {
@andersonfraga
andersonfraga / gist:2340435
Created April 8, 2012 23:58
Install mysql via source-code
# crédito http://brunitto.wordpress.com/2011/10/15/tutorial-instalando-o-mysql-5-5-16-no-ubuntu-server-11-10/
mkdir /opt/src
cd /opt/src
curl -O http://linorg.usp.br/mysqlDownloads/MySQL-5.5/mysql-5.5.22.tar.gz
apt-get install gcc g++ make cmake autoconf
apt-get install libaio1 libaio-dev
apt-get install libncurses5-dev
tar --extract --gzip --file mysql-5.5.22.tar.gz
cd mysql-5.5.22
cmake .