Sunday, July 5, 2015

Git

Git server
http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

cd ~

git config --global merge.ff false

mkdir repos
cd repos
mkdir ur_project.git
cd ur_project.git
git init --bare


Local machine

git remote add <urid>  git@your_ip:repos/ur_project.git
git remote -v


#To see the added url

git remote show origin


Git Cheat Sheet
ref: http://git.or.cz

Remember: git command --help

Global Git configuration is stored in $HOME/.gitconfig (git config --help)

Create
From existing data
cd ~/projects/myproject
git init
git add .

From existing repo
git clone ~/existing/repo ~/new/repo
git clone git://host.org/project.git
git clone ssh://you@host.org/proj.git

Show

Files changed in working directory
git status

Changes to tracked files
git diff

What changed between $ID1 and $ID2
git diff $id1 $id2

History of changes
git log

History of changes for file with diffs
git log -p $file $dir/ec/tory

Who changed what and when in a file
git blame $file

A commit identified by $ID
git show $id

A specific file from a specific $ID
git show $id:$file

All local branches
git branch

List remote
git remote -v

git remote --help


Git Repo Browser
git instaweb --httpd webrick

Log
git log
git reflog

Youtube video:
  https://www.youtube.com/watch?v=sevc6668cQ0


http://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
A common mistake is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking the ssh button left to the URL field and updating the URL of your origin remote like this:
git remote set-url origin git@github.com:username/repo.git

Monday, June 29, 2015

BeanShell - Java Scripting in Shell

BeanShell

  Ruby's IRB equivalent Java Scripting in console.

Home:
  http://www.beanshell.org/home.html


Get the latest beanShell jar file
   http://www.beanshell.org/download.html


To install as an extension place the bsh.jar file in your $JAVA_HOME/jre/lib/ext folder.

For Mac os: place the bsh.jar in /Library/Java/Extensions
( ~/Library/Java/Extensions for individual users)


CLASSPATH Update:
  unix:     export CLASSPATH=$CLASSPATH:bsh-xx.jar #update your bashrc
  windows:  set classpath %classpath%;bsh-xx.jar #update environment variables

NOTE: xx - should match you downloaded jar version


Start new Shell window

$ java bsh.Console # Starts bean console
$ java bsh.Interpreter   // run as text-only on the command line
$ java bsh.Interpreter filename [ args ] // run script file

Trial:
$ java bsh.Interpreter 
bsh %  int add(int a, int b) { return a+b;}
bsh % print(add(1,2)); //3

Manual
 http://www.beanshell.org/manual/bshmanual.html

Groovy Gears

Started from  http://www.groovy-lang.org/learn.html.

Decided to use GVM:

$ curl -s get.gvmtool.net | bash

  Installation went well; Updated bashrc and zshrc files.

  Started new shell window

$ gvm help # Showed help 

$ gvm install groovy #installed latest version

$ groovy -version # showed installed version


Create a (text) file hello_groovy
$ vim hello_groovy

Enter: System.out.println("Hello Groovy")
Save file

$ groovy hello_groovy #print "Hello Groovy"


Manual
http://www.vogella.com/tutorials/Groovy/article.html

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


Thursday, April 30, 2015

Excel - Hyperlink - Tying to a cell

Lately one friend asked my help to figure out the way to use hyperlink to a specific cell in Excel Sheet; Which was easy after trying 4-5 options and 2 hours of Google search. So I decided to document it for future reference!

One liner:
  The technique is 'define the name' for the cell to be linked and use that 'defined name' in hyper link.

Ref:
http://excelribbon.tips.net/T006195_Tying_a_Hyperlink_to_a_Specific_Cell.html
http://www.k2e.com/tech-update/tips/418-tip-fastest-way-to-create-defined-names-in-excel

Before going on step by step, please find what is 'Name Box'. [courtesy link from http://blog.accountants.intuit.com/ways-to-be-more-productive/low-tech-excel-tips/]

Name box:


 The left most cell in 'Formula bar' is the Name Box. When you hover the Name Box cell, it shows 'Enter a name for a cell range, or select a named range from the list' [in MSOffice 2013]


Step by Step:

Create the Defined Name:
  1. Select the cell you want to be hyperlinked (to be jumped to). In the 'Name Box' [check the image above], enter a 'reference' name and press return key. [Assumed 'Reference1' for our example case]
Use the Defined Name in Hyperlink
  1. Go to the cell where you want to place the hyperlink (to be jumped from), right click and click on 'Hyperlink' from the menu
  2. In the 'Insert Hyperlink' popup window, in 'Anchor' ['Link to' for older version] section, click on 'locate'; which opens another popup window
  3. In the 'Select Place in Document' popup, expand the 'Defined Names' by clicking the small triangle [or + icon] next to it [make the triangle point down, or change + to -, by clicking], and select the reference you made in step 2. [Our example 'Reference1']


Now your hyperlink pointed to the reference; so inserting or deleting any rows or columns won't affect your hyperlink pointing cell location.


All the best!