Skip to content

Instantly share code, notes, and snippets.

View amitpatelx's full-sized avatar

Amit Patel amitpatelx

View GitHub Profile
@amitpatelx
amitpatelx / upload_to_s3.rb
Last active August 23, 2017 09:12
Upload a file to Amazon S3
# assumption
# Following Environment variables are already set
# AWS_SECRET_ACCESS_KEY, AWS_REGION
# Alternative way is mentioned https://github.com/aws/aws-sdk-ruby#configuration-options
file_name = 'sample.xml'
upload_file = '/path/to/sample.xml'
# Create an instance of the Aws::S3::Resource class
s3 = Aws::S3::Resource.new
@amitpatelx
amitpatelx / Gemfile
Created August 19, 2017 14:26
Add VCR to Gemfile
group :test do
gem 'vcr'
gem 'webmock'
end
# place this in rspec/support directory
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = Rails.root.join('spec', 'vcr_cassettes')
c.allow_http_connections_when_no_cassette = true
c.hook_into :webmock
c.default_cassette_options = { :record => :once }
end
@amitpatelx
amitpatelx / application_controller.rb
Created June 11, 2017 11:50
Move sorting and pagination logic at common place
def paginated(resources, per_page=Settings.pagination.default)
resources.page(params[:page]).per(per_page)
end
def sort_by_options(resources)
resources.order("#{sort_column(resources.first.class)} #{sort_direction}")
end
def sort_and_paginate(resources)
paginated(sort_by_options(resources))
module CMS
class Base
HTTP_ERRORS = [Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError]
attr_reader :cms
def initialize(cms)
@cms = cms
end
@amitpatelx
amitpatelx / README.md
Last active September 23, 2018 20:30
Development and Deployment Processes

This page outlines about practices we are following related to development and deployment

Branches

  1. Unless mentioned in issue or verbally, create all branches from develop branch.
  2. Pull latest changes from the parent branch before creating a branch from it.
  3. Branch name should be self-explanatory about the issue you are working on(Trello Card). It is highly discouraged to use an abbreviation, issue number etc in branch names.
  4. Avoid creating nested branches from working branches. Do proper planning before start coding.

Naming the branch

  1. All enhacements and feature branches should start with feature/ eg. feature/google-oauth-integration which will be created from develop only.
@amitpatelx
amitpatelx / posts.json
Created January 20, 2017 08:55
Mocking create Posts using MounteBank server
{
"port": 9999,
"protocol": "http",
"stubs": [
{
"responses": [
{
"is": {
"statusCode": 200,
"body": "{\n \"id\": \"3\"\n}"
@amitpatelx
amitpatelx / post.json
Created January 20, 2017 08:44
Mocking get single Posts using MounteBank server
{
"port": 9999,
"protocol": "http",
"stubs": [
{
"responses": [
{
"is": {
"statusCode": 200,
"body": "{\"id\":\"1\",\"title\":\"Awsome Article on MounteBank\",\"content\":\"I am about to write it...keep eyes on it\"}"
@amitpatelx
amitpatelx / posts.json
Created January 20, 2017 08:22
Mocking Get All Posts using MounteBank server
{
"port": 9999,
"protocol": "http",
"stubs": [
{
"responses": [
{
"is": {
"statusCode": 200,
"body": "[{\"id\":\"1\",\"title\":\"Awsome Article on MounteBank\",\"content\":\"I am about to write it...keep eyes on it\"},{\"id\":\"2\",\"title\":\"Aaha MounteBank\",\"content\":\"Hope you enjoyed the first part\"}]"
@amitpatelx
amitpatelx / routes.rb
Created August 31, 2016 10:23
Configure Sidekiq web interface
require 'sidekiq/web'
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
username == ENV["SIDEKIQ_USERNAME"] && password == ENV["SIDEKIQ_PASSWORD"]
end if Rails.env.production?
mount Sidekiq::Web => '/sidekiq'