Skip to content

Instantly share code, notes, and snippets.

View crguezl's full-sized avatar
🌋

Casiano Rodriguez-Leon crguezl

🌋
View GitHub Profile
Efectivamente prototype es inicializado en las functions pero no en los objects:
> {}.prototype
undefined
> function(){}.prototype
{}
Sin embargo, Object se refiere al constructor:
> {}.constructor == Object
@crguezl
crguezl / Gemfile
Created March 29, 2014 16:43 — forked from fairchild/Gemfile
source :rubygems
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-github'
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
gem 'thin'
@crguezl
crguezl / pl0_wikip.jison
Created April 7, 2014 11:51
Grammar for the PL= language in Jison
%token IDENT CONST VAR PROCEDURE COMPARISON expression NUMBER
%token CALL BEGIN END IF THEN WHILE DO ODD
%%
program
: block "."
;
block
: const var procedure statement
defmodule MyList do
def sum([]), do: 0
def sum([ head | tail ]), do: head + sum(tail)
end
IO.puts MyList.sum [1, 2, 3, 4]
@crguezl
crguezl / app.rb
Created October 22, 2014 11:28
datamapper: simple associations
require 'data_mapper'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/example.db")
class Post
include DataMapper::Resource
property :id, Serial
property :text, Text
@crguezl
crguezl / setsdelegate.rb
Created November 5, 2014 11:55
Delegation in Ruby with DelegateClass.
require 'delegate'
class Set2 < DelegateClass(Array)
attr_accessor :sep
attr_reader :a
protected :a
def initialize(*a)
@sep = ', '
@a = a.uniq.sort
@crguezl
crguezl / delegation2.rb
Created November 5, 2014 12:27
Delegation using rails delegate method
require "rails"
module I
def f
puts "#{self.class}: doing f()"
end
def g
puts "#{self.class}: doing g()"
end
end
require 'sinatra'
require 'sinatra/contrib'
require 'sinatra/reloader' if development?
get '/' do
<<-"EOS"
cookies: #{cookies}<br/>
<a href="/set">Set the cookie 'something' to 'foobar'</a><br/>
<a href="/merge">cookies.merge! 'foo' => 'bar', 'bar' => 'baz'</a>
EOS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.example {
border-style: dashed;
border-width: 2px;
border-color: blue;
@crguezl
crguezl / dudagabriel.rb
Created June 28, 2015 18:15
¿qué definición de C usará tutu, la de A o la de B?
=begin
Hola profesor,
Me ha surgido una duda con una pregunta: supongamos que la clase B hereda de A un método tutu que usa la constante C definida en A. Si en la clase B se define C, ¿qué definición de C usará tutu, la de A o la de B?
Un saludo.
=end
class A
C = 4
def tutu
puts C