Skip to content

Instantly share code, notes, and snippets.

View shivabhusal's full-sized avatar

Shiva Bhusal shivabhusal

View GitHub Profile
@shivabhusal
shivabhusal / git_branch
Last active July 26, 2020 00:51
Add this snippet in Linux (Ubuntu)'s `~/.bashrc` to see your current git-branch in terminal prompt
# Author : Shiva Bhusal
# github: shivabhusal
# stackoverflow: users/3437900/illusionist
##########################################
# Usages:
# - create a file called ~/.promptrc
# - add following in ~/.bashrc
# `source ~/.promptrc`
# # this will include the source of the file
@shivabhusal
shivabhusal / readme.md
Last active November 19, 2015 03:01
A OpenSource Object Oriented Ruby Library to implement SingleSign On into FreshDesk. This basically gets you the redirection_url you require to implement singlesignon

How to use it

It is very easy to use this library. Just use the get_redirection_url method

def help_desk_url
    options = {
        username: user_name,
        email: email,
        role: role
    }
 SsoService.init(options).get_redirection_url
@shivabhusal
shivabhusal / base.rb
Last active December 8, 2015 08:20
SendGrid integration; Transactional EMail template via Ruby : Send data to tr-email
# /email/base.rb
class Email::Base
# This class is mostly responsible for Sending email via SendGrid or Other Provier in future
# Code in here are Common to all its successors
RootURL = 'http://dashboard.thepact.com'
VarPrefix = '{{'
VarSuffix = '}}'
attr_reader :client, :from, :template, :subject, :recipients
@shivabhusal
shivabhusal / rspec_routes_examples.md
Last active December 15, 2015 03:53
Clear and Good routing examples to teach how we can test routing specs/tests with RSpec

Newbie developers might wonder how they can test if their routes are in good conditions. They might not find good examples so I have pasted some examples from my code.

require 'rails_helper'

describe 'Routes Spec', type: :routing do
  describe 'Admin Section' do
    describe 'Articles Controller' do
      it "should route 'admin/articles/category', :to => 'articles#add_category'" do
        expect(post: 'admin/articles/category').to route_to('admin/articles#add_category')
      end
@shivabhusal
shivabhusal / signup.rb
Created January 29, 2016 05:37
Auto signup rake task
class SignUpHandler
def process
stripe_token = get_stripe_card_token
token = stripe_token.id
puts "Stripe Token Generated for card #{'*'*12}#{stripe_token.card.last4}"
response = get_sign_up_form
@shivabhusal
shivabhusal / upload_file_using_SSHKit.rb
Created February 8, 2016 06:03
Using capistrano's SSHKit library you can move file from local to server from your Rails console or IRB
require 'sshkit'
require 'sshkit/dsl'
on ['[email protected]'] do
# upload! '/home/john/Downloads/__thepact_com/__thepact_com.crt', '/home/deployer/__thepact_com.crt'
# upload! '/home/john/Downloads/__thepact_com/__thepact_com.p7b', '/home/deployer/__thepact_com.p7b'
upload! '/home/john/Downloads/__thepact_com/__thepact_com.ca-bundle', '/home/deployer/__thepact_com.ca-bundle'
within '/home/deployer/' do
@shivabhusal
shivabhusal / wait_for_ajax.rb
Created February 14, 2016 04:13 — forked from anonymous/wait_for_ajax.rb
When there is ongoing Ajax Request during Capybara test session. You can make capybara wait till all the Ajax Requests finish first. - This Code chunk is actually provided by ThoughtBot - https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# spec/support/wait_for_ajax.rb
# There is inbuild `wait_for_ajax` method in selinium WebDriver library
# This is for Capybara Webkit only
# #
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until finished_all_ajax_requests?
end
end
@shivabhusal
shivabhusal / wait_for_ajax.rb
Created February 18, 2016 03:39
New updated Waitofrajax
# spec/support/wait_for_ajax.rb
# There is inbuild `wait_for_ajax` method in selinium WebDriver library
# This is for Capybara Webkit only
# #
module WaitForAjax
def wait_for_ajax(timeout = Capybara.default_wait_time)
Timeout.timeout(timeout) do
active = page.evaluate_script('jQuery.active')
until active == 0
active = page.evaluate_script('jQuery.active')
@shivabhusal
shivabhusal / spree_sample_order_and_line_items.rb
Last active March 18, 2016 09:17
Spree Sample orders for developers working with spree
Sample Order
<Spree::Order:0x007fa6d37b52d8
id: 6,
number: "R141192317",
item_total: #<BigDecimal:7fa6d3d37d28,'0.1999E2',18(27)>,
total: #<BigDecimal:7fa6d39816c0,'0.2599E2',18(27)>,
state: "complete",
adjustment_total: #<BigDecimal:7fa6d3d37b48,'0.1E1',9(18)>,
user_id: 4,
completed_at: Thu, 10 Mar 2016 03:24:55 UTC +00:00,
GIT
remote: git://github.com/spree-contrib/spree_mail_settings.git
revision: d416a1e355893bda625ed5bea187d39526aa52f9
branch: 3-0-stable
specs:
spree_mail_settings (3.0.0)
spree_backend (~> 3.0.0)
GIT
remote: git://github.com/spree/spree_auth_devise.git