Skip to content

Instantly share code, notes, and snippets.

@Rosa-Fox
Rosa-Fox / tip.rb
Created September 18, 2015 21:47
Bill Calculator - OOP approach
class Tip
attr_reader :tip
def initialize(bill, tip)
@bill = bill
@tip = tip
end
def get_amount
@bill_amount = @bill.to_i
if @bill_amount == 0
@Rosa-Fox
Rosa-Fox / tip_user_input.rb
Created September 18, 2015 21:40
Script to print total cost of a bill with tip included. This is based on user input to the terminal.
puts "How much does the bill come to?"
bill_amount = gets.chomp.to_i
while bill_amount == 0
puts "Please enter a valid number for the bill amount:"
bill_amount = gets.chomp.to_i
end
while bill_amount < 0
puts "Please enter a positive number:"
puts bill_amount = gets.chomp.to_i
end
Elasticsearch::Transport::Transport::Errors::BadRequest at /categories/defend-market-share
[400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[oCuMYEy9Rs2FBhw6lBqTUA][contagiousfeed_development_feed_articles][0]: SearchParseException[[contagiousfeed_development_feed_articles][0]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"filter\":{\"and\":[{\"term\":{\"published\":true}},{\"terms\":{\"categories\":[\"defend-market-share\"]}}]},\"query\":{\"function_score\":{\"functions\":[{\"script_score\":{\"script\":\"(0.25/ ((3.16*pow(10,-11)) * abs(DateTime.now().getMillis() - doc['published_at'].date.getMillis()) + 0.05)) + _score\"}}],\"query\":{\"query_string\":{\"query\":\"Defend market share\",\"default_operator\":\"and\"}}}},\"sort\":[{\"published_at\":\"desc\"}],\"aggs\":{\"all_categories\":{\"filter\":{\"and\":[{\"term\":{\"published\":true}}]},\"aggs\":{\"categories\":{\"terms\":{\"field\":\"categories\",\"size\
@Rosa-Fox
Rosa-Fox / gist:e45fe41083fb7bbe760b
Created June 10, 2015 16:42
Error elastic search
Elasticsearch::Transport::Transport::Errors::BadRequest at /categories/defend-market-share
[400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[iPIrRP8XRjKSCa9MqWJSDw][contagiousfeed_development_feed_articles][0]: SearchParseException[[contagiousfeed_development_feed_articles][0]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"filter\":{\"and\":[{\"term\":{\"published\":true}},{\"terms\":{\"categories\":[\"defend-market-share\"]}}]},\"query\":{\"function_score\":{\"functions\":[{\"script_score\":{\"script\":\"(0.25/ ((3.16*pow(10,-11)) * abs(DateTime.now().getMillis() - doc['published_at'].date.getMillis()) + 0.05)) + _score\"}}],\"query\":{\"query_string\":{\"query\":\"Defend market share\",\"default_operator\":\"and\"}}}},\"sort\":[{\"published_at\":\"desc\"}],\"aggs\":{\"all_categories\":{\"filter\":{\"and\":[{\"term\":{\"published\":true}}]},\"aggs\":{\"categories\":{\"terms\":{\"field\":\"categories\",\"size\
@Rosa-Fox
Rosa-Fox / gist:618d7fc11356fda290a9
Created June 5, 2015 15:12
show.erb the second
<div class="todo">
<div class="panel panel-default">
<div class="container">
<div class="panel-body">
<h2><%= @todo.id %>: <%= @todo.title %></h2>
<h4>More Info: <%= @todo.description %></h4>
<div class="row">
<div class ="col-md-1">
<a href="/todo" class="btn btn-default">Back</a>
<a href="/todo/<%= @todo.id %>/edit" class="btn btn-info">Edit</a>
@Rosa-Fox
Rosa-Fox / gist:25f48f1afceed5ac701c
Created June 5, 2015 15:12
server.rb the second
require 'sinatra'
require 'data_mapper'
load 'datamapper_setup.rb'
class Todo
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :title, String
property :description,String
<div class="todo">
<div class="panel panel-default">
<div class="container">
<div class="panel-body">
<h2><%= @todo.id %>: <%= @todo.title %></h2>
<h4>More Info: <%= @todo.description %></h4>
<div class="row">
<div class ="col-md-1">
<a href="/todo" class="btn btn-default">Back</a>
<a href="/todo/<%= @todo.id %>/edit" class="btn btn-info">Edit</a>
require 'sinatra'
require 'data_mapper'
load 'datamapper_setup.rb'
class Todo
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :title, String
property :description,String
%nav.navbar.navbar-default
.container-fluid
.navbar-header
%span.navbar-brand
=link_to 'Users', admin_users_path
|
=link_to 'Invitations', admin_invitations_path
.collapse.navbar-collapse
.navbar-right
= link_to 'Log out', admin_session_path, method: 'delete', class: 'btn btn-sm btn-default navbar-btn'
describe '#redeem_by(user)' do
let(:access_contain_user_and_workshop_id) { Access.exists?(user_id: n, workshop_id: ["http-fundamentals", "rails-security"]) }
before do
@invitation = Factory.create(:invitation)
@user = Factory.create(:user)
@invitation.redeem_by(@user)
end