Recently in coding Category

After reading Moving Planters Indoors for the Winter by Joseph Hall I decided to translate his script to Python.  Here's the result:

#!/usr/bin/python
import xml.etree.ElementTree as ET
import httplib
import smtplib
from email.mime.text import MIMEText

conn = httplib.HTTPConnection('www.wrh.noaa.gov')
conn.request('GET','/forecast/xml/xml.php?duration=168&interval=6&lat=40.69651&lon=-112.091784')
response = conn.getresponse()

forecast_xml = ET.parse(response)
low_temp = 100
for child in forecast_xml.getiterator():
    if child.tag == 'temperature':
        temp = int(child.text)
        low_temp = temp if temp < low_temp else low_temp

if low_temp < 40:
    msg = MIMEText('Temps as low as %s coming up' % low_temp)
    msg['Subject'] = 'Cold Weather'
    msg['From'] = from_addr = '[email protected]'
    msg['To'] = to_addr = '[email protected]'

    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.starttls()
    s.login('username','password')
    s.sendmail(from_addr, to_addr, msg.as_string())
    s.quit()
I recently put up a code snippet on djangosnippets.org detailing how to do chained select boxes with Django and Mootools.

The basic idea is you have one select box that alters the contents of another select box based on what is chosen.  The idea is pretty simple, and it is pretty easy to implement also.

I've been using Mootools to do most of my javascripting lately.  I've really been impressed with that library.

CVS leapfrog

| | Comments (2192)
I don't do this very often, but on occasion I find my self working on functions in a bit of code, but forget to branch the new changes.  Of course every time I do that I find I need to go back and do bug fixes on the "old" code.

Here is how to do a somewhat graceful code leap frog in CVS.

  1. cvs commit file (commit your current working changes prior to any bug fixes)
  2. cvs up -r $rev_of_working_code file
  3. mv file file.bak
  4. cvs up -A file
  5. cp file.bak file
  6. <make bug fixes here>
  7. cvs commit -m "leapfrog from $rev_of_working_code for bug fix" file

Your old code is now at head with the bug fix.  Now you most likely want to go back to what you were working on. Depending on how complex your changes are there are two ways to do this.

Simple method:

  1. cvs up -j $rev_of_head -j $rev_of_code_before_leapfrog file
  2. cvs up -j $rev_of_working_code -j $rev_of_head file  (you will most likely get a few conflicts.  if the conflicts are over whelming then try the next method)
  3. cvs commit file

Slightly more complex method:

  1. cvs up -r $rev_of_code_before_leapfrog file
  2. mv file file.bak
  3. cvs up -A file
  4. cp file.bak file
  5. cvs up -j $rev_of_working_code -j $rev_of_head file 
  6. cvs commit file

Example:

Current version: 1.16
Code that needs bug fix: 1.15

  1. cvs commit Admin.pm (results in 1.16)
  2. cvs up -r 1.15 Admin.pm
  3. mv Admin.pm Admin.pm.bak
  4. cvs up -A Admin.pm
  5. cp Admin.pm.bak Admin.pm
  6. <apply bug fixes>
  7. cvs commit -m "leapfrogging 1.16 for Bug# 1234" Admin.pm (results in 1.17)
  8. cvs up -j 1.17 -j 1.16 Admin.pm
  9. cvs up -j 1.15 -j 1.17 Admin.pm
  10. cvs commit -m "bringing back changes from 1.16 with bug fixes in 1.17" Admin.pm
  11. joy

About this Archive

This page is a archive of recent entries in the coding category.

django is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.04