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 = 'username@gmail.com'
msg['To'] = to_addr = '000000000@messaging.sprintpcs.com'
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.
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.
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.
- cvs commit file (commit your current working changes prior to any bug fixes)
- cvs up -r $rev_of_working_code file
- mv file file.bak
- cvs up -A file
- cp file.bak file
- <make bug fixes here>
- 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:
- cvs up -j $rev_of_head -j $rev_of_code_before_leapfrog file
- 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)
- cvs commit file
Slightly more complex method:
- cvs up -r $rev_of_code_before_leapfrog file
- mv file file.bak
- cvs up -A file
- cp file.bak file
- cvs up -j $rev_of_working_code -j $rev_of_head file
- cvs commit file
Example:
Current version: 1.16
Code that needs bug fix: 1.15
- cvs commit Admin.pm (results in 1.16)
- cvs up -r 1.15 Admin.pm
- mv Admin.pm Admin.pm.bak
- cvs up -A Admin.pm
- cp Admin.pm.bak Admin.pm
- <apply bug fixes>
- cvs commit -m "leapfrogging 1.16 for Bug# 1234" Admin.pm (results in 1.17)
- cvs up -j 1.17 -j 1.16 Admin.pm
- cvs up -j 1.15 -j 1.17 Admin.pm
- cvs commit -m "bringing back changes from 1.16 with bug fixes in 1.17" Admin.pm
- joy
