Sunday, September 28, 2014

Virtualenvwrapper Basics

This video does a good job of describing the basics of Virtualenvwrapper: https://www.youtube.com/watch?v=thHNYVrY0lU

You'll need to have used virtualenv to appreciate this.

Basically, you create virtual environments with "mkvirtualenv" and they're stored in a central location. When you want to switch to your virtual environment, you use the "workon" command.

You can also create a postactivate script that loads environmental variables when you switch to your virtual environment.

Note: There is also a module called Pew that seems to have a simpler installation process: https://github.com/berdario/pew

Wednesday, September 24, 2014

Meetup API address_1_error

I was getting this error while using the POST /venues method of the meetup API.

The error seems to happen when you duplicate the address of another venue. I was able to add the venue, but when I tried to add it a second time - I would get this error.

I ended up getting the list of venues and trying to find a match first.

Tuesday, September 16, 2014

Eventbrite "Application Key Error"

The error message looks like this:
{u'status': {u'http_code': 200}, u'contents': {u'error': {u'error_type': u'Application Key Error', u'error_message': u'Please provide your Application Key in the URL as "?app_key=<APP_KEY>".'}}}

After a few hours of trying to get past the Eventbrite API's "Application Key Error". I finally figured out that I needed to switch my request URL from:
"https://developer.eventbrite.com/json/event_new"
to:
"https://www.eventbrite.com/json/event_new"

Wednesday, September 10, 2014

Wednesday, September 3, 2014

SQLAlchemy Performance Tip

http://www.mobify.com/blog/sqlalchemy-memory-magic/

"If you can process the results of database queries iteratively (and very often you can), stream the results"

"Since the data needs to travel over the network from the database whether it's streamed or not, this doesn't add a huge overhead, but we'll see that it reduces memory requirements."

Example (using Flask-SQLAlchemy):
db.engine.execution_options(stream_results=True).execute(query)

However, that's not the full story when it comes to MySQLdb (MySQL-python). http://stackoverflow.com/a/3699677

If you're going to do this with mysql, I recommend using oursql: https://pypi.python.org/pypi/oursql

Enable Threading - Flask

http://stackoverflow.com/a/14823968/1364191

If you're going to be expecting more than one user on your flask server, you need to enable threading like this: app.run(host='0.0.0.0', port=5000, threaded=True)

Unfortunately, the threading makes Ctrl+C not work sometimes and I'll have to kill the thread manually.

For better solutions for production, check out these WSGI solutions: http://flask.pocoo.org/docs/0.10/deploying/wsgi-standalone/

Monday, September 1, 2014

Mosh - SSH Without Dropped Connections

https://mosh.mit.edu/

Warning: As of 10/17/2014, it's still in development and they haven't implemented scrollback yet. However, you can use screen and view the scrollback with Ctrl+A then Esc.