setting an environment variable in virtualenv

In case you’re using virtualenvwrapper (I highly recommend doing so), you can define different hooks (preactivate, postactivate, predeactivate, postdeactivate) using the scripts with the same names in $VIRTUAL_ENV/bin/. You need the postactivate hook. $ workon myvenv $ cat $VIRTUAL_ENV/bin/postactivate #!/bin/bash # This hook is run after this virtualenv is activated. export DJANGO_DEBUG=True export S3_KEY=mykey export … Read more

Easy way to prevent Heroku idling?

You can install the free New Relic add-on. It has an availability monitor feature that will ping your site twice per minute, thus preventing the dyno from idling. More or less the same solution as Jesse but maybe more integrated to Heroku… And with a few perks (performance monitoring is just great). Note: to all … Read more

How to enable CORS in flask

Here is what worked for me when I deployed to Heroku. http://flask-cors.readthedocs.org/en/latest/ Install flask-cors by running – pip install -U flask-cors from flask import Flask from flask_cors import CORS, cross_origin app = Flask(__name__) cors = CORS(app) app.config[‘CORS_HEADERS’] = ‘Content-Type’ @app.route(“https://stackoverflow.com/”) @cross_origin() def helloWorld(): return “Hello, cross-origin-world!”

heroku – how to see all the logs

Update (thanks to dawmail333): heroku logs -n 1500 or, to tail the logs live heroku logs -t Heroku log documentation If you need more than a few thousand lines you can Use heroku’s Syslog Drains Alternatively (old method): $ heroku run rails c File.open(‘log/production.log’, ‘r’).each_line { |line| puts line }

Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly

You have to upload your public key to Heroku: heroku keys:add ~/.ssh/id_rsa.pub If you don’t have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use: heroku keys:add To clear all your previous keys do : heroku keys:clear To display all your existing keys do : heroku keys EDIT: … Read more

Rails: How to reference images in CSS within Rails 4

Sprockets together with Sass has some nifty helpers you can use to get the job done. Sprockets will only process these helpers if your stylesheet file extensions are either .css.scss or .css.sass. Image specific helper: background-image: image-url(“logo.png”) Agnostic helper: background-image: asset-url(“logo.png”, image) background-image: asset-url($asset, $asset-type) Or if you want to embed the image data in … Read more