Categories
Python

Django on Heroku: Postgres and dbshell

If you’re deploying a Django app on Heroku you should already know that Heroku uses Postgres. The surprise comes when your “dbshell” command will fail with an error message like:

You appear not to have the ‘psql’ program installed or on your path.

The workaround is rather simple, you have to copy the SQL manually and run it from the heroku pgsql console. To run the console, type in –

And you should get a prompt to type in your pgsql queries. Type in your SQL and commit. It should work! 🙂

Categories
Mac Python

Python: Sending Growl Notifications

Growl is an extremely popular notification system for OS X. The application allows developers to display beautiful notification messages with ease. If you’re developing an application in Python and would like to integrate with Growl, this blog post is for you.

Introducing GNTP

Let me quote from the official docs here – http://www.growlforwindows.com/gfw/help/gntp.aspx#intro:

The Growl Network Transport Protocol, or GNTP, is a protocol to allow two-way communication between applications and centralized notification systems such as Growl for Mac OS X and to allow two-way communication between two machines running centralized notification systems for notification forwarding purposes.

In short, GNTP allows two way communication between your application and Growl. Even shorter – you can use GNTP to publish notifications using Growl.

GNTP Binding for Python

We have an excellent library for interacting with GNTP. The project is hosted on Github – https://github.com/kfdm/gntp/ and the docs are available here – http://pythonhosted.org/gntp/

So how to use this library? First, install the library using pip –

To see if the installation was ok, we can test by running the module directly –

Sending Notifications

Sending a quick notification from the Python interactive prompt:

Simple, right?

You can find advanced examples on the github readme and the docs (links above). Have fun with Python and Growl!

Categories
Javascript

Extend Google Apps With Custom Scripts

Let’s get to the point straight way – we can extend the functionality of Google apps with our own scripts. Google allows us to create small scripts written in JS and attach these scripts to certain events (aka triggers) of the respective applications. When these events occur, the scripts are executed. For example, we can attach a script to the event when the user loads a document, or edits a spreadsheet or submits a form. The custom code we write allows the opportunity to do some extra processing. Thus it allows us to achieve a lot more than the default functionality. What are the common use cases?

— Adding our custom functions to spreadsheets
— Adding our own Menus to the user interface
— Creating Macros
— Do more with Forms: send customized messages
— Get sophisticated Gmail statistics
— Send out customized email messages to many people on the fly

and a lot more…

Google Developers Zone has it covered pretty nicely in the “Google Apps Script” section. Have a look yourself!

Just as a demonstration of what could be done, here’s a custom script I wrote to try it out. This script is for a form. It is attached to the “Form Submit” event of the form. When the form is submitted, my custom function gets an event. The event object has a “FormResponse” object which we can use to collect the field names and the values. Then we use “MailApp” object to send the submitted data to an email address:

We could do a lot more than that by adding a flick of our own imagination. Cool, no?