Skip to content

Instantly share code, notes, and snippets.

@marioluan
marioluan / built-in.js
Last active December 15, 2015 01:58
Pieces of code I've written while taking 10gen's M101J MongoDB for Java Developers course.
// 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
@marioluan
marioluan / contador-de-palavras.rb
Last active April 9, 2021 23:11
Programinhas que fiz utilizando a linguagem de programação Ruby enquanto estudo pelo code academy.
=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
@marioluan
marioluan / control-flow.rb
Last active December 12, 2015 05:29
Anotações e informações básicas que agrupei sobre a linguagem de programação Ruby.
# 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
@marioluan
marioluan / arrays-of-objects.js
Last active December 12, 2015 02:29
Programinhas que escrevo enquanto estudo JavaScript.
/*
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;
}
@marioluan
marioluan / connection.php
Created January 21, 2013 22:14
Simple web application I've coded to insert, delete and select data from database using PHP and MySQL. I've also made both client and server-side validation. Check out a live demo at http://www.marioluan.com.br/php/.
<?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>';
?>
@marioluan
marioluan / intro_basica.js
Last active December 11, 2015 01:38
Linhas de código que estou armazenando com alguns exemplos da sintaxe enquanto aprendo javaScript. Aqui você encontra como instanciar um objeto, como criar uma função, estruturas de repetição/seleção e algumas outras coisas básicas.
/* objetos */
// literal notation
var calendar = {
name: "PHP Event",
year: 2012
};
// constructor
var pets = {};
// OU
@marioluan
marioluan / censor.py
Last active August 7, 2017 11:57
A few programs/functions I've created while learning Python from MOOC's course.
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
@marioluan
marioluan / adt-abstract_data_type.py
Last active October 13, 2015 17:18
Pieces of code I've written since I started the MOOC's Python course. It includes strings, lists, tuples, dictionaries, loops, conditionals, functions, methods, classes, objects, files, exceptions, queues, trees, nodes and some exercices I've done through the course.
### 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
@marioluan
marioluan / array_find_soma.java
Created November 23, 2012 14:13
Programa em Java que cria um vetor de N posições, lê dois valores X e Y, faz uma busca nos índices X e Y do vetor e imprime a soma dos dados encontrados.
/*
* 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;
@marioluan
marioluan / array_find.java
Created November 23, 2012 12:44
Programa em Java que procura um valor dentro de um vetor e imprime na tela.
/*
* 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;