diff --git a/dip3.css b/dip3.css index 9e70225..08195b4 100644 --- a/dip3.css +++ b/dip3.css @@ -4,12 +4,12 @@ pre,kbd,code,samp{font-family:Consolas,'Andale Mono',Monaco,'Liberation Mono','B span{font:medium 'Arial Unicode MS',FreeSerif,OpenSymbol,'DejaVu Sans',sans-serif} pre span{font-family:'Arial Unicode MS','DejaVu Sans',FreeSerif,OpenSymbol,sans-serif} .baa{font:oblique large Constantia,Baskerville,Palatino,'Palatino Linotype','URW Palladio L',serif} -abbr{font-variant:small-caps;text-transform:lowercase;letter-spacing:0.1em} +abbr{font-variant:small-caps;text-transform:lowercase;letter-spacing:1px} .q{text-align:right;font-style:oblique} .q span{font-size:large} .note{margin-left:4.94em} .note span{display:block;float:left;font-size:xx-large;line-height:0.875;margin:0 0.22em 0 -1.22em} -.c,pre,.w,.w a,.download{line-height:2.154} +.c,pre,.w,.w a,.d{line-height:2.154} .f:first-letter{float:left;color:#ddd;padding:0.11em 4px 0 0;font:normal 4em/0.68 serif} h1,h2,h3,p,ul,ol{margin:1.75em 0;font-size:medium} @@ -20,7 +20,7 @@ form div{float:right} .c{text-align:center;margin:2.154em 0} /* links */ -a{background:transparent;text-decoration:none;border-bottom:1px dotted} +a{text-decoration:none;border-bottom:1px dotted} a:hover{border-bottom:1px solid} a:link,.w a{color:#26c} a:visited{color:#93c} @@ -29,23 +29,19 @@ a:visited{color:#93c} /* code blocks */ pre{white-space:pre-wrap;padding-left:2.154em;border-left:1px solid #ddd} .w{float:left} -.c,.w,.w a,.download{font-size:small} -.block,ol,p,blockquote,h1,h2,h3{clear:left} +.c,.w,.w a,.d{font-size:small} +.b,ol,p,blockquote,h1,h2,h3{clear:left} pre a,.w a{padding:0.4375em 0} .w a{text-decoration:underline} kbd{font-weight:bold} .p{color:#667} -/* hover effect for table rows, list items, and lines in code blocks */ -.h{background:#eee;cursor:default} - /* overrides */ li ol,.q{margin:0} pre a,.w a,pre a:hover{border:0} -.s{text-decoration:line-through} /* headers */ -h1,#noscript{background:PapayaWhip;width:100%} /* all hail PapayaWhip */ +h1{background:PapayaWhip;width:100%} /* all hail PapayaWhip */ h1:before{content:"Chapter " counter(h1) ". "} h1{counter-reset:h2} h2:before{counter-increment:h2;content:counter(h1) "." counter(h2) ". "} diff --git a/dip3.js b/dip3.js index bac6331..d6b929c 100644 --- a/dip3.js +++ b/dip3.js @@ -4,20 +4,10 @@ var LANGS = {'python2': 'Python 2', 'java': 'Java', 'perl5': 'Perl 5', 'clang': //google.load("jquery", "1.3"); //google.setOnLoadCallback(function() { $(document).ready(function() { - var HS = {'visible': 'hide', 'hidden': 'show'}; -/* - // toggle-able language comparisons - for (var lang in LANGS) { - $("blockquote.compare").filter("blockquote." + lang).each(function(i) { - $(this).wrapInner('
'); - $(this).prepend(''); - }); - } -*/ - hideTOC(); - // "hide", "open in new window", and (optionally) "download" widgets on code & screen blocks + /* "hide", "open in new window", and (optionally) "download" widgets on code & screen blocks */ + var HS = {'visible': 'hide', 'hidden': 'show'}; $("pre > code").each(function(i) { var pre = $(this.parentNode); if (pre.parents("table").length == 0) { @@ -26,22 +16,39 @@ $(document).ready(function() { }); $("pre.code, pre.screen").each(function(i) { this.id = "autopre" + i; - $(this).wrapInner(''); + $(this).wrapInner(''); $(this).prepend(''); - $(this).prev("p.download").each(function(i) { + $(this).prev("p.d").each(function(i) { $(this).next("pre").find("div.w").append(" " + $(this).html()); this.parentNode.removeChild(this); }); + + /* create skip links */ + var postelm = $(this).next().get(0); + var postid = postelm.id || ("postautopre" + i); + postelm.id = postid; + $(this).before('skip over this code listing'); + }); + + /* make skip links disappear until you tab to them */ + $(".skip a").blur(function() { + $(this).css({'position':'absolute','left':'0px','top':'-500px','width':'1px','height':'1px','overflow':'hidden'}); + }); + $(".skip a").blur(); + $(".skip a").focus(function() { + $(this).css({'position':'static','width':'auto','height':'auto'}); }); // synchronized highlighting on callouts and their associated lines within code & screen blocks + var hip = {'background-color':'#eee','cursor':'default'}; + var unhip = {'background-color':'inherit','cursor':'inherit'}; $("pre.code, pre.screen").each(function() { $(this).find("a:not([href])").each(function(i) { var a = $(this); var li = a.parents("pre").next("ol").find("li:nth-child(" + (i+1) + ")"); - li.add(a).hover(function() { a.addClass("h"); li.addClass("h"); }, - function() { a.removeClass("h"); li.removeClass("h"); }); + li.add(a).hover(function() { a.css(hip); li.css(hip); }, + function() { a.css(unhip); li.css(unhip); }); }); }); @@ -57,6 +64,16 @@ $(document).ready(function() { }); }); +/* + // toggle-able language comparisons + for (var lang in LANGS) { + $("blockquote.compare").filter("blockquote." + lang).each(function(i) { + $(this).wrapInner('
'); + $(this).prepend(''); + }); + } +*/ + }); /* document.ready */ //}); /* google.setOnLoadCallback */ @@ -69,7 +86,7 @@ function toggleComparisonNotes(lang) { */ function toggleCodeBlock(id) { - $("#" + id).find("div.block").toggle(); + $("#" + id).find("div.b").toggle(); var a = $("#" + id).find("a.toggle"); a.text(a.text() == HS['visible'] ? HS['hidden'] : HS['visible']); } diff --git a/strings.html b/strings.html index eeab388..796b4b2 100644 --- a/strings.html +++ b/strings.html @@ -5,6 +5,7 @@ @@ -100,7 +101,7 @@ La PeñaLet's take another look at humansize.py:
-
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], ①
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
diff --git a/unit-testing.html b/unit-testing.html
index 39b3719..ec9a06f 100644
--- a/unit-testing.html
+++ b/unit-testing.html
@@ -49,7 +49,7 @@ body{counter-reset:h1 7}
The to_roman() function should return the Roman numeral representation for all integers 1 to 3999.
It is not immediately obvious how this code does… well, anything. It defines a class which has no __init__() method. The class does have another method, but it is never called. The entire script has a __main__ block, but it doesn't reference the class or its method. But it does do something, I promise.
-
import roman1
import unittest
@@ -159,7 +159,7 @@ Traceback (most recent call last):
Overall, the unit test failed because at least one test case did not pass. When a test case doesn't pass, unittest distinguishes between failures and errors. A failure is a call to an assertXYZ method, like assertEqual or assertRaises, that fails because the asserted condition is not true or the expected exception was not raised. An error is any other sort of exception raised in the code you're testing or the unit test case itself.
Now, finally, you can write the to_roman() function.
-
roman_numeral_map = (('M', 1000),
('CM', 900),
('D', 500),
@@ -233,7 +233,7 @@ OK
The to_roman() function should raise an OutOfRangeError when given an integer greater than 3999.
What would that test look like?
-
class ToRomanBadInput(unittest.TestCase): ①
def test_too_large(self): ②
@@ -298,7 +298,7 @@ FAILED (failures=1)
Of course, the to_roman() function isn't raising the OutOfRangeError exception you just defined, because you haven't told it to do that yet. That's excellent news! It means this is a valid test case — it fails before you write the code to make it pass.
Now you can write the code to make this test pass.
-
def to_roman(n):
"""convert integer to Roman numeral"""
if n > 3999:
diff --git a/your-first-python-program.html b/your-first-python-program.html
index b3317f1..3b0c8e4 100644
--- a/your-first-python-program.html
+++ b/your-first-python-program.html
@@ -17,7 +17,7 @@ th{font-family:inherit !important}
Diving in
Books about programming usually start with a bunch of boring chapters about fundamentals and eventually work up to building something useful. Let's skip all that. Here is a complete, working Python program. It probably makes absolutely no sense to you. Don't worry about that, because you're going to dissect it line by line. But read through it first and see what, if anything, you can make of it.
-
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}