W3C Geolocation, Bing Maps and HTML 5 Canvas
This code uses the W3C's Geolocation API in conjunction with Bing Maps and HTML 5 Canvas.
<!DOCTYPE HTML>
<html>
<head>
<title>HTML5 page</title>
<!--link rel="stylesheet" type="text/css" href="site.css"/-->
<style type="text/css">
#baseDiv {position:relative; width:80%; left:10%; border:1px solid;}
</style>
</head>
<body>
<div id="baseDiv">
<canvas id="stage" width="600" height="600">Sorry, your browser does not support the canvas tag.</canvas>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.js"></script>
<script type="text/javascript">
//<![CDATA[
var lineHeight = 14;
jQuery(function() {
navigator.geolocation.getCurrentPosition(showPosition);
});
function showPosition(position) {
var ctx = document.getElementById('stage').getContext('2d'),
txt = 'This is a string of text',
x = 10, y = lineHeight,
maxWidth = 50,
lat = position.coords.latitude,
lon = position.coords.longitude;
ctx.font = '12pt Courier New';
ctx.fillText('latitude: ' + lat, x, y);
y += lineHeight;
ctx.fillText('longitude: ' + lon, x, y);
y += lineHeight;
var img = new Image(),
url = 'http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/' + lat + ',' + lon + '/15'
+ '?mapSize=400,400'
+ '&pushpin=' + lat + ',' + lon
+ '&mapLayer=trafficFlow'
+ '&key=XXXXXXXXXXXXXXXXXX';
jQuery(img).bind('load', function() {
ctx.drawImage(img, x, y);
});
img.src = url;
}
//]]>
</script>
</body>
</html>
Python - CSV to sqllite
Nice Python CSV to sqlite conversion...
# toSqlite.py - Imports humod06.txt to sqlite.
import csv
import sqlite3
conn = sqlite3.connect('humod.sqlite')
c = conn.cursor()
c.execute('''DROP TABLE IF EXISTS skl_desc''')
c.execute('''CREATE TABLE skl_desc (
id INTEGER PRIMARY KEY AUTOINCREMENT,
parent INTEGER,
mod INTEGER,
desc TEXT,
abr TEXT,
r INTEGER)
''')
insertSql = '''
INSERT INTO skl_desc
VALUES (null, ?, ?, ?, ?, ?)
'''
reader = csv.reader(open('humod06.txt', 'rb'), delimiter='\t')
rownum = 0
for row in reader:
if rownum == 0: pass
else:
parent = 0
rValue = 0
if row[5] == 'R':
rValue = 1
t = (parent,
row[1],
unicode(row[4].strip(), 'utf8'),
unicode(row[2].strip(), 'utf8'),
rValue)
c.execute(insertSql, t)
rownum += 1
print('rows: %s' % rownum)
conn.commit()
c.close()
Python - CSV to XML
# toXml.py - Imports humod06.txt to XML.
import csv
from xml.dom.minidom import parseString
doc = parseString('<skill_descriptors lvl="0"/>')
reader = csv.reader(open('humod06.txt', 'rb'), delimiter='\t')
rownum = 0
elm = doc.documentElement
for row in reader:
if rownum == 0:
header = row
else:
sd = doc.createElement('skill_descriptor')
colnum = 0
for col in row:
#print '%-8s: %s' % (header[colnum], col)
sd.setAttribute(header[colnum].lower(), unicode(col.strip(), 'utf8'))
colnum += 1
while row[3] <= elm.getAttribute('lvl'):
elm = elm.parentNode
elm.appendChild(sd)
elm = sd
rownum += 1
print(doc.toxml())
print('rows: %s' % rownum)
doc.unlink()
Egregious IE Bug
After nearly a decade of battling Internet explorer, you would have thought I knew all of IE's quirks, but today I stumbled across a "feature" (read bug) which absolutely astounded me. Running the code below in IE 7 or 8 shows their implementation of innerHTML strips leading spaces from the DOM. This wreaks havoc on HTML editors such as TinyMCE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XHTML Page</title>
</head>
<body>
<div id="baseDiv">
<a id="link" href="#" onclick="helloWorld()">Say hi...</a>
</div>
<script type="text/javascript">
//<!--<![CDATA[
function helloWorld() {
var newSpan = document.createElement('span');
newSpan.innerHTML = ' hello world ';
prompt('', newSpan.outerHTML);
}
//]]>-->
</script>
</body>
</html>












