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 / Dockerfile
Created August 6, 2019 06:38
Dockerfile that install package manually from .deb file
FROM ruby:2.6.1
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash \
&& apt-get update && apt-get install -y nodejs xvfb libfontconfig wkhtmltopdf && rm -rf /var/lib/apt/lists/* \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*
# Packages for wkhtmltopdf. These are available in ubuntu but not in debian 9. Base image uses debian 9.
RUN wget -q -O /tmp/libjpeg-turbo8.deb http://archive.ubuntu.com/ubuntu/pool/main/libj/libjpeg-turbo/libjpeg-turbo8_2.0.1-0ubuntu2_amd64.deb \
&& dpkg -i /tmp/libjpeg-turbo8.deb \
@prsanjay
prsanjay / console_to_file.rb
Created June 30, 2019 08:07
Copy Rails Console output to the file
f = File.new("recome.txt", 'w')
f << Recommendation.last.primary_plan_cost
f.close
@prsanjay
prsanjay / paperclip.rb
Created June 30, 2019 07:20
Style configuration for taxon header image
module Spree
class TaxonHeaderImage < Asset
module Configuration
module Paperclip
extend ActiveSupport::Concern
included do
def self.styles
attachment_definitions[:attachment][:styles]
end
@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')
{
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
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
@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)
@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 / 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 / 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"