Skip to content

Instantly share code, notes, and snippets.

View FerPerales's full-sized avatar
🎯
Focusing

Fernando Perales FerPerales

🎯
Focusing
View GitHub Profile
@FerPerales
FerPerales / prime.py
Created July 14, 2012 18:43
Primer numbers
def primos(limite):
primos = []
for elemento in range(2,limite):
encontrado = False
for primo in primos:
if elemento % primo == 0 and elemento is not primo:
encontrado = True
break
if not encontrado:
primos.append(elemento)
@FerPerales
FerPerales / zenExamples
Created August 30, 2012 02:31
Some Zen coding examples
Basic commands:
html:5
Creates a HTML5 template
@FerPerales
FerPerales / gist:3612623
Created September 3, 2012 19:26
Zen code for practice #6
This zen:
html:5>h1+(fieldset>(p>label+input)*2)+(fieldset>(label+(p>input)*4)+(p>label+input)*2)+(fieldset>(p>label+input)*4+(label+select>option*2))
Generates this:
<!DOCTYPE HTML>
<html lang="en-US">
@FerPerales
FerPerales / gist:3777473
Created September 24, 2012 18:26
Software Gurú
public class Operaciones {
/**
* @param args
*/
public static void main(String[] args) {
char operacion = args[0].charAt(0);
int valor = Integer.parseInt(args[1]);
suma(valor, operacion);
}
@FerPerales
FerPerales / gist:3882984
Created October 13, 2012 02:38
Single vs Double
print 'Enter your name: ' #Fer
name = gets()
puts "Hello #{name}" #prints "Hello Fer"
puts 'Hello #{name}' #prints "Hello {name}"
@FerPerales
FerPerales / gist:3884684
Created October 13, 2012 13:48
Evaluations
class RubyMeeting
attr_accessor :name, :number, :date
def initialize( aName, aNumber, aDate = Time.now )
@name = aName
@number = aNumber
@date = aDate
end
def attendance
@FerPerales
FerPerales / gist:3884705
Created October 13, 2012 13:57
Delimiters
puts %Q/This is the same as a double-quoted string./
puts %Q/This is also the same as a double-quoted string./
puts %q/And this is the same as a single-quoted string/
puts %Q*This is the same as a double-quoted string*
puts %Q!This is also the same as a double-quoted string!
puts %q(And this is the same as a single-quoted string)
puts %Q?This is the same as a double-quoted string?
puts %Q/This is also the same as a double-quoted string./
puts %q/And this is the same as a single-quoted string/
puts %Q#This is the same as a double-quoted string#
@FerPerales
FerPerales / gist:3884724
Created October 13, 2012 14:05
Backquote
puts(`ls`)
puts(%x/clear/)
puts(%x{su -})
@FerPerales
FerPerales / gist:3884809
Created October 13, 2012 14:24
Concatenation
s = "Hello " << "rubyCUCEI"
puts s # Hello rubyCUCEI
s = "Hello " + "rubyCUCEI"
puts s # Hello rubyCUCEI
s = "Hello " "rubyCUCEI"
puts s # Hello rubyCUCEI
@FerPerales
FerPerales / gist:3884835
Created October 13, 2012 14:32
Special concat
#s = "Hello " + 64 #Error: can't convert Fixnum into String
s = "Hello " << 64
puts s # Hello @
s = "Hello " << 64.to_s
puts s # Hello 64