Friday, September 21, 2012

Usecases using git log

ref:http://dev-logger.blogspot.sg/2009/05/usecases-using-git-log.html

Usecase: I want to be up to date with the latest activity

git log
git log -4
git log --since="1 day"
git log --since="2 hour"
git log -2 --stat
git log -2 --name-status
git log --since='2009-05-05' --until='3 days'
git log i-2 --author='Martin C'
git log 9485fdd2..7b766227 # optionally specify a file



Usecase: I want the latest changes on a specific file

git log [file] # gives you all commits for that specific file
git log -3 [file] # gives you the 3 last commits
git log -p [file] # gives you all diffs for every commit of that file
git log -2 -p db/schema.rb
git blame [file] # gives SHA1, author, line changed, app/controllers/questions_controller.rb



Usecase: I want the changes of a commit you partly remember the comment

git log --pretty=oneline | grep [comment
git log --grep='^user icon'
git log --grep='user icon' -i
git show [SHA1]
git show [SHA1]:[file


Usecase: I want stats on commits

git log --pretty=oneline | wc -l
git log --pretty=oneline --no-merges | wc -l  # no-merges: do not show commits that have more than 1 parent
git log --pretty=oneline --author='Martin C' | wc -l
git log --pretty=format:'%an' | sort | uniq -c | sort -n
git log --pretty=format:'%h by %an'
git log -4 --pretty=format:'%h (%H) by %an %ar (%ad) %s'
git log -4 --pretty=format:'%h by %an %ar (%ad) %s' db/schema.rb

Wednesday, September 5, 2012

Time triggered job Cron or Quartz?

ref: http://stackoverflow.com/questions/1029383/time-triggered-job-cron-or-quartz

Q:

I already asked a separate question on how to create time triggered event in Java. I was introduced to Quartz. At the same time, I also google it online, and people are saying cron in Unix is a neat solution.
Which one is better? What's the cons and pros?
Some specification of the system: * Unix OS * program written in Java * I have a task queue with 1000+ entries, for each timestamp, up to 500 tasks might be triggered.

A: 
  1. Using cron seems to add another entry point into your application, while Quartz would integrate into it. So you would be forced to deal with some inter-process communication if you wanted to pass some information to/from the process invoked from cron. In Quartz you simply (hehe) run multiple threads.
  2. cron is platform dependent, Quartz is not.
  3. Quartz may allow you to reliably make sure a task is run at the given time or some time after if the server was down for some time. Pure cron wouldn't do it for you (unless you handle it manually).
  4. Quartz has a more flexible language of expressing occurences (when the tasks should be fired).
  5. Consider the memory footprint. If your single tasks share nothing or little, then it might be better to run them from the operating system as a separate process. If they share a lot of information, it's better to have them as threads within one process.
  6. Not quite sure how you could handle the clustering in the cron approach. Quartz might be used with Terracotta following the scaling out pattern (I haven't tried it, but I believe it's doable).