Monthly Archives: April 2014

python circular import fun?!

dlam notes on it!

and `import …` vs `from x import y`

from the Python Programming FAQ  section:  How can I have modules that mutually import each other?

Guido van Rossum recommends avoiding all uses of from <module> import ..., and placing all code inside functions. Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as <module>.<name>.

Also see…  http://effbot.org/pyfaq/how-can-i-have-modules-that-mutually-import-each-other.htm

https://docs.python.org/2/reference/simple_stmts.html#the-import-statement

 

record Lyft tip in the PA

on my way back from the Eventbrite Pycon practice talks, I decided to turn on Lyft from Redwood City to Palo Alto

I wasn’t too optimistic about getting a ride.  I exited Marsh Road in Menlo Park, and went down Middlefield, turning right on University.   There, to my delight, I got a ping!  Next to Evvia on Emerson.  Awhile back I ate there with Yuna and ate the bestest 40 dollar lamb chops ever.  But anyways,  turns out this guy was really drunk, though I’ve seen much worse as a driver and I told him that, he was from Missouri, and as he put it in his own words was “funemployed” from his job as a restaurant person in San Francisco.

We have a fun conversation, he’s married, and he guides me to this somewhat hidden cul-de-sac off Oregon Expressway in between Middlefield and Cowper.  His wife also drives for Lyft.  He also goes to Philz Coffee on Middlefield!  Eventually after a short drive we get there, and he rambles on stating that I need to help him use the app to tip because he wasn’t familiar with the UI.  So I show him where to tap  (on the credit card button on the Lyft app) and helped him navigate to the screen with the plus and minus signs to increase the amount/donation.

Turns out the guy goes crazy, and jacks up the 7 dollar ride to like 46!   This dude was the best!   His wife came out while he was tapping the + plus button, and saw me cuddlestache.  She asked me how do you get one and I told her I went to one of the Lyft driver events (in Mitchell Park!) and got one.   Before departing I gave em like two of my green Lyft stickers and my referral card  (not that they could use it though in hindsight)

 

it seems Eventbrite has some pro Django peeps

Tonight I went to this Pycon practice talk at Eventbrite, and it was really great!   Simon Willison, who helped create Django at the Lawrence Journal-World gave a talk about feature flags and talked a bout things like flags for “maintenance mode” for a site, which is useful for having to make a site read-only.  One particularly interesting thing he noted about this was how you could create a custom auth middleware which basically ignored the user cookie.  And so, since this would make users not be able to login and modify data, your site could make progress towards being read only.   He also explicitly mentioned that the notion of “read only”-ness wasn’t at the SQL level, as you might think.  Instead, the preferred method was just to disable all possible ways of doing stuff!

Andrew Godwin, who I didn’t catch as “famous” at first but eventually realized as the creator of South gave a talk about API services and Eventbrite, and Lanyard’s migration from MySQL to Postgresql.

One cool thing I wrote down was this UserBasedExceptionMiddleware which could be used to show the debug page to a superuser even on production!

from django.views.debug import technical_500_response
import sys

class UserBasedExceptionMiddleware(object):
    def process_exception(self, request, exception):
        if request.user.is_superuser:
            return technical_500_response(request, *sys.exc_info())