Skip to content

Instantly share code, notes, and snippets.

module Pricing::Pricers
class BasePricer
PRICE_EXPIRES_IN = 12.months
attr_accessor :property, :check_in_on, :check_out_on, :reindex, :expiry, :request_live_price, :cookied
alias_method :cookied?, :cookied
def initialize(property, check_in_on, check_out_on, reindex: true, expiry: PRICE_EXPIRES_IN, request_live_price: false, cookied: false)
@property = property
@maciekr
maciekr / gist:287f00b3590742b6806c
Created October 14, 2015 07:28 — forked from jeffsteinmetz/gist:063bd3237033f3af2ed9
Generate Unique, Hashed, Random Token in Scala for use in API calls or as an OAuth Token Bearer
import scala.util._
import java.security.SecureRandom
import java.security.MessageDigest
/*
* Generates a Bearer Token with a length of
* 32 characters (MD5) or 64 characters (SHA-256) according to the
* specification RFC6750 (http://tools.ietf.org/html/rfc6750)
*
* Uniqueness obtained by hashing system time combined with a
@maciekr
maciekr / pricer_factory.rb
Created June 30, 2015 09:35
pricer factory
module Pricing::Pricers
class PricerFactory
def self.pricer_for(property, check_in_on, check_out_on, request_live_price: false)
pricer_class = begin
"Pricing::Pricers::#{property.source.gsub(/\s+/,'')}Pricer".constantize
rescue NameError
Pricing::Pricers::BasePricer
end
@maciekr
maciekr / wyndham_pricer.rb
Created June 29, 2015 16:01
and finally an example of concrete pricer implementation. it overrides couple of 'hooks' to interact with price calculation process in base_pricer
module Pricing::Pricers
class WyndhamPricer < Pricing::Pricers::BasePricer
WYNDHAM_DISCOUNT = 35
def do_force_live_price?
(check_in_on - Date.today).to_i > 1
end
def price_with_members_discount(price)
@maciekr
maciekr / base_pricer.rb
Created June 29, 2015 16:00
this is pricer factory and a base pricer that implements pretty much all that current pricer does, but allows for nice overrides of core behaviours. the factory though, it tries to instantiate a 'valid' pricer - pricer is really a handler (with business) for dummy price. factory is a bit smarter than usual, as it implements some business logic a…
module Pricing::Pricers
class PricerFactory
def self.pricer_for(property, check_in_on, check_out_on, request_live_price: request_live_price?)
pricer_class = begin
"Pricing::Pricers::#{property.source.gsub(/\s+/,'')}Pricer".constantize
rescue NameError
Pricing::Pricers::BasePricer
@maciekr
maciekr / property_decorator.rb
Created June 29, 2015 15:57
check out pricer method. it's fairly anemic now, no business there, all pushed down to brand specific pricers.
class PropertyDecorator < Draper::Decorator
delegate_all
decorates_association :reviews
def summary
collection = [] #'breadcrumbs will go here? see properties/show.html.haml'
('<span>' + name + '</span>' + collection.join(', ')).html_safe
end
def summary_plain
@maciekr
maciekr / property_decorator.rb
Created June 29, 2015 15:56
check pricer method - no business logic in here, just delegating to pricer (which is de facto handler for price)
class PropertyDecorator < Draper::Decorator
delegate_all
decorates_association :reviews
def summary
collection = [] #'breadcrumbs will go here? see properties/show.html.haml'
('<span>' + name + '</span>' + collection.join(', ')).html_safe
end
def summary_plain
@maciekr
maciekr / NearestLinePointFromStandalonePoint.java
Created February 20, 2014 14:44
nearest line point rfrom a standalon point
package com.adleritech.searchplay;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineSegment;
import com.vividsolutions.jts.linearref.LinearLocation;
import com.vividsolutions.jts.linearref.LocationIndexedLine;
public class NearestLinePointFromStandalonePoint {
@maciekr
maciekr / RabbitHAClient.java
Created November 23, 2013 17:31
amqp connection recovery
package com.adleritech.aitcommons.rabbit;
import com.rabbitmq.client.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
@maciekr
maciekr / pom.xml
Created June 28, 2013 13:02
added version.txt task
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.adleritech.billing</groupId>
<artifactId>billing-platform</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Billing Platform</name>