Skip to content

Instantly share code, notes, and snippets.

View shivabhusal's full-sized avatar

Shiva Bhusal shivabhusal

View GitHub Profile
@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 ['deployer@XX.79.200.XXX'] 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
@shivabhusal
shivabhusal / unmanaged-index.jsx
Created January 14, 2017 20:45
This looks like mess. Its so difficult to maintain any software with this kind of scattered components. It is always a better idea to sperate out logical things into well defined directory structure. We will do this in a moment. Checkout the next Pull request
import {combineReducers, createStore} from 'redux';
const usersReducer = (usersState = [], action) => {
const new_state = Object.assign([], usersState);
switch (action.type) {
case 'UPDATE_USER': {
var updateable_record = new_state.find((item) => item.id === action.payload.id);
new_state[new_state.indexOf(updateable_record)] = Object.assign({}, updateable_record, action.payload);
break;
}