Skip to content

Instantly share code, notes, and snippets.

<%= 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 %>
@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
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 / 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
@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
# n, can be the number of times you want to execute this command.
# In my case tag were like below
# release-1.4.0
# release-1.4.1
# release-1.4.10
# release-1.4.11
# release-1.4.2
# release-1.4.3
# release-1.4.4
# release-1.4.5
@abhinaykumar
abhinaykumar / break.py
Created September 25, 2018 06:55 — forked from obfusk/break.py
python equivalent of ruby's binding.pry
import code; code.interact(local=dict(globals(), **locals()))
@abhinaykumar
abhinaykumar / gist:4762e168d5f78fbb46edeec61a4abe65
Created March 12, 2020 08:55 — forked from guisehn/gist:6648c8fdcd1102a22a22
Backup Heroku Postgres database and restore to local database

Grab new backup

Command: heroku pg:backups capture -a [app_name]

Download

Command: curl -o latest.dump `heroku pg:backups public-url -a [app_name]`

Restore backup dump into local db

@abhinaykumar
abhinaykumar / Deploy monorepo to Heroku
Created November 10, 2020 13:59
Deploy monorepo to Heroku
1. Create Procfile at the root of each frontend and backend folder (with command to start the server)
2. Create Heroku dynos for each (frontend and backend)
```
heroku create -a my-awesome-frontend
heroku create -a my-awesome-backend
```
3. Get the auth token from Heroku by running: `heroku auth:token` #=> HEROKU_API_TOKEN
4. Add remote origin for frontend and backend
```
@abhinaykumar
abhinaykumar / Graphql subscription with ActionCable
Last active May 31, 2021 05:11
Setup Graphql subscription with ActionCable Rails
{ Ref: https://evilmartians.com/chronicles/graphql-on-rails-3-on-the-way-to-perfection }
(Rails - 5, Graphql-ruby - 1.8.x)
# Gemfile
gem 'redis'