Skip to content

Instantly share code, notes, and snippets.

View kitwalker12's full-sized avatar

Kunwar Aditya Raghuwanshi kitwalker12

View GitHub Profile
@kitwalker12
kitwalker12 / app-init.js
Created August 15, 2013 01:14
Clean way of making jQuery Initializers
// handle window.console if console.log isn't available. Define an empty function here
function emptyFunction() { }
if (window.console === undefined) {
window.console = {
log: emptyFunction,
error: emptyFunction,
info: emptyFunction,
trace: emptyFunction
};
}
@kitwalker12
kitwalker12 / application_controller.rb
Created August 15, 2013 19:16
Custom 404 & 500 Error Pages
class ApplicationController < ActionController::Base
#...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end
#...
@kitwalker12
kitwalker12 / my_feature_spec.rb
Created August 15, 2013 21:20
Rspec & VCR to mock API calls
require 'spec_helper'
feature "My Feature: " do
context "User Registers" do
scenario "through api" do
VCR.use_cassette "register_new_user", :record => :new_episodes do
#make api call
end
end
end
@kitwalker12
kitwalker12 / PUT Request
Created August 22, 2013 17:57
Braintree add Payment through Spree API.
PUT http://<spree-domain>/api/checkouts/<order_number>?order[payments_attributes][][payment_method_id]=<braintree_payment_id_spree>&order[payments_attributes][][amount]=<amount>&order[payments_attributes][][source_attributes][gateway_payment_profile_id]=<braintree_customer_id>&order[payments_attributes][][source_attributes][gateway_customer_profile_id]=<braintree_payment_id>&order[payments_attributes][][source_attributes][year]=<year>&order[payments_attributes][][source_attributes][month]=<month>
@kitwalker12
kitwalker12 / routes.rb
Last active December 21, 2015 15:28
Sitemap Generation in Rails
#...
match 'sitemap.xml' => 'sitemap#sitemap'
#...
<style>
.video-container {
position: relative;
padding-bottom: 50%;
padding-top: 30px; height: 0; overflow: hidden;
}
.video-container iframe,
.video-container object,
.video-container embed {
@kitwalker12
kitwalker12 / post.rb
Created October 30, 2013 00:51
Active Admin Customizations
ActiveAdmin.register Post do
index do
selectable_column
column :name do |post|
link_to post.name, admin_post_path(post)
end
column :author
#...
end
end
@kitwalker12
kitwalker12 / cookies.js
Created November 13, 2013 01:59
Set cookies based on referral links
// init namespace
window.app = {};
window.app.custom = {};
(function ($, app) {
var $window = $(window);
app.captureCampaign = {
parameters: ['campaign_source'],
cookiePersistDays: 30,
# Capybara
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
@kitwalker12
kitwalker12 / check_string.rb
Last active August 29, 2015 13:56
check if string is float and/or whole number
def is_number?(str)
true if Float(str) rescue false
end
def prettify(str)
str = str.to_f
str.to_i == str ? str.to_i : str
end