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
// Primeiro eu crio uma variável chamada nome | |
// depois abro uma caixa pedindo o nome usando 'prompt' | |
// e jogo o que você digitar na variável nome | |
var nome = prompt("Qual o seu nome?"); | |
// A função confirm vai me retornar true se você clicar em OK | |
// e vai retornar false se você clicar em cancelar ou apertar ESC | |
if(confirm("Seu nome é " + nome + "?")) { | |
// Se você apertou OK, o alert mostra uma caixa | |
// com um botão OK exibindo a mensagem Olá e o seu nome |
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
(ns euler04-2) | |
(defn peel | |
"Peel a string like a banana, removing first and last character" | |
[str] | |
(butlast (rest str))) | |
(defn palindrome? | |
"Returns true or false if name is a palindrome. | |
This recursive approach is slightly faster than compare with its reverse." |
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
(ns server.core) | |
(import [java.net ServerSocket]) | |
(import [java.io DataInputStream | |
DataOutputStream]) | |
(defn- debug [message] | |
(println (str "[" (.getName (Thread/currentThread)) "] " message))) | |
(defn- start-server |
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
rails g migration ChangeNomeSizeInDepartamento | |
invoke active_record | |
create db/migrate/20130428143550_change_nome_size_in_departamento.rb |
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 ChangeNomeSizeInDepartamento < ActiveRecord::Migration | |
def up | |
change_column(:departamentos, :nome, :string, :limit => 60, :null => false) | |
end | |
def down | |
end | |
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
rake db:migrate | |
== ChangeNomeSizeInDepartamento: migrating =================================== | |
-- change_column(:departamentos, :nome, :string, {:limit=>60, :null=>false}) | |
-> 0.0445s | |
== ChangeNomeSizeInDepartamento: migrated (0.0447s) ========================== |
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
# Primeiro você criou um model chamado Contato | |
rails g model contato nome:string{60} endereco:string{100} | |
invoke active_record | |
create db/migrate/20130428145000_create_contatos.rb | |
create app/models/contato.rb | |
invoke test_unit | |
create test/unit/contato_test.rb | |
create test/fixtures/contatos.yml |
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 AddFieldsToContato < ActiveRecord::Migration | |
def change | |
change_table :contatos do |t| | |
t.string :cidade , :limit => 60 | |
t.string :cep , :limit => 8 | |
t.string :telefone, :limit => 20 | |
end | |
end | |
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
(group-by even? (range 1 11)) | |
; {false [1 3 5 7 9], true [2 4 6 8 10]} | |
(group-by #(= (mod % 3) 0) (range 1 15)) | |
; {false [1 2 4 5 7 8 10 11 13 14], true [3 6 9 12]} | |
(group-by #(mod % 3) (range 1 15)) | |
; {1 [1 4 7 10 13], 2 [2 5 8 11 14], 0 [3 6 9 12]} |
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
Inicio | |
+---------+---------+---------+ | |
| 6 | 3 | 8 4 | | |
| | | | | |
| 5 3 7 | 9 | | | |
| | | | | |
| 4 | 6 | 3 7 | | |
+---------+---------+---------+ | |
| 9 | 5 1 | 2 3 8 | | |
| | | | |