Skip to content

Instantly share code, notes, and snippets.

View amitpatelx's full-sized avatar

Amit Patel amitpatelx

View GitHub Profile
@amitpatelx
amitpatelx / secrets.yml
Created March 23, 2016 11:31
Set same secret base in secrets.yml
# secret_key_base must be same for both applications
development:
secret_key_base: c85ef952bfeb14117a3d55c249fa5e582e5c6327fa56f227e6dbb88b4be780ba2aef9e20f58c3f65e0faf282a49a802aefa29d2aae3e36d1a4ffc7e625a644d5
test:
secret_key_base: 29f526a44fdd6f5596da9cb46ee4823da7ffaf9893a7c8e34f126dd9865bdaf0d65cb04381faf7d56544a86e688d1aa7704ceb23a65560585cca266946b877c2
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@amitpatelx
amitpatelx / application.rb
Created March 23, 2016 11:32
Use shared memcached client to share sessions
# Use a different cache store in production.
# Configure this in both applications
elasticache = Dalli::ElastiCache.new('amit.patel.cfg.usw2.cache.amazonaws.com:11211')
config.cache_store = :dalli_store, elasticache.servers
@amitpatelx
amitpatelx / index.html
Last active March 23, 2016 11:43
Sample html with iframe sharing domain
<!-- Accessed via http://first.example.com -->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<iframe src="//second.example.com/path/to/resource" width="100%" height="100%"></iframe>
</body>
</html>
@amitpatelx
amitpatelx / thingstolearn.md
Created April 7, 2016 08:50
List of technologies/tools/framework I am planning to learn

Things To Learn

Computer Languages & Code

  • ReactJS
  • jQuery
  • Volt Framework

General

  • Docker
@amitpatelx
amitpatelx / post.json
Created April 29, 2016 09:36
Wordpress getPost response
{
"post_id": "11468",
"post_title": "Post with short sommary",
"post_date": {
"year": 2016,
"month": 4,
"day": 29,
"hour": 9,
"min": 20,
"sec": 12
@amitpatelx
amitpatelx / hash_to_yaml.rb
Last active May 3, 2016 09:17
Hash to YAML - Used to convert hash to YAML and save in a fixture file.
#asumpution - Hash contains all keys as symbols
hash = {:post_id=>"11468",
:post_title=>"Post with short sommary",
:post_date=>{:year=>2016, :month=>4, :day=>29, :hour=>9, :min=>20, :sec=>12}}
#1. deep_stringify_keys! - Destructively convert all keys to strings. This includes the keys from the root hash and from all nested hashes and arrays.
hash.deep_stringify_keys!
#2. Write to file
file = 'path/to/output/file.txt'
@amitpatelx
amitpatelx / application_controller.rb
Created May 5, 2016 13:04
Common Pagination inside ApplicationController - With Kaminari
def paginated(resources, per_page = 10)
resources.page(params[:page]).per(per_paget)
end
@amitpatelx
amitpatelx / mysql.yml
Created May 16, 2016 08:38
database.yml
development:
adapter: mysql2
encoding: utf8
pool: 10
min_messages: warning
timeout: 5000
database: myapp_development
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
@amitpatelx
amitpatelx / create_content_units.rb
Created May 23, 2016 08:01
Override default primary key
class CreateContentUnits < ActiveRecord::Migration
def change
create_table :content_units, primary_key: :guoid do |t|
t.boolean :active, default: false
end
end
end
CREATE TABLE `content_units` (
`guoid` int(11) NOT NULL AUTO_INCREMENT,
`active` tinyint(1) DEFAULT '0',
PRIMARY KEY (`guoid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;