Skip to content

Instantly share code, notes, and snippets.

View cmthakur's full-sized avatar
🎯
Focusing

Chandra M. Thakur cmthakur

🎯
Focusing
View GitHub Profile
@cmthakur
cmthakur / main.tf
Created July 3, 2023 08:14 — forked from danihodovic/main.tf
Terraform - deployment using S3, Cloudfront and Route53
variable "aws_region" {
default = "eu-west-1"
}
variable "domain" {
default = "my_domain"
}
provider "aws" {
region = "${var.aws_region}"
@cmthakur
cmthakur / has_many_attached.rb
Last active October 16, 2019 10:42
activestorage
# Model
class Company < ApplicationRecord
has_many_attached :attachments
end
# Controller
def create
@company = Company.new(company_params)
attachments = params[:company][:attachments]
@cmthakur
cmthakur / Rakefile
Created February 21, 2018 05:19 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@cmthakur
cmthakur / solution.md
Created September 12, 2017 08:13 — forked from kendagriff/solution.md
Solution to "OpenSSL::X509::StoreError: setting default path failed: Invalid keystore format" for JRuby

Solution to StoreError: invalid keystore format (OS X)

The following error appeared upon upgrading JRuby:

OpenSSL::X509::StoreError: setting default path failed: Invalid keystore format

Download cacert.pem

def variables
variables = GC.stat.keys.map(&:to_s)
end
variables.each do |name|
instance_variable_set("@#{name.to_s.gsub(' ', '_')}", Array.new())
end
def get_recent_stats
@cmthakur
cmthakur / devise.rb
Last active March 5, 2017 05:20 — forked from jperry/remote_authenticatable.rb
Devise and warden remote authentication
Devise.setup do |config|
config.warden do |manager|
manager.strategies.add(:remote, Devise::Strategies::RemoteAuthenticatable)
manager.default_strategies(:scope => :user).unshift :remote
end
end
@cmthakur
cmthakur / repo synchronizer
Last active April 26, 2016 05:07
Repo synchronizer sync your all available repos under given directory with latest master
project_dir = "my_code_hub"
repos = Dir["#{project_dir}/*"]
success_pull = repos.map do |rep_path|
response = `cd #{rep_path}; git checkout master; git pull`;
print '=>'
rep_path.split('/').last if response.length > 0
end;
@cmthakur
cmthakur / README.md
Created November 3, 2015 14:40 — forked from oodavid/README.md
Backup MySQL to Amazon S3

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

@cmthakur
cmthakur / liquid_view.rb
Last active August 29, 2015 14:27 — forked from danshultz/liquid_view.rb
liquid/lib/extras/liquid_view.rb file to use in Rails 3 with layouts
# LiquidView is a action view extension class. You can register it with rails
# and use liquid as an template system for .liquid files
#
# Example
#
# ActionView::Base::register_template_handler :liquid, LiquidView
class LiquidView
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
_response url _request _cookies variables_added _flash params _headers request cookies
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
@cmthakur
cmthakur / digital_ocean_setup.md
Last active August 29, 2015 14:26 — 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