Skip to content

Instantly share code, notes, and snippets.

View prsanjay's full-sized avatar
🏠
Working from home

Sanjay Prajapati prsanjay

🏠
Working from home
View GitHub Profile
@prsanjay
prsanjay / registrations_controller.rb
Created March 7, 2016 13:32 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@prsanjay
prsanjay / digital_ocean_setup.md
Created March 12, 2016 09:01 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@prsanjay
prsanjay / web-fonts-asset-pipeline.md
Created June 14, 2016 12:40 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@prsanjay
prsanjay / ruby-signaturepad-to-image.rb
Created July 18, 2016 10:01 — forked from branch14/ruby-signaturepad-to-image.rb
convert json signatures captured by thomasjbradley's signature-pad to an image
# see https://github.com/thomasjbradley/signature-pad for more details
instructions = JSON.load(data).map { |h| "line #{h['mx']},#{h['my']} #{h['lx']},#{h['ly']}" } * ' '
system "convert -size 198x55 xc:transparent -stroke blue -draw '#{instructions}' signature.png"
@prsanjay
prsanjay / mina_setup.rb
Last active April 8, 2018 16:13
Mina Initial Setup
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'
set :repository, 'git@bitbucket.org:sanjayprajapati/your-app.git'
set :user, 'deploy'
set :deploy_to, '/home/deploy/your-app-name'
set :branch, 'develop'
set :domain, YOUR_SERVER_IP
@prsanjay
prsanjay / ahoy_visit.rb
Last active June 3, 2018 14:35
Event record created via Ahoy gem
2.5.1 :006 > Ahoy::Visit.first
Ahoy::Visit Load (1.1ms) SELECT "ahoy_visits".* FROM "ahoy_visits" ORDER BY "ahoy_visits"."id" DESC LIMIT $1 [["LIMIT", 1]]
=> #<Ahoy::Visit id: 1, visit_token: "d1dec227-ecd8-4052-bd45-ba7f5ac162b8", visitor_token: "76afdd83-5dc8-43a6-8dc8-21bf43ae247b",
user_id: nil, ip: "127.0.0.1", user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36...", referrer: nil,
referring_domain: nil, landing_page: "http://localhost:3000/", browser: "Chrome", os: "GNU/Linux", device_type: "Desktop",
country: nil, region: nil, city: nil, utm_source: nil, utm_medium: nil, utm_term: nil, utm_content: nil, utm_campaign: nil,
started_at: "2018-06-03 14:23:49">
@prsanjay
prsanjay / customize_ahoy.rb
Created June 3, 2018 16:19
Customize Ahoy tracking method
class Ahoy::Store < Ahoy::DatabaseStore
def track_visit(data)
data[:accept_language] = request.headers["Accept-Language"]
super(data)
end
def track_event(data)
data[:properties] = { key: 'value' }
super(data)
class ApplicationMailbox < ActionMailbox::Base
# Any of the recipients of the mail (whether to, cc, bcc) are matched against the regexp.
routing /^replies@/i => :replies
# Any of the recipients of the mail (whether to, cc, bcc) needs to be an exact match for the string.
routing "help@example.com" => :help
# Any inbound_email that has not been already matched will be sent to the BackstopMailbox.
routing :all => :backstop
end
class ApplicationMailbox < ActionMailbox::Base
routing ->(inbound_email) { with_sku?(inbound_email) } => :price_finder
def self.with_sku?(inbound_email)
inbound_email.mail.subject.include?('SKU') || inbound_email.mail.body.include?('SKU')
end
end
class PriceFinderMailbox < ApplicationMailbox
@prsanjay
prsanjay / taxon_header_image.rb
Created June 30, 2019 06:01
Add new attachment to taxons
module Spree
class TaxonHeaderImage < Asset
include Rails.application.config.use_paperclip ? Configuration::Paperclip : Configuration::ActiveStorage
include Rails.application.routes.url_helpers
def styles
self.class.styles.map do |_, size|
width, height = size[/(\d+)x(\d+)/].split('x')
{