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
=begin | |
o objetivo abaixo é trazer para o Rails 2.1 o recurso de atribuir um Hash e ele criar a entidade. | |
Ao invés de: pessoa.endereco_residencial = Endereco.new(:cep => 12345678) | |
fazer: pessoa.endereco_residencial = {:cep => 12345678} | |
para facilitar uso de submodel em form: Pessoa has_one EnderecoResidencial | |
mas ao mesmo tempo, tratar as seguintes característica: | |
Se não tiver endereço, cria ao atribuir hash ou objeto. | |
Se já tiver endereço e atribuir um hash vazio ou um endereco vazio, apagar o relacionamento. | |
Se atribuir um hash não vazio e já tiver endereço, faz update, ao invés de destruir e criar dinovo. | |
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
<? | |
function validar_cartao($c) { | |
$c = ereg_replace("[^0-9]", "", $c); | |
$s = 0; | |
$v = ''; | |
$n = strlen($c); | |
if ($n != 16) return false; | |
if ($c[0] != '4') return false; | |
for($i = 0; $i < $n; $i += 2){ |
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Título do Seu Site</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
<script type="text/javascript" src="js/swfobject.js"></script> | |
<script type="text/javascript"> | |
var flashvars = {swf:"index.swf"} | |
var params = {wmode:"transparent"} | |
var attributes = {} |
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
package | |
{ | |
import flash.display.* | |
import flash.events.* | |
public class Botao extends SimpleButton | |
{ | |
var estado = "up" | |
function Botao() | |
{ | |
iniciar_parado() |
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
# estou estudando variaveis de classe e para entender corretamente seu comportamento, | |
# criei uma variavel que deveria contar quantas vezes a classe foi criada, | |
# mas gostaria que tivesse um contador para cada classe, de modo que se eu criar um animal, | |
# o contador incrementa apenas para a classe Animal, mas se eu criar um Gato, o contador incrementa | |
# para a classe Gato e para a classe Animal também. | |
class Animal | |
@@total = 0 | |
def self.total |
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
describe Animal do | |
before(:each) do | |
Animal.new | |
end | |
it "ao criar um Animal, o contador dos filhoes deve permanecer 0" do | |
lambda { Animal.new }.should_not change(Gato, :total) | |
end |
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
class Animal | |
@@total = 0 | |
def initialize | |
increment_total | |
end | |
def self.total | |
@@total | |
end |
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
.svn | |
.DS_Store | |
Thumbs.db | |
*~$ | |
config/database.yml | |
log/*.log | |
tmp/**/* | |
vendor/src/**/* | |
db/*.sqlite* |
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
=begin | |
esta é uma solução que tenho implementada no PHP. | |
a configuração é feita no construtor, | |
pois o PHP não suporta código a nível de classe como o Ruby. | |
Como posso converter o comportamento abaixo para nivel de classe, | |
onde eu posso configurar direto na classe, sem utilizar o construtor? | |
=end | |
class CrudController | |
attr_reader :acoes |
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Título do Seu Site</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
<link rel="stylesheet" href="global.css" /> | |
<script src="global.js"></script> | |
</head> | |
<body> |
OlderNewer