Learning Python and Pylons, Part 1

By kenglish

I don’t have anything insightful to blog about these days other than the fact that I’m learning Python and Pylons for my school project. I am using a package called BioPython. Instead of reading the standard Python tutorial, I went through the Python course in Bioinformatics . This tutorial walks biologists through the python language using biological examples. It then introduces the main packages in the BioPython library. It has some fun exercises to make it at hands-on experience.

The Biopython API documentation leaves a lot to be desired. I am probably spoiled by raiilsbrains where I can just enter a search string rather than clicking  until I can find what I need.

I did bust out and purchase the Python Cookbook. The Programming Python book is a massive 1596. This is very impractical for the travelling programmer to carry. It would probably end up unread and collecting dust on my bookshelf the way my copy of the Cryptonomicon does.

I am surprised that python doesn’t have ruby/perl/php style string interpolation of variable.

In perl/php, I would do:
print "$first_name $last_name";

In ruby, I’d do:
puts "#{first_name} #{last_name}”

In Python, I must do:
print first_name + " " + last_name

but quite often I’m seeing examples like this:

print "%s %s" % (first_name, last_name)

Is that throw back to C or what? Didn’t they add string variable interpolation to languages to make the code more readable?

categoriaProgramming commentoNo Comments dataFebruary 8th, 2009
Read All

git reset, like svn revert, abandon all changes

By kenglish

Sometimes I’ve been making changes on the master branch and I want get my code back in sync with what is on the server. This is my stategy:

First, checkout the current branch into a new branch in case I need those change and then switch back to the master:

git checkout -b newbranch1.1.1
git checkout master

Then, view the log of the remote repository:

git log origin/master

Copy the commit number from the last commit, (eg 0b7e7260cf85ae0d57f6ab0e502202fade94df9d).

The, reset the master branch to the above commit number:

git reset --hard 0b7e7260cf85ae0d57f6ab0e502202fade94df9d

This seems like kind of long method, your comments are welcome.

categoriaProgramming commentoNo Comments dataDecember 19th, 2008
Read All

git merge stategy for deploy.rb

By kenglish

My problem is that I have multiple git branch of a rails project and in each branch, I want to maintain a different value the branch setting my deploy.rb. For example:

In branch v1.0.0-stable

set :branch, "v1.0.0-stable"

In branch, I want v1.0.1-stable

set :branch, "v1.0.1-stable"

In the master branch, I want no value.

The problem is that I often merge from v1.0.1-stable into the master branch and this overwrites the deploy.rb. This can be frustrating because every time  I need to remember to remove that “set :branch” line from the deploy.rb. If I forget and deploy from the master, it  will deploy version “v1.0.1-stable” instead of master. This always results in my wondering  “Why didn’t the deploy work? Why aren’t my changes on the site?”

The only way that I could find to prevent this is to adding a line my gitattributes file.

In .git/info/attributes, I added:

deploy.rb merge="ours"

Ours is a merge strategy and this tells git always apply

      ours
           This resolves any number of heads, but the result of the merge is
           always the current branch head. It is meant to be used to
           supersede old development history of side branches.

Note:
If you Google git merge the first 5 pages of results are the man page for the git-merge command. Why does everyone feel the need to replicate the man page all over the internet. Seriously! If what I needed was in the man page, I wouldn’t be using Google!

categoriaProgramming commentoNo Comments dataDecember 19th, 2008
Read All

Refactoring ExtJS for readability

By kenglish

An old colleague once remarked that Perl is “write-only.” That wouldn’t be funny if it wasn’t true. I think JavaScript has a similar property. Being up to my eyeballs in ExtJS lately, I have been trying to come up with ways to make my code a little more manageable. One thing any JavaScript programmer hates is variable scoping bugs. They appear all the time and take 20 hours to fix.

categoriaProgramming commentoNo Comments dataDecember 17th, 2008
Read All

Horizontal Scrollbars on ExtJS Dataview

By kenglish

If you use the Extjs Dataview Example, you will notice it is does not tell you how to do horizontal scrollbars. Nor does the documentation mention this. This actually requires some trickery as this is not currently supported.

categoriaProgramming commentoNo Comments dataDecember 15th, 2008
Read All

Awesome incident of the month

By admin

I'm (finally) getting more structured and object-oriented with my JavaScript. My co-worker is a guru at this stuff.

I was working on an awesome class called FirstTree. It was super-object-oriented. I went to go use it in my code like this:

var myObject = FirstTree.new({config: configuration});

I pounded my head on this for like 20 minutes. Why was it giving some strange error?!?!? I thought JavaScript would let me be object-oriented!

So, I asked the guru to look at my code. And he pointed out, “Dumbass, you write that line of code like this”:

var myObject = new FirstTree({config: configuration});

Moral of the story: Stop thinking in Ruby!

categoriaProgramming commentoNo Comments dataOctober 17th, 2008
Read All

PHP Captch

By admin

best tutorail so far here:

http://www.webcheatsheet.com/php/create … ection.php

categoriaProgramming commentoNo Comments dataJuly 29th, 2007
Read All

Php Excel Writer

By admin

Getting this working on Godaddy and other web hosts:

1) Download Speadsheet_Excel_Writer and OLE packages from pear.php.net
2) Create the directory structurs so they are like this:

Spreadsheet/
Spreadsheet/Excel
Spreadsheet/Excel/Writer
Spreadsheet/Excel/Writer/BIFFwriter.php
Spreadsheet/Excel/Writer/Workbook.php
Spreadsheet/Excel/Writer/Format.php
Spreadsheet/Excel/Writer/Worksheet.php
Spreadsheet/Excel/Writer/Parser.php
Spreadsheet/Excel/Writer/Validator.php
Spreadsheet/Excel/Writer.php

OLE/
OLE/OLE.php
OLE/PPS.php
OLE/PPS
OLE/PPS/Root.php
OLE/PPS/File.php

Copy the excample from http://pear.php.net/manual/en/package.f … .intro.php and make sure it works…

categoriaProgramming commentoNo Comments dataMarch 15th, 2007
Read All