Skip to content

Instantly share code, notes, and snippets.

Avatar

Joaquim Torres jqmtor

View GitHub Profile
View ring_swagger_bug.clj
(require '[ring.swagger.swagger2 :as rs])
(require '[schema.core :as schema])
(schema/defschema Person {:age schema/Int})
(defn adult?
[person]
(> (:age person) 17))
(def Adult (schema/constrained Person adult?))
@jqmtor
jqmtor / configurable_gateway.rb
Last active Jun 1, 2016
Make URLs more visible in HTTP-based gateways. In HTTP-based gateways, URL visibility is an important feature because it gives the reader a very good idea of the overall functionality of the class. This proposal strives to achieve that goal and was instigated by @tjsousa, who brought the problem up while reviewing some code.
View configurable_gateway.rb
# simple DSL to describe and build URLs in an HTTP gateway
module ConfigurableGateway
def self.included(base)
base.extend(ClassMethods)
end
def url_for(name, params = nil)
# probably should be replaced by an automatic forwarding mechanism
@jqmtor
jqmtor / init_without_new.rb
Last active Dec 26, 2015
Initialize object without new
View init_without_new.rb
class Team
attr_accessor :name, :country
class << self
undef_method :new
end
def self.constructor(*args)
obj = allocate
obj.send(:initialize, *args)
You can’t perform that action at this time.