This file contains 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
(doseq [i (range 1 101)] | |
(let [mn {"" (str i)} | |
st (str (get ["Fizz" nil] (rem i 3) nil) | |
(get ["Buzz" nil] (rem i 5) nil))] | |
(println (get mn st st)))) |
This file contains 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
(ns clj-design-patterns.template-method) | |
(defn crear-perro [nombre ladrido] | |
{ :nombre nombre, :ladrido ladrido }) | |
(def chiguagua | |
(crear-perro :chiguagua (fn [] (println "guau!")))) | |
(def bulldog | |
(crear-perro :bulldog (fn [] (println "GUAU!")))) |
This file contains 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
# Probado en Ruby 1.9.3 | |
######################## | |
# Ejemplo de Duck Typing | |
######################## | |
class Chiguagua | |
def ladrar | |
puts "guau!" | |
end |
This file contains 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
# Probado en Ruby 1.9.3 | |
############################################################# | |
# Implementación del patrón template method usando prototipos | |
############################################################# | |
# perro es el prototipo de los otros objetos | |
perro = Object.new | |
# Nota: define_singleton_method define un |
This file contains 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
# Probado en Ruby 1.9.3 | |
######################################################### | |
# Implementación del patrón template method usando clases | |
######################################################### | |
class Perro | |
def ladrar | |
3.times do | |
ladrar_especifico |
This file contains 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
(ns family-recursion.core) | |
(def families | |
{ :ale [:alep :alem :luli] | |
:luli [:lulip :lulim :sabri :ale] | |
:sabri [:luli :ale :enrrique] | |
:enrrique [:pablo :diego] | |
:pablo [:jesus :ernesto] | |
:ernesto [:ernestop :ernestom] }) |
This file contains 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
; SICP exercise 1.6 | |
(define (new-if predicate then-clause else-clause) | |
(cond (predicate consecuent) | |
(else alternative))) | |
(define (square x) (* x x)) | |
(define (good-enough? guess x) | |
(< (abs (- (square guess) x)) 0.001)) |
This file contains 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
/** | |
* Esta clase representa un paso de la cadena y tiene la responsabilidad | |
* de ejecutar la propia lógica de negocios y la de continuar la cadena. | |
* | |
* @author jolisper | |
* | |
*/ | |
public abstract class Chain { | |
private Chain next; |
This file contains 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
require 'socket' | |
# Simple preforked echo server | |
socket = TCPServer.open('localhost', 2000) | |
puts "PID: " + Process.pid.to_s | |
3.times do | |
fork do |
This file contains 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 morse_to_eng(morse) | |
table = { | |
A:'.-', N:'-.', B:'-...', O:'---', C:'-.-.',P:'.--.',D:'-..',Q:'--.-', | |
E:'.',R:'.-.',F:'..-.',S:'...',G:'--.',T:'-',H:'....',U:'..-', | |
I:'..',V:'...-',J:'.---',W:'.--',K:'-.-',X:'-..-',L:'.-..',Y:'-.--', | |
M:'--', Z:'--..' }.invert | |
phrase = '' | |
morse.split(' ').each do |word| | |
phrase << word.split(' ').map { |letter| table[letter] }.join << ' ' |
NewerOlder