This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Recursively diff two hashes, showing only the differing values. | |
| # By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license. | |
| # | |
| # Example: | |
| # | |
| # a = { | |
| # "same" => "same", | |
| # "diff" => "a", | |
| # "only a" => "a", | |
| # "nest" => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def flatten_hash(hash, results = {}, parent_key = '') | |
| return results unless hash.kind_of?(Hash) | |
| hash.keys.each do |key| | |
| # current_key = "#{parent_key}[#{key}]" # uncomment this if you want to keep parent key as a partof key for flattened hash (csv column name) | |
| current_key = key | |
| if hash[key].kind_of?(Hash) | |
| results = flatten_hash(hash[key], results, current_key) | |
| else | |
| if hash[key].kind_of?(Array) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query | |
| http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails | |
| #payload: [{"kind"=>"person"}] | |
| Segment.where("payload @> ?", [{kind: "person"}].to_json) | |
| #data: {"interest"=>["music", "movies", "programming"]} | |
| Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json) | |
| Segment.where("data #>> '{interest, 1}' = 'movies' ") | |
| Segment.where("jsonb_array_length(data->'interest') > 1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| With the size: attribute in your configure_* blocks removed = | |
| ERROR: heartbeat: ERR max number of clients reached | |
| app[worker.1]: 3 TID-ormcs1tts ERROR: ERR max number of clients reached | |
| with the size attribute = " Sidekiq seems to run normally but mailers not moving from in enqueued. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/assets/javascripts/welcome.js.coffee | |
| $ -> | |
| $(document).on 'change', '#countries_select', (evt) -> | |
| $.ajax 'update_cities', | |
| type: 'GET' | |
| dataType: 'script' | |
| data: { | |
| country_id: $("#countries_select option:selected").val() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web: bundle exec puma -C config/puma.rb -p $PORT | |
| worker: bundle exec sidekiq -e $RAILS_ENV -q default -q mailers | |
| # By default, sidekiq only operates on the `default` queue | |
| # So if you do `Mailer.new(...).deliver_later`, those are queued to the `mailers` queue | |
| # Hence you need to explicitly tell Sidekiq to operate on `mailers` queue too | |
| # You can also put this into sidekiq.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Rails console script that can be run on AWS Elastic Beanstalk. | |
| # | |
| # Run this script from the app dir (/var/app/current) as root (sudo script/rails-console) | |
| # | |
| set -xe | |
| EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SSL self signed localhost for rails start to finish, no red warnings. | |
| # 1) Create your private key (any password will do, we remove it below) | |
| $ openssl genrsa -des3 -out server.orig.key 2048 | |
| # 2) Remove the password | |
| $ openssl rsa -in server.orig.key -out server.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To enable SSL in Rails you could now simply use *force_ssl* in your | |
| # ApplicationController but there is two more things to think about: | |
| # In development our SSL webserver is running on port 3001 so we would | |
| # actually need to use *force_ssl port: 3001* but then this wouldn't | |
| # work for production. | |
| # Also there is a good chance you might not always want to use SSL in development | |
| # so it would be nice if we could just enable or disable SSL in the config. | |
| # To make all this work first copy the file *ssl_with_configured_port.rb* to | |
| # your *lib* directory. Second to enable SSL add *config.use_ssl = true* |