Skip to content

Instantly share code, notes, and snippets.

View gtcarlos's full-sized avatar

Guilherme Carlos gtcarlos

View GitHub Profile
@gtcarlos
gtcarlos / par_impar.rb
Created September 17, 2012 02:10
Função para diferenciar números pares e impares sem usar divisão
def par_impar(num)
if (-1)**num == 1
print "#{num}: par\n"
else
print "#{num}: impar\n"
end
end
par_impar(1)
par_impar(2)
@gtcarlos
gtcarlos / locadora.c
Created October 25, 2012 20:08
Projeto Locadora
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <conio.h>
struct cli
{
char nome[50];
int codigo;
struct mov *alugados;
@gtcarlos
gtcarlos / fila_pilha.c
Created October 29, 2012 00:51
Transformando Pilha em Fila na linguagem C
#include <stdio.h>
#include <stdlib.h>
struct pilha
{
int info;
struct pilha *prox;
};
@gtcarlos
gtcarlos / questionario.rb
Created October 29, 2012 16:33
Questionário
def valida_questionario(confirmacao)
unless confirmacao.downcase == "sim" || confirmacao.downcase == "nao"
print "Responda apenas com Sim ou Nao. "
confirmacao = gets.chomp
valida_questionario(confirmacao)
end
if confirmacao.downcase == "nao"
print "Qual pergunta esta errada?\n"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int main(int lWordofArgs, char* pszArgs[])
{
char primeira_letra, segunda_letra;
int terceiro_numero;
@gtcarlos
gtcarlos / exerc.rb
Created November 30, 2012 02:38
Exercício APDA (INCOMPLETO)
MAX = 8
def fib(n)
return n if (0..1).include? n
fib(n-1) + fib(n-2) if n > 1
end
def fatorial(n)
return n <= 1 ? 1 : n * fatorial(n-1)
end
@gtcarlos
gtcarlos / python_mongo.py
Created February 1, 2013 01:19
Python code to connect to the database MongoDB and select first one.
import pymongo
from pymongo import Connection
connection = Connection('localhost', 27017)
db = connection.test
names = db.names
item = names.find_one()
@gtcarlos
gtcarlos / ruby_mongo.rb
Created February 1, 2013 01:20
Ruby code to connect to the database MongoDB and select first one.
require 'mongo'
include Mongo
@client = MongoClient.new('localhost', 27017)
@db = @client['test']
@names = @db['names']
item = @names.find_one()
@gtcarlos
gtcarlos / elefante.rb
Created February 2, 2013 00:25
1 elefante incomoda muita gente...
1.upto(100) do |e|
puts "#{e} elefante incomoda muita gente" if e == 1
puts "#{e+=1} elefantes #{'incomodam ' * e += 1}muito mais" if e % 2 == 0
puts "#{e+=1} elefantes incomodam muita gente" unless e % 2 == 0
end
<!DOCTYPE html>
</html>
<head>
<title>Administrador de Aplicação</title>
</head>
<body>
<div id=title><h1>Administrador de Aplicação</h1></div>
<table title="Estados">
<thead>
<tr>