Git shell command checkout out branch if exists else create one

Posted on Updated on

git rev-parse --quiet --verify <branch-name> && git checkout <branch-name> || git checkout -b <branch-name>

Amazon AWS Codedeploy and Jenkins

Posted on Updated on

Things to Note:

Assign new instance to an IAM Role required for codedeploy to work on that instance while creating the instance, you can’t assign an instance to a new role once it has been initiated

While using Jenkins Aws Codedeploy plugin for Jenkins, the symbolic links are not preserved when the files in the workspace directory are zipped so there may be some error.

To preserver symlinks what I did was

tar the required files and then allow Jenkins aws codedeploy to zip that tar file and deploy it on AWS, then on appspec.yaml file  I ran a post install script to untar the tar archive.

Python extract filename and extension from filepath

Posted on Updated on

import os
inputFilepath = 'path/to/file/foobar.txt'
filename_w_ext = os.path.basename(inputFilepath)
filename, file_extension = os.path.splitext(filename_w_ext)
#filename = foobar
#file_extension = .txt

path, filename = os.path.split(path/to/file/foobar.txt)
# path = path/to/file
# filename = foobar.txt

Python Selenium Webdriver selectors

Posted on Updated on

from selenium import webdriver # import webdriver
browser = webdriver.Chrome() # initiate chrome browser for instance
browser.find_element_by_id('id of element to select') # return first element matched by the selector
browser.find_elements_by_id('id of element to select) # returns list of all elements matched by the selector
browser.find_element_by_xpath('selector expression')
browser.find_element_by_link_text('selector expression')
browser.find_element_by_partial_link_text('selector expression')
browser.find_element_by_name('selector expression')
browser.find_element_by_tag_name('selector expression')
browser.find_element_by_class_name('selector expression')
browser.find_element_by_css_selector('selector expression')

The function names are self explanatory. Every function has the element(s) version to return list of elements matched by the selector

Mystery of line break character in php file writes

Posted on

‘\n’ in single quotes is a literal \n. So you won’t see line breaks when you put \n within single quotes

file_put_contents(‘log.txt’, TEST\nTEST, FILE_APPEND);
Result in log.txt file :

“\n” in double quotes is interpreted as a line break. You will see the line breaks when you put \n within double quotes
file_put_contents(‘log.txt’, TEST\nTEST, FILE_APPEND);
Result in log.txt file :


For more info:

Thankx for reading. Cheers!!!

Useful Magento Extensions

Posted on Updated on

  1. Enhanced Admin Grids (+ Editor)
    Allow to customize a vast majority of the administration grids and add to it some useful features + an editor
  2. Magento Debug
    Debug toolbar for Magento
  3. Featured products
    Display list of featured products
  4. Pulse Storm Launcher
    The Pulse Storm Launcher is a fast, free, and fantastic productivity extension for the Magento admin console
  5. Online Magento Module Creator
    Magento Module Creator is a magento online module tool

Prestashop: Override Tools Class

Posted on

Recently, I tried overriding the meta tags on my homepage in one of my prestashop sites.
Here is what I did, made a new class in the folder overrides/classes/Tools.php and created
class Tools extends ToolsCore

I tried overriding the
public static function getHomeMetaTags
in my overridden class.

But something seemed to be wrong, and getHomeMetaTags function from the core parent class was being called instead of the child class’s getHomeMetaTags function.
After going through the code for a few hours, I found that the getHomeMetaTags was being called as self::getHomeMetaTags($id_lang, $page_name); in the function getMetaTags() in the parent.

So the problem was self::getHomeMetaTags($id_lang, $page_name); // PHP binds this to ToolsCore::getHomeMetaTags() right away
This would call the getHomeMetaTags function of the core class

So in order to override the getHomeMetaTags() function I also had to override the getMetaTags() function so that the self::getHomeMetaTags($id_lang, $page_name) function call in the child class would call the function of the same child Class.

To sum up, In order to override the static method getHomeMetaTags in child Tools class, you will also have to override the getMetaTags method as well in the child class.

Thank you for reading.
Hope this was helpful to you.