Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
@reu
reu / edit.html.erb
Created May 12, 2010 19:06
Custom attributes using serialization
<% form_for(@user) do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<% f.fields_for :custom, @user.custom do |custom_form| %>
<% custom_form.object.marshal_dump.each_key do |custom_field| %>
<p>
<%= custom_form.label custom_field %><br />
- form_for @products do |form|
%h3== Specifications
%ul#specifications_container
- form.fields_for :specifications do |specification_form|
= render :partial => "specification", :locals => { :form => specification_form }
%p= add_child_link "Add Specification", :specifications
= new_child_fields_template form, :specifications
(function(){
//Adcionando o método digaOla para a classe Date
Date.prototype.digaOla = function() {
var hora = this.getHours();
if(hora > 00 && hora <= 06)
return "Boa madrugada";
else if(hora > 06 && hora <= 12)
return "Bom dia";
else if(hora > 12 && hora <= 18)
@reu
reu / lsimple.c
Created June 12, 2010 03:05
List current directory (aula de introdução a programação)
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
int main (void)
{
DIR *directory;
struct dirent *current_file;
if(directory = opendir("./")){
@reu
reu / cpsimple.c
Created June 12, 2010 14:17
Simple file copy example using functions
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
return copy(open_file_for_reading(argv[1]), open_file_for_writing(argv[2]));
}
int copy(FILE *source_file, FILE *target_file)
{
@reu
reu / factorial.c
Created June 12, 2010 17:37
The famous factorials (aula de introdução a programação)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("%i\n", factorial(atoi(argv[1])));
}
int factorial(int number)
{
@reu
reu / arrays.c
Created June 12, 2010 18:04
Arrays (aula de introdução a programação)
#include <stdio.h>
int main()
{
char *students[3];
int iterator;
students[0] = "Thiago";
students[1] = "Gustavo";
students[2] = "Thomas";
Dim Connection As New SqlConnection()
Dim Command As New SqlCommand()
Dim Result As SqlDataReader
Connection.ConnectionString = "Data Source=myserver;Initial Catalog=databasename;Integrated Security=True"
Connection.Open
Command.Connection = Connection
Command.CommandText = "SELECT * FROM users"
<?php
function sendEmailViaWebService($email) {
$soapClient = new soapclient("http://www.paulinia.sp.gov.br/email/sendmail.asmx?WSDL", "wsdl");
$request = "<Send xmlns='http://tempuri.org/'>
<De>{$email['from']}</De>
<Para>{$email['to']}</Para>
<Assunto>{$email['subject']}</Assunto>
<Mensagem>{$email['message']}</Mensagem>
</Send>";
1.upto 500 do
Class.new do
1.upto 1000 do |method_number|
method_name = "method_#{method_number}"
instance_eval "# Hi I am a comment for #{method_name}"
attr_accessor method_name.to_sym
end
["click", "mousedown", "mouseenter", "mouseleave", "mouseout", "mouseover", "mouseup"].each do |event|
define_method event.to_sym do
"Hi I am on #{event}"