Posts

Showing posts with the label python

JJ's Mostly Adequate Summary of the Django Meetup: When *Not* To Use the ORM & Goodbye REST: Building GraphQL APIs with Django

The Django meetup was at Prezi. They have a great space. They are big Django users.Goodbye REST: Building APIs with Django and GraphQLJaden Windle, @jaydenwindle, lead engineer at Jetpack.https://github.com/jaydenwindle/goodbye-rest-talkThey moved from Django REST Framework to GraphQL.It sounds like a small app.They're using Django, React, and React Native.I think he said they used Reason and moved away from it, but I could be wrong.They had to do a rebuild anyway, so they used GraphQL.He said not to switch to GraphQL just because it's cool, and in general, avoid hype-driven development.GraphQL is a query language, spec, and collection of tools, designed to operate over a single endpoint via HTTP, optimzing for perf and flexibility.Key features:Query for only the data you need.Easily query for multiple resources in a single request.Great front end tooling for handling caching, loading / error states, and updates.(I wonder if he's talking about Apollo, not just GraphQL. I f…

"How to Give a Talk" and "Building Video Games for Fun with PyGame"

Image

Python: Custom App Labels in Django

Django has had a long-standing missing feature that made it impossible to give your apps friendly names. See #3591 and #14251. Thankfully, this will be fixed in Django 1.7, but switching to the latest version of Django is not an option for me right now. This was making my admin look really ugly because I have app names such as "mps" and "budget_cost_data". Those would show up in random places in the admin as "Mps", "Budget_cost_data", "Budget cost data", etc. What I wanted was "MPS" and "Budget Cost Data".There are many ways to try to solve this problem. You may be able to switch to Django Suit or Grappelli and then use localization to fix it. However, when I tried that approach with Django Suit, the breadcrumbs were still broken.I finally found this snippet which got me started down a viable path. I grabbed a copy of the Django egg I was using, unzipped it, and copied django/contrib/admin/templates/admin to my proj…

Raspberry Pi: Building an LED Digital Clock

Image
As I mentioned in a previous post, I really enjoyed reading Programming Raspberry Pi: Getting Started with Python. One of the chapters in the book teaches you how to build an LED digital clock. It took some futzing around, but I finally got it done :)The first problem I had was that I didn't know how to solder. My buddy Chris Dudte gave me a kit to learn. I watched a bunch of YouTube videos with the kids in my Raspberry Pi class, and then we put the circuit board together. Problem solved.The next two problems I encountered were with the author's library for talking to the smbus for controlling the LEDs, i2c7segment. One of the problems resulted in my saying quite a few less than charitable words under my breath. The Python code kept giving me the error message "IOError: [Errno 5] Input/output error".I finally figured it out. On line 42 of i2c7segment.py, the code is hardcoded to use smbus.SMBus(0). However, sometimes you need to use smbus.SMBus(1). You can run "…

Best Practices for Software Engineers

Image
As I mentioned in my last blog post, I'm going to be giving my "Best Practices for Software Engineers" talk at both the East Bay Ruby Meetup and at BayPIGgies (the Bay Area Python Interest Group). We're planning on broadcasting the BayPIGgies meeting using a Google+ Hangout on Air. If you're interested, here's the event, and here's the direct YouTube link.Thanks to @nicholsonjf for setting this up!

Best Practices for Software Engineers

Image
I'm going to be giving my talk "Best Practices for Software Engineers" at two different user groups in May:East Bay Ruby MeetupBayPIGgiesHere's the abstract:Being a software engineer requires a lot more than knowing how to write good code.This class covers a wide variety of topics such as making code reviews useful and effective, how to deal with team conflicts, networking in real life, and planning for your career. The goal is to help you not only be a solid asset for your team, but also to be the type of software engineer that others really enjoy working with.I hope to see some of you there!

PyCon Notes: Introduction to SQLAlchemy

At PyCon, Mike Bayer, the author of SQLAlchemy, gave a three hour tutorial on it. Here's the video. What follows are my notes.

He used something called sliderepl. sliderepl is a nice ASCII tool that's a mix of slides and a REPL. You can flip through his source code / slides in the terminal. It's actually pretty neat.

At the lowest level, SQLAlchemy sends strings to the database and interprets the responses.

It took him 10 years to write it. He started the project in 2005. He's finally going to hit 1.0.

SQLAlchemy forces you to be aware of transactions.

Isolation models have to do with how ongoing transactions see ongoing work amongst each other.

Goals:

    Provide helpers, etc.

    Provides a fully featured facade over the Python DBAPI.

    Provide an industrial strength, but optional, ORM.

    Act as a base for inhouse tools.

Philosophies:

    Make the usage of different DBs and adaptors as consistent as possible.

    But still expose unique features in each backend.

…

PyCon Notes: PostgreSQL Proficiency for Python People

In summary, this tutorial was fantastic! I learned more in three hours than I would have learned if I had read a whole book!

Here's the video. Here are the slides. Here are my notes:

Christophe Pettus was the speaker. He's from PostgreSQL Experts.

