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
// querying and cursors | |
cursor = db.people.find(); null ; | |
cursor.hasNext() // returns true (if there is another set of results) and false (if not) | |
cursor.next() // returns the next result and move the cursor foward | |
// Limiting the set of results returned by the queries | |
cursor.limit(5); null; // limit the results returned by the cursor (default is 20) | |
// note: the 'null' keyword is used to prevent the mongoshell from printing that query out |
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 | |
Recebe uma entrada de dados (palavra(s)), faz a contagem de cada palavra e mostra na tela em ordem crescente por quantidade de repetições | |
=end | |
puts "Enter some text" | |
text = gets.chomp # recebe a entrada de dados | |
words = text.split(" ") # cria um array, onde cada palavra ficará em uma posição | |
# cria um hash vazio para armazenar as palavras e a quantidade de vezes que apareçem |
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
# if/else | |
if x > y | |
print "x é maior que y" | |
elsif x < z | |
print "x é menor que y" | |
else | |
print "valor padrão" | |
end | |
# unless |
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
/* | |
Exercice: | |
Define a function called olderAge. We want the function to return the age of the person who is older. | |
*/ | |
// Our person constructor | |
function Person (name, age) { | |
this.name = name; | |
this.age = age; | |
} |
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 | |
// openning connection | |
$link = mysqli_connect('host', 'user', 'password', 'database') | |
or die('Could not connect to server'.'<br>'); | |
// uncomment next line to debug | |
//print 'connection opened'.'<br>'; | |
?> |
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
/* objetos */ | |
// literal notation | |
var calendar = { | |
name: "PHP Event", | |
year: 2012 | |
}; | |
// constructor | |
var pets = {}; | |
// OU |
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
def censor(text, word): | |
"""takes two strings 'text' and 'word' as input and | |
returns the text with the word you chose replaced | |
with asterisks.""" | |
import string # we're going to use split and join built-in functions | |
# first of all, we need to break the words into a list | |
text = string.split(text) | |
# now, we iterate over the list index |
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
### abstract data type - ADT | |
### specifies a set of methods and what they do, but not its implementation | |
## | |
### -> the stack ADT = a collection/data structure with mutiple elements | |
##""" a ADT is defined by its interface: the operations/methods that | |
## can be performed on it """ | |
## | |
### interface of a stack: | |
##__init__ = initialize a new empty stack | |
##push = add a new item to the stack |
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
/* | |
* Leia um vetor de N posições | |
* leia dois valores x e y | |
* procure os valores armazenados nos índices x e y do vetor | |
* imprima a soma destes valores | |
*/ | |
package vetores; | |
import java.util.Scanner; |
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
/* | |
* Leia um vetor de 20 posições | |
* leia um valor X qualquer | |
* Faça uma busca de X no vetor | |
* informe a posição do vetor que X foi encontrado | |
* ou diga que não foi encontrado | |
*/ | |
package vetores; | |
import java.util.Scanner; |