Skip to content

Instantly share code, notes, and snippets.

@rahul100885
rahul100885 / ssl_puma.sh
Created October 23, 2018 12:20 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@rahul100885
rahul100885 / UserProfile.rb
Last active February 12, 2023 18:23
Simple json file upload in rails api
class UserProfile < ActiveRecord::Base
has_attached_file :picture,
styles: {
original: {geometry: '1000x0>'},
thumb: '100x100#',
large: '300x200>',
},
convert_options: {large: "-quality 80 -strip -interlace Plane"},
default_url: "http://s3-ap-southeast-1.amazonaws.com/#{ENV["S3_BUCKET"]}/user_profiles/placeholder.png",
path: (Rails.env == 'test' || Rails.env == 'development') ? ":rails_root/public/images/:class/:id/:style/:filename" : "/:class/:id/:style/:filename",
@rahul100885
rahul100885 / largest_table.sql
Created July 2, 2014 12:09
Find largest size table ( Disk usage )
SELECT relname, PG_SIZE_PRETTY(PG_TOTAL_RELATION_SIZE(relid)) FROM pg_stat_all_tables WHERE schemaname != 'pg_toast' AND relname LIKE 'pg_%' ORDER BY PG_TOTAL_RELATION_SIZE(relid) DESC;
@rahul100885
rahul100885 / s3_header.rb
Last active July 27, 2023 14:09
Ruby script to add Metadata ( Cache Control and Expires) header to existing S3 Objects
require 'rubygems'
require 'aws-sdk'
s3 = AWS::S3.new(
:access_key_id => 'XXXXXXXXXXXXXXX',
:secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
bucket = s3.buckets['your_bucket_name']
ten_year_in_seconds = 10 * 365 * 24 * 60 * 60
@rahul100885
rahul100885 / Email-header
Created May 7, 2014 17:36
Email header for gmail action button
Delivered-To: XXXX@mydomain.com
Received: by 10.229.25.199 with SMTP id a7csp15957qcc;
Wed, 7 May 2014 05:55:13 -0700 (PDT)
X-Received: by 10.182.241.67 with SMTP id wg3mr44908240obc.16.1399467313246;
Wed, 07 May 2014 05:55:13 -0700 (PDT)
Return-Path: <rahul100885@gmail.com>
Received: from mail-pd0-x22d.google.com (mail-pd0-x22d.google.com [2607:f8b0:400e:c02::22d])
by mx.google.com with ESMTPS id yb4si1843965pbb.403.2014.05.07.05.55.12
for <XXXX@mydomain.com>
(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
@rahul100885
rahul100885 / routes.rb
Created May 6, 2014 05:01
How to: override devise default routes of sign in and sign out
MyApp::Application.routes.draw do
# If you concern about SEO then send permanent redirect (301) on old routes to new routes
# It is always better to do this setting in web server that is in nginx or apache.
# Here I am showing how to do it in rails routes file
get '/users/sign_in', to: redirect("/sign-in")
get '/users/sign_up', to: redirect("/sign-up")
# Need to skip session and registration so that we can override them in devise_scope block
# If we not do so then default route of devise continue to work
devise_for :users, :skip => [:sessions, :registrations]
@rahul100885
rahul100885 / device_size.rb
Created October 13, 2013 18:48
Set browser screen size in rspec + capybara suite for responsive web design test.
# spec/support/device_size.rb
module DeviceSize
extend ScreenSize
RSpec.configure do |config|
config.before(:each) do
if example.metadata[:device_size].blank?
# set screen size default to :large
@rahul100885
rahul100885 / screen_size.rb
Created October 13, 2013 18:44
Set browser screen size in rspec + capybara suite for responsive web design test.
# spec/support/screen_size.rb
module ScreenSize
SCREENS = {
small: { width: 590 , height: 768 },
medium: { width: 1025, height: 768 },
large: { width: 1280, height: 768 }
}
@rahul100885
rahul100885 / transaction_isolation_level.html
Created September 22, 2012 07:39
transaction isolation level
If your database supports setting the isolation level for a transaction,
you can set it like so:
Post.transaction(isolation: :serializable) do
# ...
end
Valid isolation levels are:
* `:read_uncommitted`
railsadmin@prodApp:~/application/production/my_app$ sudo bundle install
[sudo] password for lvadmin:
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb:49:in `initialize': not in gzip format (Zlib::GzipFile::Error)
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb:49:in `new'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb:49:in `initialize'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader.rb:64:in `each'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader.rb:55:in `loop'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader.rb:55:in `each'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb:32:in `initialize'
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rub