Skip to content

Instantly share code, notes, and snippets.

View benhawker's full-sized avatar

Ben Hawker benhawker

View GitHub Profile
@benhawker
benhawker / gist:017add3ae3daa94df433291cbfd28d33
Created February 28, 2018 15:27
Oyster another approach
require './lib/journey'
require './lib/journey_history'
class Oyster
MAX_BALANCE = 50
MIN_FARE = 1.7
attr_reader :balance, :customer_id, :journey_history
def initialize(balance: 0, customer_id:)
@benhawker
benhawker / Oyster
Created February 13, 2018 11:43
Oyster
```
In order to use public transport
As a customer
I want money on my card
In order to keep using public transport
As a customer
I want to add money to my card
In order to protect my money
@benhawker
benhawker / script.rb
Created December 5, 2017 16:01
Hacky script to take a look at some Honeybadger errors
require 'rubygems'
require 'colorize'
token = 'INSERT_YOUR_TOKEN_HERE'
total_notices_count, total_logged_in_count = 0, 0
project_id = 42287
require 'base64'
require 'httparty'
@benhawker
benhawker / friendly_urls.markdown
Created July 19, 2017 20:45 — forked from cdmwebs/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@benhawker
benhawker / README.md
Created July 19, 2017 09:01 — forked from lopezjurip/README.md
Ruby on Rails - Send (batch) emails using mailgun-ruby (HTTP, not SMTP)

Requisites:

  • Create a free account at https://www.mailgun.com/
  • Save your API Key as a environment variables: export MAILGUN_API_KEY=key-1111111111111111111111111

As example, I will use a model named Request.

@benhawker
benhawker / script.rb
Created June 7, 2017 16:36
Combining some xml files.
require 'nokogiri'
require 'pry'
# Layout - There remains an issue with the XML formatting Layout with i need to resolve.
files = %w(BookingPhrases CommonTerms ClientSide Validation)
# files = ["Layout"]
languages = %w(en-US it pt fr es de nl zh-CN)
files.each do |filename|
require 'csv'
require 'json'
file = 'data2.csv'
# TODO: Check file encoding - some destinations airports are missing a few chars.
file_contents = CSV.read(file, col_sep: ",", encoding: "ISO8859-1")
grouped_hash = file_contents[1..-1].group_by { |x| x[0] }
master_arr = []
id_iterator = 1
@benhawker
benhawker / codes.rb
Created May 4, 2017 14:20
Unique codes
def generate_coupon_code(user_id)
characters = %w(A B C D E F G H J K L M P Q R T W X Y Z 1 2 3 4 5 6 7 8 9)
code = ''
4.times { code << characters.sample }
code << user_id.to_s
code
end
@benhawker
benhawker / csv_to_json.rb
Created April 28, 2017 14:59
Takes a CSV and outputs a required format in json.
require 'csv'
require 'json'
file = 'data.csv'
# TODO: Check file encoding - some destinations airports are missing a few chars.
file_contents = CSV.read(file, col_sep: ",", encoding: "ISO8859-1")
grouped_hash = file_contents[1..-1].group_by { |x| x[0] }
master_arr = []
id_iterator = 1
@benhawker
benhawker / room_stats.rb
Last active August 12, 2016 08:23
Pulls values on views to inquiry to booking conversion into a CSV for analysis
require 'csv'
class RoomStats
VALUES = %w(num_views num_inquiries num_bookings
views_to_inquiry_conversion inquiry_to_booking_conversion
views_to_booking_conversion)
attr_reader :counts, :averages
def initialize