Monthly Archives: August 2012

Heroku Timezones – Ruby on Rails

Hey everyone,

Just a quick post on how to adjust the timezone on Heroku, comes in handy when using the log files.

#Console
$ heroku config:add TZ=Australia/Brisbane

There is a fairly detailed StackOverflow post at the following link if anyone is interested in more info:
http://stackoverflow.com/questions/2719330/why-does-heroku-log-using-the-server-time-rather-than-the-rails-time-zone

The language options can also be found on the following wikipedia page:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Oracle – Number of Weekdays Between Two Dates

Hey everyone,

Just a quick post on how to select the number of weekdays between two dates:

SELECT temp_tbl.days
--SELECT COUNT(temp_tbl.days)
FROM (          
        SELECT (TRUNC(TO_DATE ('01/08/2012', 'DD/MM/YYYY'), 'dd') + LEVEL - 1) days
        FROM DUAL
        CONNECT BY LEVEL <= TO_CHAR(TO_DATE('10/08/2012', 'DD/MM/YYYY') - TO_DATE('01/08/2012', 'DD/MM/YYYY'))
     ) temp_tbl
WHERE TO_CHAR(temp_tbl.days, 'D') >= 2
      AND TO_CHAR(temp_tbl.days, 'D') <= 6

Rails Casts #142 Paypal Notifications

Hey all,

I ran into a bit of an issue in Rails Cast #142. I received the following error while testing the IPN:

WARNING: Can't verify CSRF token authenticity
Completed 500 Internal Server Error in 2ms
app/controllers/payment_notifications_controller.rb:11:in `process_ipn_payment'

Simply replace the following line with the alternative below it:

  1. #Payment_Notifications_Controller.rb
  2. protect_from_forgery :except => [:create]
  1. #Payment_Notifications_Controller.rb
  2. skip_before_filter :verify_authenticity_token, :only => [:create]

Sending Email – PL/SQL

A quick post on how to send an email with PL/SQL.

There’s a LOT of documentation available at the following link:
http://www.orafaq.com/wiki/Send_mail_from_PL/SQL

  1. PROCEDURE EMAIL_ERROR_REPORT IS
  2.  
  3.        /* Create vars */
  4.        v_From        VARCHAR2 (80) := 'test@test.com';
  5.        v_Recipient   VARCHAR2 (80) := 'me@me.com';--REPORT_RECEIVER;
  6.        v_Subject     VARCHAR2 (80) := 'test subject';
  7.        v_Mail_Host   VARCHAR2 (30) := 'smtp.test.com';
  8.        v_Mail_Conn   UTL_SMTP.Connection;
  9.        crlf          VARCHAR2 (2) := CHR (13) || CHR (10);
  10.     BEGIN
  11.  
  12.        /* Define connection */
  13.        v_Mail_Conn := UTL_SMTP.Open_Connection (v_Mail_Host, 25);
  14.        UTL_SMTP.Helo (v_Mail_Conn, v_Mail_Host);
  15.        UTL_SMTP.Mail (v_Mail_Conn, v_From);
  16.        UTL_SMTP.Rcpt (v_Mail_Conn, v_Recipient);
  17.        UTL_SMTP.Data (
  18.           v_Mail_Conn,
  19.              'Date: '
  20.           || TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss')
  21.           || crlf
  22.           || 'From: '
  23.           || v_From
  24.           || crlf
  25.           || 'Subject: '
  26.           || v_Subject
  27.           || crlf
  28.           || 'To: '
  29.           || v_Recipient
  30.           || crlf
  31.           || crlf
  32.           || 'some message text'
  33.           || crlf
  34.           ||                                                       -- Message body
  35.             'more message text'
  36.           || crlf);
  37.        UTL_SMTP.Quit (v_mail_conn);
  38.     EXCEPTION
  39.  
  40.        /* Catch exceptions */
  41.        --WHEN OTHERS THEN         
  42.     END;

Cannot Generate Tempfile – Ruby on Rails

Ran into the following problem, still not too sure what caused it but this seems to have fixed it:

Error

cannot generate tempfile `/home/chris/cartsite/tmp/cache/assets/sprockets%2Fd585a06e2ee6203ccb04c8b84150d14d20120804-8682-7q77nb-9'

Just run the following:

$ rake tmp:clear

Let me know if you come across the cause, I’d be interested to know.

Paypal Platform Ruby SDK – Adaptive Payments

Hey everyone,

This is the SDK for PayPal adaptive payments. I’ve just uploaded it to *hopefully* make it a little easier to find. Please note that it has not been updated recently and that there are a few changes to be made. The StackOverflow post below provides a few examples:

StackOverflow Post:
Adaptive Payments with Ruby

I’ll try to list any others as I come across them, but if you’ve got some of your own please let me know and I’ll try to keep the post up to date.

Download SDK here:
Paypal Platform SDK


Error #1:

Internal Server Error
 
undefined method `debug_rjs=' for ActionView::Base:Class

Remove the following line from your development.rb config file:

  1. PayPalPlatformRubySDK::Application.configure do
  2.   # Settings specified here will take precedence over those in config/environment.rb
  3.  
  4.   # In the development environment your application's code is reloaded on
  5.   # every request.  This slows down response time but is perfect for development
  6.   # since you don't have to restart the webserver when you make code changes.
  7.   config.cache_classes = false
  8.  
  9.   # Log error messages when you accidentally call methods on nil.
  10.   config.whiny_nils = true
  11.  
  12.   # Show full error reports and disable caching
  13.   config.consider_all_requests_local       = true
  14.   #config.action_view.debug_rjs             = true <---- Comment this line out (no longer supported)
  15.   config.action_controller.perform_caching = false
  16.  
  17.   # Don't care if the mailer can't send
  18.   config.action_mailer.raise_delivery_errors = false
  19.  
  20.   # Print deprecation notices to the Rails logger
  21.   config.active_support.deprecation = :log
  22.  
  23.   # Only use best-standards-support built into browsers
  24.   config.action_dispatch.best_standards_support = :builtin
  25. end

Paypal IPN History:
For some reason the IPN history button often won’t appear in the sandbox, use the following link to view it:
https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_display-ipns-history

IPN Notifications:
Just a warning for anyone else setting up payments with PayPal, the sandbox IPN is extremely flaky. It has gone down twice in the last six months for weeks at a time, with no warning or error messages. If you’re not receiving the IPN check out the forums to make sure it’s not down.