March 13th, 2010 by Rodrigo
I have this code I’m working on that is needs to be deployed remotely (Fabric makes this SO easy) and I’m using git as my version control system. Well, I was creating tarballs for this, but I was basically doing them as similar as I could to what git had in the tree (ignoring the same files, etc.), so it was kind of repetitive and, boring. Well, git to the rescue!!!
git archive --format=tar HEAD | gzip > myproject.tar.gz
And you have a nice clean zipped tarball of your code as is on HEAD, without tears
Git is awesome!
February 25th, 2010 by Rodrigo
I had this use case where I have to check which elements of a list of words where available in another list of words. So I decided to use the operator in. Just for further reference a tried the following:
# common code for all test
base_list = [...]
query_list = [...]
- Pretty simple method:
for word in query_list:
if word in base_list:
# do something
For a list of 4284 elements against a list of 107 it took 9 seconds. Using simple lists, this method is the most straight forward of all, and also the slowest one.
- Sorting things:
base_list.sort()
for word in query_list:
if word in base_list:
# do something
After sorting the list, guess what? Yeap, nothing changed, same 9 seconds
- What about sets?
bs = set(base_list)
for word in query_list:
if word in bs:
# do something
Using sets this is another history, 0.6 seconds for the same amount of data; but… if this could be achived turning one of lists into a set, what if…
- Using more sets
bs = set(base_list)
qs = set(query_list)
solution = bs.intersection(qs)
0.02 seconds.
Well, as you can see, sets are great.