Skip to content

Instantly share code, notes, and snippets.

Avatar

Alfred Rowe nukturnal

View GitHub Profile
View rails-4.0.0_upgrade_notes.md
  • 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
      
View 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 / report.rb
Created Dec 31, 2018 — forked from bgreenlee/report.rb
Displays a mysql-style report for an array of ActiveRecord objects. Stick it in your .irbrc.
View report.rb
# 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 / audio_length.rb
Created Jan 18, 2010
Extracting audio length with Rails and ffmpeg
View audio_length.rb
def self.get_audio_length(filepath)
pipe = "ffmpeg -i "+ filepath.to_s+" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"
command = `#{pipe}`
if command =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/
#convert the result to only secs
duration = ($2.to_i * 60) + $3.to_i
end
#return and array containing the seconds and the human readable time length, ["6453","03:54"]
return "#{duration.to_s},#{$2}:#{$3}".split(",")
end
@nukturnal
nukturnal / cancel_url.json
Created Sep 18, 2013
Checkout Cancel URL
View cancel_url.json
"actions": {
"cancel_url": "http://www.yourwebsite.com/cancelurl"
}
View invoice_structure.json
{
"invoice": {
"items": {
},
"taxes": {
},
"total_amount": 200,
"description": "Description of the invoice here"
View chare_via_opr_keys.txt
curl -H "Content-Type: application/json" \
-H "MP-Master-Key: dd6f2c90-f075-012f-5b69-00155d866600" \
-H "MP-Private-Key: test_private_amOI11Gb0SIo6NSLZr1xkfOYSuE" \
-H "MP-Token: d25e1f4ddc053779d526" \
-X POST -d '{ "token" : "OPR-test_17ca95", "confirm_token" : "2082" }' \
"https://app.mpowerpayments.com/sandbox-api/v1/opr/charge"
@nukturnal
nukturnal / opr_checkout.txt
Last active Dec 23, 2015
MPower Onsite Payment Request (OPR)
View opr_checkout.txt
curl -H "Content-Type: application/json" \
-H "MP-Master-Key: dd6f2c90-f075-012f-5b69-00155d866600" \
-H "MP-Private-Key: test_private_amOI11Gb0SIo6NSLZr1xkfOYSuE" \
-H "MP-Token: d25e1f4ddc053779d526" \
-X POST -d '{"invoice_data" : {"invoice":{"items": {},"taxes": {},"total_amount": 325,"description": "a tin of milk"},"store":{"name": "Kwame Ayewa Enterprises","tagline": "provision store","postal_address": "P.O.Box 1233 Accra North","phone": "233249441409","logo_url": "","website_url": ""},"custom_data": {},"actions":{"cancel_url": "","return_url": ""}},"opr_data" :{"account_alias" : "mpower2"}}' \
"https://app.mpowerpayments.com/sandbox-api/v1/opr/create"
@nukturnal
nukturnal / chk_endpoint.txt
Last active Dec 23, 2015
MPower Checkout Redirect HTTP API
View chk_endpoint.txt
#Sandbox Endpoint
https://app.mpowerpayments.com/sandbox-api/v1/checkout-invoice/create
#Live Endpoint
https://app.mpowerpayments.com/api/v1/checkout-invoice/create