Monday, May 25, 2015

Rails 4: Page Specific JS Load

To load JS files only on particular page:


1. Stop loading it globally
    In application.js file, stub (stop) loading the js file, you don't want to load.
 
    Example:
     //stub file_name


2. Add to Precompile
     Update config/initializer/assets.rb with following line to enable assets precompile.
      Rails.application.config.assets.precompile += %w( file_name.js )

     Rails throws 'AssetFilteredError', if the file is not precompiled.


3. Load JS file in specific folder
    Load the application JS and specific file JS where needed.
    Example:
      = javascript_include_tag 'application''data-turbolinks-track' => true
   = javascript_include_tag 'file_name''data-turbolinks-track' => true 




To call document ready for specific page:


1. Introduce new class to body or div of the page
2. Use jQuery selector for that class

Example:
  %div{"class": "_class_name"}


:javascript
   $("._class_name").on("ready", ready_function);
  

Monday, May 18, 2015

Mac iCal Shared Calendar (Exchange)

One liner:
iCal - Menu =>  'Preferences'  => 'Accounts' => 'Delegation'. Add accounts using the '+' sign in 'Accounts I can access'.

TLDR;

After a weekly MS Office update, MS Outlook stopped working in Mac 10.10.3 (Yosemite); Often it went to frozen mode, and every time I had to rebuild the using Microsoft Database Utility [Press alt(option) key and click on outlook icon to open DB utility]. This made me force to use the iCal.

Followed standard Exchange integration given by current outlook provider. But adding shared calendar was tricky with iCal 8.0.

To add Shared calendar, go to 'Preferences', then select 'Accounts' tab; then go to 'Delegation'; Add accounts using the '+' sign in 'Accounts I can access'.

The 'Accounts ...' and 'Add Account ..' options in iCal menu is kind of confusing when you try to access shared calendar with existing calendar account.


Tuesday, May 5, 2015

log4j - File & Format

Sample codes to configure log4j

General logger initialization

 Logger logger = Logger.getLogger(YourClass.class);

log4j.properties file sample (writes to file too)

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d{DATE} %5p [%c]:%L - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %5p [%c]:%L - %m%n
#Same as ISO8601
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.S Z} %5p [%c]:%L - %m%n
log4j.appender.stdout.Threshold=trace

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${user.dir}/you_log_file.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=trace, stdout, file



Additional file outputs [2 sample layouts]


//Load the file handler for the logger 1
Appender fh = new FileAppender(new SimpleLayout(),  workingDir + File.separator + logfile);
logger.addAppender(fh);
fh.setLayout(new SimpleLayout());


//Load the file handler for the logger 2
TTCCLayout logLayout = new TTCCLayout();
logLayout.setDateFormat("dd MMM yyyy HH:mm:ss,SSS");
Appender fh = new FileAppender(logLayout,  workingDir + File.separator + logfile);
logger.addAppender(fh);
fh.setLayout(logLayout);


More options available with 'Enhanced Pattern Layout' and 'Layout'

Ref:
http://www.mkyong.com/logging/log4j-log4j-properties-examples/
http://stackoverflow.com/questions/4474646/how-to-write-to-a-text-file-using-to-log4j

API:
https://logging.apache.org/log4j/1.2/apidocs/index.html