Adding dynamic classes to your custom WordPress widgets

I recently released an ad management plugin for WordPress called “Easy AdSense Ads & Scripts Manager“.

In this plugin we have a custom widget with option to remove the padding and borders (if any) added by the theme. I did not think much before implementing this feature and was expecting WordPress to have some kind of hook or filter to easily add a class to the widget wrapper and use it to remove the padding and border.

Option that lets you remove padding and borders from the widget

Unfortunately for some reason there is no easy hook or filter in this case. Very strange for WordPress.

But luckily there are two things available

  1. You can add any custom classes to your widget.
  2. There is $args['before_widget']

So here is what I did, use option one to add a custom class, which is actually a place holder which I would replace later. Like this

Now whenever the user checks the remove padding and border option,

I would simply replace this __eaa__ with the class eaa-clean like like below

I could have done this directly skipping the first step of adding a placeholder and directly using a regular expression on $args['before_widget'], but did not for the following reasons.

  1. It did not seem solid, and might fail in some cases.
  2. Since this a plugin that can be used in conjunction with any theme, I don’t have control over what $args['before_widget'] is going to be.

Complete implementation of this can be found on git

Sending email from docker through Postfix installed on the host

We use MUP to deploy our Meteor app, NYBR. MUP creates three docker containers for running the meteor app, nginx reverse proxy and mongo. Like most applications, the need for sending the email came, ideally we should be using Amazon Web Services SES,  but getting their approval was pain in the @$$ and was taking time. So, we did not want to hold back our development and decided to send the email through our own SMTP server until SES was approved.

We installed postfix and were hoping to get to developing and sending beautiful email to our users. Unfortunately we were greeted with the Connection refused error.

After trying various things in post fix configuration at /etc/postfix/, turns out there is something called docker bridge (docker0) which acts a a bridge between your ethernet port and docker containers so that data can go back and forth.

So you have to listen on the docker0 interface. Todo that, type ifconfig on your host system to find out the bridge address and set your postfix to listen on it.

Docker Bridge address

As you can see in the image above, the ip is

In post fix cons located at set /etc/postfix/

inet_interfaces =

While you are there, add your actual docker container ip address to mynetworks

mynetworks =

above two are private ip addresses of my docker containers from which I wish to send email.

You can find the IP address of your docker container by

docker inspect [container_id, container_name]


docker inspect my_container_name

Let me know in comments if you would like to learn how to send html emails in meteor.

error: command ‘cc’ failed with exit status 1; Can’t install PIL, Pillow, MySql and other packages in Mavericks.

If you are getting the following error when installing python packages using PIP or easy_install, don’t worry. You have come to the right place for solution.

First make sure you have developer tools installed. You can install them by executing the following command in terminal

xcode-select --install

The clang errors are due to changes introduced in Xcode 5.1 and due to the way the Apple-supplied system Python 2.7 is built. You can tell them to shut up by adding these environment variables in terminal.

Error while installing PIL, Pillow, MySql on OSX Mavericks using PIP

2 Common errors while setting up phpMyAdmin on Mac OSX

You might encounter the following two errors while installing phpMyAdmin on OSX

  • Login without password is forbidden by the configuration ( See AllowNoPassword )
  • #2002 can not login tot the MySQL server

Here are the fixes for the above two errors.

1. Open phpMyAdmin configuration located at (phpMyAdmin Folder)/ and change

$cfg['Servers'][$i]['AllowNoPassword'] = False; to $cfg['Servers'][$i]['AllowNoPassword'] = true;

2. In the configuration file change  $cfg['Servers'][$i]['host'] = 'localhost'; to $cfg['Servers'][$i]['host'] = '';

Django | Set the defulat ordering rule for queries in the models

Though we can specify order explicitly in queries like below


it is repetitive and most of the times we will want to order by a particular field.

We can specify the order in the models like this

Restrict Django Templates From Deleting Data.

Django allows method calls inside template system. Though this is an useful feature, some of the methods will have side effects. Mostly the ones that alter data.
Say, for instance, you have a UserAccount object that has a delete() method. If a template includes something like {{ account.delete }}, where account is a UserAccount object, the object would be deleted when the template is rendered!

To prevent this, set the function attribute alters_data on the method:

def delete(self):
# Delete the account
delete.alters_data = True

The template system won’t execute any method marked in this way. Continuing the above example, if a template includes {{ account.delete }} and the delete() method has the alters_data=True, then the delete() method will not be executed when the template is rendered. Instead, it will fail silently.

What do Dollar and Caret ( $ and ^) sign in Django urls mean?

$ and ^ are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,” and the dollar sign means “require that the pattern matches the end of the string.”

For example consider the  following url pattern

Without the dollar sign at the end it will match any url starting with hello like

  • hello/satish
  • hello/gandham/
  • hello/satish/123/pqr

Note: use url(r'^$', my_homepage_view), to match root.

Right way to break Django code for debugguing

Django traceback is a very helpful tool in Django development. It saves us from the boring tasking of writing print statements to track variables.

Traceback doesn’t kick when there is no error.  There may be no coding errors but there is a flaw in our application logic which we want to debug. In such cases we can trigger Django traceback by adding assert False in our code.


def hello_world(response):
test_var = "Something"
test_var2 = "another var"
assert false
return HttpResponse(test_var+test_var2)

Error whil creating super user in django1.4 on MAC

I got the following error while trying to create a super user from shell for django1.4.

This problem was rectified by running this command in terminal before adding the user
export LANG="en_US.UTF-8"

I’m guessing this character encoding problem while running syncdb is the reason for the following error while accessing admin section of django1.4

If i’m wrong you can solve the above problem by running this code i django shell