Tuesday 2 February 2016

Using different magento configuration files via Git Hooks

The post-checkout git hooks runs a script, in any shebang script language, after a checkout is completed.

This can be used to change the magento config based on the branch name. To do this create multiple magento configs in app/etc e.g. local.xml.branch1 & local.xml.branch2

Create the hook

$ sudo vi .git/hooks/post-checkout
insert sample post-checkout
$ sudo chmod 775 ./.git/hooks/post-checkout
$ git checkout master

This hook is invoked when a git checkout is run after having updated the worktree. The hook is given three parameters: the ref of the previous HEAD, the ref of the new HEAD (which may or may not have changed), and a flag indicating whether the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index, flag=0). This hook cannot affect the outcome of git checkout.

sample post-checkout

       
#!/bin/sh

MAGE_CONFIG=$PWD/app/etc/local.xml

prev_head=$1
new_head=$2
checkout_type=$3

# 1 branch | 0 file
if [ $checkout_type -eq 0 ]; then
    echo "ignore file checkouts";
    exit;
fi

current_branch=$(git rev-parse --abbrev-ref HEAD)
prev_branch=$(git rev-parse --abbrev-ref @{-1})

if [ "$current_branch" == "$prev_branch" ]; then
 echo "branch "$current_branch" not changed";
 exit;
fi

if [ -n "$current_branch" ]
then
 echo "install config for branch "$current_branch"..."
 if [[ $current_branch =~ ^dev_upgrade_1_9_2_2$ ]]; then
     echo "cp $PWD/app/etc/local.xml.bincani_go_dev_mage_1_9_2_2 $MAGE_CONFIG"
  cp $PWD/app/etc/local.xml.bincani_go_dev_mage_1_9_2_2 $MAGE_CONFIG
 elif [[ $current_branch =~ ^master$ ]]; then
  echo "cp $PWD/app/etc/local.xml.bincani_go_dev_mage_1_9_0_1 $MAGE_CONFIG"
  cp $PWD/app/etc/local.xml.bincani_go_dev_mage_1_9_0_1 $MAGE_CONFIG
 else
  echo "no config"
 fi
 echo "done" 
fi

Testing

Remove the branch comparison check and then checkout the same branch each time.

$ git checkout master

if nothing happens check the file permissions

$ ls ./.git/hooks/post-checkout

Other hooks

applypatch-msg
pre-applypatch
post-applypatch
pre-commit
prepare-commit-msg
commit-msg
post-commit
pre-rebase
post-checkout
post-merge
pre-receive
update
post-receive
post-update
pre-auto-gc
post-rewrite
pre-push

More info here

  • https://git-scm.com/docs/githooks
  • https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
  • http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/

Monday 2 July 2012

Bye Bye Goolge Ads with FireFox

Step 1 : Open Firefox, Go to 'Help' menu at the top-left of the browser OR hit Alt + H
Help ⇒ Troubleshooting Information ⇒ Profile Folder: Show Folder
Note. This is your profile folder containing bookmarks etc, which you can copy and move to other PC's etc

Step 2 : Create a folder named chrome

Step 3 : Create a css file named userContent.css

Step 4 : Copy the following code to the files userContent.css
 @-moz-document domain(google.com.au) {  
    #taw {  
        display:none !important;  
    }  
    #rhs_block {  
        display:none !important;  
    }  
}   
Step 5 : Restart Firefox

Sunday 1 July 2012

HTML5 Geolocation API

Lowest Supported Browsers

IE 9.0+, Firefox 3.5+, Chrome 5.0+, Safari 5.0+, Opera 10.6+, iOS Safari 3.2+, Opera Mobile 11.0+, and Android/Browser 2.1+/3.0+
For current compatibility see here http://caniuse.com/geolocation

Geolocation API Specification

http://dev.w3.org/geo/api/spec-source.html

Technology Used

Global Position System GPS
Assisted GPS (A-GPS) cell site triangulation


Example JavaScript

 //Check if browser supports W3C Geolocation API  
 if (navigator.geolocation) {  
   // single shot position request (others are repeat + cached)   
   navigator.geolocation.getCurrentPosition(successFunction, errorFunction);  
 }  
 else {  
   alert('Geolocation API is not supported by your browser.');  
 }  
 function successFunction(position) {  
   var lat = position.coords.latitude;  
   var long = position.coords.longitude;  
   alert('Your location coordinates are: Latitude:'+lat+' Longitude: '+long);  
 }  
 function errorFunction(position) {  
   alert('Error!');  
 }  
code formatted here

Friday 29 June 2012

Movie Review: Prometheus

Don't blame Ridley, blame Lindelof (Lost) & Spaihts (The Darkest Hour) for any misgivings you may have about this movie. These two aliens to Sci-Fi clearly take the word 'fiction' too literally and skip so much logic that this film becomes utterly unconvincing.

I actually enjoyed the direction and visual effects in this movie, but as you know, these two alone do not make a great movie.

Its the Star Wars prequel disaster all over again.

At least we have a new contender for the best acted android!

1. Michael Fassbender - Prometheus (2012)
2. Lance Henriksen - Aliens (1986)
3. Jude Law - Artificial Intelligence (2001)
4. Rutger Hauer - Blade Runner (1982)

Only 1/2 star from me, although I had high expectations.

More here: At The Moives: Prometheus

Sunday 17 June 2012

How to override the blogger template copyright using jQuery

1. Add link to the latest jQuery JavaScript library to the of your template.
http://code.jquery.com/jquery-latest.min.js

2. Add a HTML/JavaScript Gadget to your template and populate with the following JavaScript.
 $(document).ready(function() {  
  var year = new Date();  
  var cr = "© " + year.getFullYear();
  cr = cr + "&nbsp;<a href='mailto:email@address.com'>Name</a>";   
  var attr = $("#Attribution1 .widget-content");  
  attr.html(cr);   
 });  
code formatted here