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

Mounting Amazon S3 bucket on EC2 Instance

Posted on Updated on

Install required libraries :
sudo yum install -y gcc libstdc++-devel gcc-c++ fuse fuse-devel curl-devel libxml2-devel mailcap automake openssl-devel
git clone
cd s3fs-fuse/
./configure –prefix=/usr –with-openssl
sudo make install

Create password file with S3 identity and credential :
echo MYIDENTITY:MYCREDENTIAL > /home/ec2-user/s3fs-passwd
chmod 600 /home/ec2-user/s3fs-passwd

To make file accessible for other users as well(ie nginx user) :
sudo nano /etc/fuse.conf
uncomment “user_allow_other”

To mount :
s3fs bucketname /usr/share/nginx/html/project-name/sitemap/ -o passwd_file=/home/ec2-user/s3fs-passwd -o allow_other

To mount with debug :
s3fs bucketname /usr/share/nginx/html/project-name/sitemap/ -o passwd_file=/home/ec2-user/s3fs-passwd -d -d -f -o f2 -o curldbg -o allow_other


Mount on boot :
create the global credential file :
echo MYIDENTITY:MYCREDENTIAL > /etc/passwd-s3fs
chmod 600 /path/to/passwd

sudo nano /etc/fstab
mybucket /path/to/mountpoint fuse.s3fs _netdev,allow_other 0 0


Thankx for reading. Cheers!!!

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.

Magento: Get attribute Group Name of a product attribute

Posted on Updated on

The code below will get you the  attribute group name of a product attribute.
For eg. if you want to get the attribute group name “General” of a product attribute say “description”, the code below will do the job for you.

$resource = Mage::getSingleton('core/resource');
* Retrieve the read connection
$readConnection = $resource->getConnection('core_read');
$product = Mage::getModel('catalog/product')->load(15);// replace 15 with the required product Id
$attributeId = 117; // id of the product attribute
$attributeSetId = $product->getAttributeSetId();
$query = 'SELECT * FROM `' . $resource->getTableName('eav/entity_attribute')
.'` AS main_table JOIN `'
.'` AS group_table ON main_table.attribute_group_id = group_table.attribute_group_id WHERE attribute_id = "' 
. $attributeId
.'" and main_table.attribute_set_id = "'
. $attributeSetId . '"';
* Execute the query and store the results in $results
$results = $readConnection->fetchAll($query);

// gives you the name of the required group name
$attributeGroupName = $results[0]['attribute_group_name'];
echo $attributeGroupName;

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