Skip to content

Instantly share code, notes, and snippets.

@abhinaykumar
abhinaykumar / rails http status codes
Created April 27, 2018 04:50 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@abhinaykumar
abhinaykumar / total_price.rb
Created September 29, 2016 18:32
This program is the part of a coding challenge where we need to calculate the total price of a Model of a car based on their policy and base price.
# Calculate the Total Price of a Model of Car based on the policy(which will
# decide margin) and based price provided by User. Every policy has a condition
# to calculate the margin which will then gets added to base price to get the
# total price of the car.
class Models
require 'open-uri'
require 'nokogiri'
def self.calculate_total_price(pricing_policy, base_price)
case pricing_policy
require 'oauth2'
require 'legato'

client = OAuth2::Client.new('client-ID', 'client-secret', {
  :authorize_url => 'https://accounts.google.com/o/oauth2/auth',
  :token_url => 'https://accounts.google.com/o/oauth2/token'
})

client.auth_code.authorize_url({
@abhinaykumar
abhinaykumar / add_comma_to_phone_numbers_string.rb
Last active March 12, 2016 06:56
challenge is to add ',' at the end of every number which is not pin-code. Pincodes are the number lesser or equal to 5.
# challenge is to add ',' at the end of every number which is not pin-code. Pincodes are the number lesser or equal to 5.
# Also, make sure they all are one space apart.
# ex: "123 23424324 34534 2342442234"
# function should return: "123 23424324, 34534 2342442234,"
#
a = "1234 23434242 232342442 345 2342341234"
a.scan(/[\w']+/) do |w|
if w.length > 5
b << "#{w},"
next
<%= f.collection_radio_buttons(:role, User::ROLES, :to_s, lambda{|i| i.to_s.humanize}) do |b| %>
<% b.label do %>
<%= b.radio_button %><%= if b.value == 'vendor' then 'Professional' else b.text end %>
<% end %>
<% end %>