PostgreSQL is a rich environment.

It's fully ACID compliant.

It has the richest set of features of any modern, production RDMS. It has even more features than
Oracle.

PostgreSQL focuses on quality, security, and spec compliance.

It's capable of very high performance: tens of thousands of transactions per second, petabyte-sized data sets, etc.

To install it, just use your package management system (apt, yum, etc.). Those systems will usually take care of initialization.

There are many options for OS X. Heroku even built a Postgres.app that runs more like a foreground app.

A "cluster" is a single PostgreSQL server (which can manage multiple databases).

initdb creates the basic file structure. PostgreSQL has to be up …

Books: Two Scoops of Django: Best Practices For Django 1.6

Image
I just finished reading the book Two Scoops of Django: Best Practices For Django 1.6. I had already reviewed the previous edition, so I was anxious to see what had changed. In short, I loved it!It's not an introduction, tutorial, or a reference for Django. In fact, it assumes you've already gone through the Django tutorial, and it occasionally refers you to the Django documentation. Rather, it tells you what you should and shouldn't do to use Django effectively. It's very prescriptive, and it has strong opinions. I've always enjoyed books like that. Best of all, it's only about 400 pages long, and it's very easy to read.This edition is 100 pages longer than the previous edition, and I really enjoyed the new chapters. It has even more silly drawings and creamy ice cream analogies than the original, and even though I'm lactose intolerant, that made the book a lot of fun to read.Having read the book cover-to-cover, even though I'm fairly new to Django,…

Python: A Response to Glyph's Blog Post on Concurrency

If you haven't seen it yet, Glyph wrote a great blog post on concurrency called Unyielding. This blog post is a response to that blog post.Over the years, I've tried each of the approaches he talks about while working at various companies. I've known all of the arguments for years. However, I think his blog post is the best blog post I've read for the arguments he is trying to make. Nice job, Glyph!In particular, I agree with his statements:What I hope I’ve demonstrated is that if you agree with me that threading has problematic semantics, and is difficult to reason about, then there’s no particular advantage to using microthreads, beyond potentially optimizing your multithreaded code for a very specific I/O bound workload.There are no shortcuts to making single-tasking code concurrent. It's just a hard problem, and some of that hard problem is reflected in the difficulty of typing a bunch of new concurrency-specific code.In this blog post, I'm not really dispu…

Python: A lightning quick introduction to virtualenv, nose, mock, monkey patching, dependency injection, and doctest

Image
pippip is a tool for installing Python packages. Python 2.7.9 and later include pip by default. If you don't have pip, you'll need to install it.virtualenvvirtualenv is a tool for installing Python packages locally (i.e. local to a particular project) instead of globally. Here's how to get everything setup: # Make sure you're using the version of Python and pip that you want to use. sudo which python sudo which pip sudo pip install virtualenv Now, let's setup a new project: mkdir ~/Desktop/sfpythontesting cd ~/Desktop/sfpythontesting virtualenv env # Do this anytime you want to work on the application. . env/bin/activate # Make sure that pip is running from within the env. which pip pip install nose pip install mock pip freeze > requirements.txt # Now that you've created a requirements.txt, other people can just run: # pip install -r requirements.txt noseNose is a popular Python testing library. It simple and powerful.Setup the project structure: mkdir …

Python: My Notes from Yesterday's SF Python Meetup

Here are my notes from yesterday's SF Python Meetup:Embed CurlJohn Sheehan.embedcurl.comIt creates a pretty version of a curl command and the output. You can embed it in your site.shlex is a module in Python to do simple lexical analysis.1-Click Deployment with Launch and DockerNate Aune @nateaThere are 10 million repos on GitHub. The curve is exponential.appsembler.comIt launches a Docker container.It makes it easy to deploy certain types of apps.You can embed a widget on your app that says "Launch demo site".docker.io (see also docker.io/learn_more/)He talked about Containers vs. VMs.Containers share the OS, so they launch very quickly.You can create new containers, and each container is just a diff of another container, so it uses very little space.Yelp: Building a Python Service StackJulian Krause, John BillingsThey're moving toward a Service Oriented Architecture.There are over 100 engineers at Yelp.They have about 180k lines of code in a Python webapp called ye…

Some Random Thoughts on Haskell

It seems like all my Python friends are playing around with Haskell lately, so it's been on my mind a lot lately. Since I'm a language guy, Haskell has always fascinated me. I wrote my first article on Haskell in 2006 (Everything Your Professor Failed to Tell You About Functional Programming), and I think it's a beautiful, interesting, awe-inspiring language. However, I've never really achieved full mastery of it. Since I've been thinking about it a lot lately, I thought I'd share some of my thoughts:Haskell is well known for being very concise. The functionality / lines of code ratio is very good. However, if I compare Haskell code to Python code, one thing is clear to me. Haskell squeezes in a lot more function calls per line of code than Python does. We have this idea in programming that the number of lines of code that a programmer can write in a given time period is relatively constant regardless of language. However, in my experience, I can write lines of…