Entries tagged “python”

How We Deliver Features to Pinners

Previously we discussed what tools Pinterest uses for deploys. This article shows how we connect them to one another in order to create a “pipeline.”

Read full post
Automatic versioning of python packages with Jenkins

I maintain a few internal python libraries at Pinterest, and for some of them, we try to maintain properly versioned pip packages. There’s no real method to my madness of versioning things, I start with 0.1 and if I need to make changes that require me to reinstall the package somewhere we’ll soon see a 0.1.1.

Read full post
Naming things and a recursion

Most Mozilla webdev projects have an awful project structure, and it’s partially my fault. I’m attemtping to fix that, but I cringe every time someone creates a new playdoh (Mozilla’s Django template) based project.

Read full post
Better querying for ElasticSearch

I wrote about how to write filter queries using pyes. Unfortunately after using ElasticSearch in the Add-ons Builder, I realized that our code would become unwieldy and hard to read if we kept using straight up pyes.

Read full post
How we slug at Mozilla

One problem we find with slug generators, is they do an awful job with unicode. For a string like this: Bän...g (bang) you get something like bng---g--bang- or at best bang-bang. But it’s 2011, urls can have unicode… here’s what we really want: bäng-bang.

Read full post
Bulk load ElasticSearch using pyes

When indexing a lot of data, you can save time by bulk loading data.

Read full post
Installing ElasticSearch plugins

I’m slowly trying to familiarize myself with ElasticSearch and the pyes python interface. ElasticSearch uses a lot of plugins, and while the plugin system is easy to use, it’s not obvious where to find the plugins.

Read full post
Delicious keeps you in the know

My last task at Delicious was to build along with the amazing Vik Singh was to build a new feed of bookmarks that was heavily influenced by Twitter. It was one of the most interesting and enjoyable pieces of code that I worked on at Delicious.

Read full post
From Delicious to Mozilla

Today I said my good-byes to Delicious.com and Yahoo! and tonight I went to the Addons Meetup @ Mozilla to get a sneak peak at what I’ll be working on in less than two weeks.

I was thrilled. I had no idea how many people to expect, but the Mozilla living room was packed - and most people were there the whole time. Real developers with really cool addons giving feedback to addons.mozilla.org directly. No matter how many blog comments, forums answered, customer care emails I responded to at Delicious - nothing beats the real insight and instant feedback you get from meeting a group of users face to face.

My brain, because of Delicious is always in data mining and analysis mode so through each presentation and each question asked, my brain was churning through things that I could build to bring some level of utility to the community.

I’m also happy to be joining an organization where everything is open sourced and available for comment. So I’m hoping to post a lot more on some of the cool tricks I do at Mozilla.

Read full post
Reading urlopen and probably any file-ish things in python fast

So I’ve been churning away in my last few days in Delicious-land trying to optimize some python code.

Read full post
Python Generators

Someone had mentioned “generators” in python to me, so I decided to figure out what it was… and I figured it out. I think a simple example would help explain it:

Read full post
Versioning Django Models

In symfony, versioning a model was not terribly difficult. I had my own specialized brute-force way of doing this.

Read full post
PHPs strengths: array_count_values

I always like to think of what different interpreted programming languages bring to the table.

Read full post
Python String Formatting

Python 2.6 (and Py3K) introduce a new way to format strings. Perviously you did this:

Read full post
postgresql and python in osx

I want to start dabbling with postgreSQL on OS X. After several SVN checkouts, binary packages, etc, I’ve realize the easiest path to success is just installing from fink unstable.

Read full post
py vs php: stemming

I’ve been porting some PHP to python during SuperHappyDevHouse and was amazed at how little code I needed to write since python makes list manipulation a breeze.

Read full post
unix timestamp in python

I spent far too much time learning that:

Read full post
the magic of django: get_callable

Read full post

[tags]smarty, symfony, php, python, django[/tags]

Read full post
python: relative paths

So I started yesterday with Django, and I decided I didn’t want to futz with creating another mysql database that I’d need to manage, etc. Instead I’ll just use sqlite.

I wanted to keep my sqlite database within my project regardless of where I might move my project later. So I did this:

I confused a lot of people on IRC, but it’s really quite easy:

  • __file__ is the filename of the current script, very similar to PHP’s __FILE__
  • os.path.abspath calculates the absolute path, hence the absolute path of the current file
  • os.path.join does all the nasty business of joining paths together and figuring out what type of slashes are needed, etc.
  • ‘data/db.sqlite’ is a string

So really all we were doing is creating a relative path, but setting it absolutely.

Read full post
python: it begins

[tags]php, python, symfony, frameworks, programming[/tags]

Read full post
python: UnicodeEncodeError: 'ascii' codec can't encode character u'\xbb' ...: ordinal not in range...

I don’t fully understand utf-8 errors, but I’ve been getting this error.

Read full post
Python, Named arguments: Pure Genius

I decided I want to learn python, if only to learn Django and to “get” what all the python hub-bub is about.

Python’s named arguments in function calls is pure genius. Let me explain.

In PHP, and many other languages you can define a function as such:

function foo($a = 2, $b = 2)
	return pow($a,$b);

If you follow, foo() will give you 4. foo(3) is 9 and foo(99,0) is 1. In python we can do the same thing, but it’ll pay to use some better variable names:

def foo(base=2, exponent=2):
	return base**exponent

Similarly foo() will give you 4. foo(3) is 9 and foo(99,0) is 1. But what if we forgot what the order was? Did base come first or was it exponent? We can do this:

foo(exponent=99, base=2)

Since base and exponent both have default values, we can even omit base and let it use the default:


This means rather than passing an $options array to my functions and checking whether an option was set or not, I can just specify which options I want in my function call. Or instead of remembering the order of the arguments, I can use whatever order suits me. Or instead of calling a function like bar(null, null, null, 2) I can just skip those first three arguments all together.

A side effect of this, is now there’s a real use, even for simple functions, to give your variables easy to remember names.

Read full post