Archive for the 'Programming' Category

friendsnippets.com is for code what del.icio.us is for bookmarks. Just found it and fell in love with it.
link to my account.

My “Computer Networks” (Redes de Computadores) assignment is writing an HTTP server that implements GET and conditional (if-modified-since) GET with persistent connections.
Here’s the code - Obviously, no guarantees.

This one instead reads the values from a CSV file containing experimental data.
Link to my previous implementation of Simspson’s rule.

import csv

class simpsonCsv:
    def __init__(self, filename):
        reader = csv.reader(open(filename, "rb"))

        xlist = []
        ylist = []
       
        for row in reader:
            try:
               x = float(row[0])
               y = float(row[1])
            except TypeError:
                continue
            except ValueError:
                continue
            xlist.append(float(x))
            ylist.append(float(y))
       
        self.len [...]

def simpson(f, a, b, n):
    "Approximate the definite integral of f from a to b by Simpson's rule."

    if n % 2 != 0:
        print "Ups: n must be even!"
        return -1
        
    h  = (float(b) - a)/n
    
    si = 0.0
    sp = 0.0
    
    for i in range(1, n, 2):
        xk = a [...]

MNUM - Gauss

# this requires numpy get it from http://numpy.sf.net

from copy import deepcopy
from numpy import *

# this function, swapRows, was adapted from
# Numerical Methods Engineering with Python, Jean Kiusalaas
def swapRows(v,i,j):
    """Swaps rows i and j of vector or matrix [v]."""
    if len(v) == 1:
        v[i],v[j] = v[j],v[i]
    else:
        temp = v[i].copy()
        v[i] = v[j]
   [...]

JabberLogBot

JabberLogBot is a jabber bot that records messages sent to it in a database.
The idea came from Nuno Dantas who wanted a jabber bot to record quick notes. He talked about it at a Prt.Sc dinner last Wennesday.
There’s also a simple PHP file in there that displays the data. That file is currently just for [...]

The second beta version of the iPhone SDK is now available and includes Interface Builder, a powerful tool that allows you to visually build your interface and makes creating a UI as simple as drag and drop.
Screenshots:

Download at iPhone Dev Center

I finally decided to take the Numerical Methods (MNUM) course. It turns out it’s a lot more fun than I thought. There is programming involved but you can chose to use whatever language you want. This is yet another nice excuse for me to use Python instead of C++ or Java. Last semester I was [...]

Ok, from the comments on the previous post it seems people are NOT “getting it”. This is NOT a “problem”, this is funny.
So I guess people don’t know what the functions min() and max() do or are just confusing them
max([...]) - this function usually takes a list of numbers and returns the highest number in [...]

I just got an email (via the faculty-wide spam network) about the ACM International Collegiate Programming Contest (ICP) or more precisely about SWERC 08. For a few moments I thought “hey, this might be fun”. A second later I read something like
“Languages allowed: C, C++, Java or Pascal”
Yay it’s 1995 again!!!
Pascal? Didn’t Pascal die like [...]

I mentioned in a previous post that I was using a private WordPress blog to keep my notes. Not anymore. I migrated to Evernote.
Thanks to Maria Joao Valente for sending me the invite to evernote.
Evernote is a note organizers, similar to Journler which I used a while back.
Check out the About Evernote and their screencast. [...]

It’s been months since I was insulted by Apple fanboys for saying that the iPhone needed an SDK and now Apple has officially released a beta version of the iPhone/iPod Touch SDK.
I can’t access developer.apple.com at the moment but Levi Figueira was kind enough to upload both screenshots of the pages and the PDFs of [...]

Since there’s (apparently) been some discussion (I missed) @ PrintScreen about what’s the best programming language for beginners I’ll leave here my opinion:
Python
I don’t feel like copy-pasting & summarizing a bunch of text so I’ll just leave the link for a (draft) paper I co-authored which looks at the issue in some detail
A Look At [...]

* HTML5
* JS2

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
Unicode in Python
How to Use UTF-8 with Python
Unicode HOWTO
Updated: added more links