Skip to content

Instantly share code, notes, and snippets.

View nukturnal's full-sized avatar

Alfred Rowe nukturnal

View GitHub Profile
@nukturnal
nukturnal / my_api.rb
Created October 19, 2015 15:18 — forked from doitian/my_api.rb
Allow cors from any domain
class MyAPI < Grape::API
class CrossOriginResourceSharingPolicy < Grape::Middleware::Base
def append_cors_headers(headers)
headers['Access-Control-Allow-Origin'] = env['HTTP_ORIGIN'] || '*'
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Max-Age'] = '180'
if env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
headers['Access-Control-Allow-Headers'] = env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
end
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
@nukturnal
nukturnal / report.rb
Created December 31, 2018 06:36 — forked from bgreenlee/report.rb
Displays a mysql-style report for an array of ActiveRecord objects. Stick it in your .irbrc.
# mysql-style output for an array of ActiveRecord objects
#
# Usage:
# report(records) # displays report with all fields
# report(records, :field1, :field2, ...) # displays report with given fields
#
# Example:
# >> report(records, :id, :amount, :created_at)
# +------+-----------+--------------------------------+
# | id | amount | created_at |
@nukturnal
nukturnal / capybara cheat sheet
Created October 18, 2019 19:06 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@nukturnal
nukturnal / rails-4.0.0_upgrade_notes.md
Created November 11, 2020 01:43
Rails 4.0.0 Upgrade Notes
  • Requirements
    • Must be on Ruby 1.9.3 or higher.
  • Upgrade Tools
    • Run rake rails:update as quick way to upgrade in place. Check your Git diff afterwards.
    • Use RailsDiff to compare changes between your version of Rails and Rails 4.0.0.
  • Upgrade Tips
    • I found it easiest to create a new Rails skeleton app and use it as my index when toggling between the Rails 4.0.0 skeleton and the older Rails 3.x.x app. You can then use Git to compare and adjust differences for each file copied and pasted.
    • When using the above technique, the following files are worth simply copying and pasting and then using Git to compare differences for anything you might not want to loose:

/config/environments/*.rb