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
| module RequestHelper | |
| def json_response | |
| JSON.parse(response.body, symbolize_names: true) | |
| end | |
| end | |
| class ActionDispatch::IntegrationTest | |
| include RequestHelper | |
| end |
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
| #config/initializers/redis.rb | |
| require 'redis' | |
| require 'redis/objects' | |
| REDIS_CONFIG = YAML.load( File.open( Rails.root.join("config/redis.yml") ) ).symbolize_keys | |
| dflt = REDIS_CONFIG[:default].symbolize_keys | |
| cnfg = dflt.merge(REDIS_CONFIG[Rails.env.to_sym].symbolize_keys) if REDIS_CONFIG[Rails.env.to_sym] | |
| $redis = Redis.new(cnfg) | |
| Redis::Objects.redis = $redis |
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
| require 'curb' | |
| require "json" | |
| require "base64" | |
| require "net/http" | |
| require "uri" | |
| CUID = "8132533"; | |
| CLIENT_ID = "your_client_id"; | |
| CLIENT_SECRET = "your_client_secret"; |
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 self.dedupe | |
| # find all models and group them on keys which should be common | |
| grouped = all.group_by{|model| [model.title,model.info,model.address,model.phone] } | |
| grouped.values.each do |duplicates| | |
| # the first one we want to keep right? | |
| first_one = duplicates.shift # or pop for last one | |
| # if there are any more left, they are duplicates | |
| # so delete all of them | |
| duplicates.each{|double| double.destroy} # duplicates can now be destroyed | |
| end |
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
| # lib/custom_logger.rb | |
| class CustomLogger < Logger | |
| def format_message(severity, timestamp, progname, msg) | |
| "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n" | |
| end | |
| end | |
| logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file | |
| logfile.sync = true # automatically flushes data to file | |
| CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere |
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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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
| Rails 4 - Respond only to JSON and not HTML | |
| I believe there are 2 parts here: | |
| 1) json only requests in rails | |
| 2) json only responses in rails | |
| 1) Configure your application controller to ensure json requests only | |
| # app/controller/application_controller.rb | |
| before_action :ensure_json_request |
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
| require_relative 'boot' | |
| require 'csv' | |
| require 'rails/all' | |
| # Require the gems listed in Gemfile, including any gems | |
| # you've limited to :test, :development, or :production. | |
| Bundler.require(*Rails.groups) | |
| module Giant | |
| class Application < Rails::Application |
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
| Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository | |
| deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main | |
| wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \ | |
| sudo apt-key add - | |
| sudo apt-get update | |
| sudo apt-get install postgresql-9.6 postgresql-server-dev-9.6 postgresql-contrib-9.6 -y | |
| sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'" |
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
| You can specify an explicit logger in your config; | |
| my_logger = ActiveSupport::BufferedLogger.new(path) | |
| config.logger = my_logger | |
| This will replace Rails.logger | |