This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Recebe a função soma como argumento (f = soma) | |
def meu_decorator(f): | |
#Escreve uma nova função | |
#nova_soma recebe os mesmos argumentos da soma (não precisa ser *args) | |
#Imagine que é uma nova versão da sua soma | |
def nova_soma(x,y): | |
#Executa algo antes | |
print 'iniciando nova soma' | |
f(x,y) #Chama a própria função soma (a soma externa) | |
#Executa algo depois |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
#Exemplo de *args e **kwargs (argumentos ilimitados, nomeados e em qualquer ordem) | |
class Conta(): | |
#É precico passar o self para dentro dos métodos de instância | |
#O Python é bem explícito :) | |
def metodo(self, *args, **kwargs): | |
print args | |
print kwargs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Exemplo de for super legal utilizando Scala | |
object Laco{ | |
//main (um pouquinho diferente do java) | |
def main(args: Array[String]){ | |
for{ | |
/* | |
Para cada 5 incrementos em i vai haver 1 incremento em j | |
Quando i chegar a 5 vai resetar seu contador para 1 e j vai incrementar para 2 | |
E assim sucessivamente... ate j chegar a 5 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Função recursiva que calcula o fatorial de um número | |
function fatorial($numero){ | |
if($numero <= 1){ | |
return $numero; | |
}else{ | |
return $numero * fatorial($numero - 1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
@author: Tiago Davi | |
@blog: tiagodavi.blogspot.com | |
//fonte : somatematica.com.br | |
CÁLCULO DO M.D.C. PELO PROCESSO DAS DIVISÕES SUCESSIVAS | |
Regra prática: | |
1º) dividimos o número maior pelo número menor; | |
48 / 30 = 1 (com resto 18) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//mdc (PHP 5.3) | |
$mdc = function($x,$y) use (&$mdc){ | |
$a = max($x,$y); | |
$b = min($x,$y); | |
return ($a%$b == 0) ? ($b) : ($mdc($b,($a%$b))); | |
}; | |
//mmc (PHP 5.3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//(Variáveis Variantes)Não é só o conteúdo da variável que pode mudar mas também seu nome | |
$variavel = 'nome'; | |
// $$ Cria uma nova variável representada pelo contéudo de $variavel | |
$$variavel = '@auhtor: Tiago Davi'; | |
//=> @auhtor: Tiago Davi | |
echo $nome.'<br>'; | |
$frameworks = array( | |
'codeigniter' => 'leve, simples, flexível e baixa curva de aprendizado', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Armamentos/Armamento.php | |
<?php | |
//Qualquer tipo de arma deve implementar armamento | |
interface Armamento{ | |
//Deve obrigatoriamente poder ser utilizada | |
public function usar(); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<!-- jquery CDN --> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> | |
</script> | |
<script type="text/javascript"> | |
$(function(){ | |
//Verifica se temos acesso ao recurso |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Content-Type do tipo stream | |
header('Content-Type: text/event-stream'); | |
//Sem cash | |
header('Cache-Control: no-cache'); | |
//Inicia uma função | |
function send_msg($msg) { | |
//Envia um json | |
echo 'data:'.json_encode(array('id' => rand(0,100), 'msg' => $msg)); | |
//Descarrega o buffer de saída |
OlderNewer