tag:quandyfactory.com,2010-7-27:/20107272010-7-27T12:00:00ZQuandy Factory Newsfeed - AllQuandy Factory is the personal website of Ryan McGreal in Hamilton, Ontario, Canada..http://quandyfactory.com/blog/69/how_to_write_a_blog_post2010-07-26T12:00:00ZHow to Write a Blog Post
<p>The most basic guideline to writing a blog is this: <strong>Provide value for your readers.</strong> Valuable writing is personal, informative, instructional, revelatory, entertaining, and engaging. The object of your blog is not to promote your organization but to serve the interests of your readers. </p>
<p>Don't think of it as an alternative channel for press releases or other marketing activities; people can see a sales pitch coming a mile away. Instead, think of it as a way to build relationships with readers by sharing your expertise in a way that helps them and encourages them to share your articles more widely and come back for more.</p>
<h3>Topics</h3>
<p>There's no predicting which topics will generate the most interest, but variety of topics and approaches will give your blog the broadest set of opportunities to engage readers. </p>
<p>If you stick with it, blogging becomes a habit that integrates itself into your workflow and actually helps you by engaging readers to discuss, expand, scrutinize and clarify your own thoughts.</p>
<ul>
<li><p><strong>Relax.</strong> Think of blogging as a conversation, not an assignment. A blog entry is closer in tone to a personal correspondence than a term paper. Think about subjects, issues or events that you would enjoy discussing with your peers.</p></li>
<li><p><strong>Write for yourself.</strong> Write about things that interest or challenge you. The single most-read article I've ever written is a technical guide on <a href="/blog/65/designing_a_restful_web_application">designing web applications</a>, which I wrote to clarify the underlying principles so I would understand them more fully.</p></li>
<li><p><strong>Try to surprise.</strong> Most nonfiction writing is goal-oriented and persuasive, but the term "essay" comes from the French verb <em>essayer</em>, which means "to try". An <em>exploratory</em> essay is a formalized attempt to understand an issue rather than defend a conclusion. Exploratory essays often lead in <a href="http://www.paulgraham.com/essay.html">surprising</a> directions, which makes for a compelling read.</p></li>
<li><p><strong>Solve a problem.</strong> Your day is filled with problems and challenges that are similar to those faced by other people. Share some of the innovative ways you have solved particular problems and invite readers to share theirs. Another popular blog entry I've written was a summary of lessons I've learned trying to deal with <a href="/blog/54/shared_awareness_a_better_way_to_manage_comment_trolls">comment trolls</a>.</p></li>
<li><p><strong>Find and explore a niche.</strong> The internet is a big enough medium that even seemingly narrow subjects, if well-developed, can attract lively reader communities. This also provides opportunities to transfer ideas and practices from one niche to another.</p></li>
<li><p><strong>Explain a statistic.</strong> Modern citizens are bombarded with statistics delivered out of the blue and out of context. You can humanize statistics by explaining what they mean in concrete terms and by sharing anecdotes that sketch the human faces behind the numbers.</p></li>
<li><p><strong>Share your experience.</strong> Your value to your organization goes beyond a narrow job description and encompasses all the experiences, values and connections you bring with you to work. Tap into those so your writing reflects your broader competence.</p></li>
<li><p><strong>Entertain.</strong> Good blog writing is like good conversation: refreshing, invigorating, and entertaining as well as informative. Feel free to have a bit of fun.</p></li>
<li><p><strong>Revisit older posts.</strong> Over time, with new information and greater experience, our opinions often change and evolve. It's worth going back to older posts periodically to reassess them - what is still true, and what has changed. Obviously you won't be able to do this right away.</p></li>
</ul>
<h3>Writing and Tone</h3>
<ul>
<li><p><strong>Write in first person.</strong> You are writing as a <em>person</em> as well as on behalf of an organization. Allow your writing to reflect your personality and your personal voice. Don't be afraid to refer to yourself as "I" if you're writing about something you've done.</p></li>
<li><p><strong>Use the active voice.</strong> Your blog is written <em>by</em> people, <em>about</em> people and <em>for</em> people. Don't drop the people out of your writing by relegating them to the tail-end of your sentences. Figure out who is the active agent in a sentence and move that person or entity forward into the subject.</p>
<p><em>Passive</em>: "Ideas were gathered from community residents on how to use the vacant land." <br />
<em>Active</em>: "Community residents shared their ideas on how to use the vacant land."</p></li>
<li><p><strong>Have an opinion.</strong> Readers know you are a human and expect you to have opinions. Good opinions are <em>reasonable</em> and <em>defensible</em> but <em>encourage discussion</em>. </p></li>
<li><p><strong>Add value.</strong> Don't just re-post a link to something else. At the very least, add your own commentary that expands, clarifies, corrects or otherwise enhances the linked content.</p></li>
<li><p><strong>Vary the length of your posts.</strong> Sometimes a short piece with a pithy observation or bit of commentary can stand on its own. Other issues deserve a more in-depth treatment. Both are welcome and keep the blog interesting.</p></li>
<li><p><strong>Leave some room.</strong> Your article doesn't need to be exhaustive or anticipate every possible critique. A well-written article covers an important aspect of an issue but leaves room for readers to add to the conversation by expanding, clarifying, and challenging what you've written. </p></li>
</ul>
<h3>Editing</h3>
<ul>
<li><p><strong>Always check spelling and grammar.</strong> Typos and other flagrant errors look sloppy. Aim for the sweet spot that feels like conversational English - the terrain that lies between the strictures of formal writing and the morass of split infinitives and grocers' apostrophes.</p></li>
<li><p><strong>Edit for clarity and brevity.</strong> Stephen King recently shared the simplest advice he ever received for revising: <em>Draft 2 equals draft 1 minus 10 percent.</em> He also advises, "Kill your darlings" - by which he means sentences that serve only to display their own cleverness.</p></li>
<li><p><strong>Remove noise words.</strong> We all habitually pepper our writing with such tics as "to be sure", "in order to", "bottom line", "liaise", "going forward", "in the loop", "two cents", "for what it's worth", "in my [humble] opinion", "ducks in a row", "outside the box", "at the end of the day", "vis-a-vis", and a profusion of adverbs (e.g. "<em>very</em> unique") that communicate nothing but hyperbole. Get rid of them.</p></li>
<li><p><strong>Define Jargon.</strong> Some business-speak is a necessary evil. If you have to use industry-specific terminology, write the terms and acronyms out in full and define them for readers.</p></li>
</ul>
<h3>Presentation</h3>
<ul>
<li><p><strong>Write a Punchy Title.</strong> Clear, descriptive, humorous titles catch the reader's attention and help search engines determine the article's content. Warning: don't go overboard. A hyperbolic title that oversells the content will leave readers feeling betrayed.</p></li>
<li><p><strong>Keep paragraphs short.</strong> Big walls of text are hard to scan on a computer screen. Keep paragraphs short - between one and three sentences - and discrete in terms of their contents.</p></li>
<li><p><strong>Include subtitles.</strong> Subtitles within an article, particularly a longer one, break up the text into manageable chunks.</p></li>
<li><p><strong>Use appropriate layout techniques.</strong> If you want to draw attention to a key word or phrase, make the text <strong>bold</strong>. If you have a list of items, use lists (like the lists in this guide). Use bullet-point lists for your items unless they need to be in a specific order, in which case use numbered lists. </p></li>
<li><p><strong>Summarize.</strong> After writing your article, write a one- or two-sentence summary and post the summary at the top, just beneath the title. Combined with a punchy title, a clear summary will help readers decide whether your article is worth reading.</p></li>
</ul>
Ryan McGreal2http://quandyfactory.com/blog/65/designing_a_restful_web_application2010-06-25T12:00:00ZDesigning a RESTful Web Application
<h3>Introduction</h3>
<p>I'm working on a couple of projects that involve building a web service, and I decided early on that because of our business constraints - having to communicate with a variety of different systems of varying levels of sophistication - it made sense to keep the web service as simple and accessible as possible.</p>
<p>That pointed me toward designing a RESTful web service that transmits data in a simple format over straight HTTP. After all, just about any programming language imaginable can make an HTTP request. I also decided to go with JSON for the data format, in part because I've been <a href="/blog/50/couchdb_working_notes">experimenting lately with CouchDB</a> and appreciate both the simplicity and flexibility of JSON and the fact that you can find a JSON parser for any language.</p>
<p>This blog entry is my attempt to get all the concepts of RESTful web service design straight. There's a good chance that some of this information is wrong; and if you notice something, please <a href="mailto:ryan@quandyfactory.com">let me know about it</a>. I'll investigate your argument and update the essay as applicable.</p>
<p>With that in mind, here we go.</p>
<h3>Representational State Transfer</h3>
<p>Representational State Transfer, or REST, is a model for designing networked software systems based around clients and servers. In a RESTful system, a client makes a <strong>request</strong> for a <strong>resource</strong> on a server, and the server issues a <strong>response</strong> that includes a representation of the resource.</p>
<p>The concept was formalized in 2000 by Roy Fielding, one of the architects of Hypertext Transfer Protocol (HTTP), about more which below, in his doctoral dissertation. It is not surprising, then, that REST and HTTP mesh very smoothly.</p>
<p>A RESTful client-server system is <strong>stateless</strong>, meaning each request against the server contains all the information the server needs to process it; and <strong>cacheable</strong>, in that the server can specify whether and for how long resource representations can be cached either locally on the client or on intermediate servers between the client and the server.</p>
<h3>Hypertext Transfer Protocol</h3>
<p>Hypertext Transfer Protocol (HTTP) is a stateless protocol based on a client requesting a resource across a network and the server providing a response. As such, an HTTP transaction entails a <strong>request</strong> and a <strong>response</strong>. The request goes from the client to the server, and the response goes from the server back to the client.</p>
<h4>HTTP Requests</h4>
<p>An HTTP request has three parts:</p>
<ol>
<li><p>The <strong>request</strong> line, which includes the HTTP method (or "verb"), the URI, and the HTTP version. E.g.</p>
<p>GET /article/1/ HTTP/1.1</p></li>
<li><p>One or more optional <a href="http://en.wikipedia.org/wiki/List_of_HTTP_headers">HTTP headers</a>, which are key/value pairs that characterize the data being requested and/or provided.</p></li>
<li><p>An optional <strong>message body</strong>, which is data being sent from the client to the server as part of the request.</p></li>
</ol>
<h4>HTTP Responses</h4>
<p>An HTTP response also has three parts:</p>
<ol>
<li><p>The <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP status code</a>, indicating the status of the requested URI, e.g.</p>
<p>HTTP/1.1 200 OK</p></li>
<li><p>One or more optional <strong>HTTP headers</strong>, which are key/value pairs that characterize the data being provided.</p></li>
<li><p>An optional <strong>message body</strong>, which is the data being returned to the client in response to the request.</p></li>
</ol>
<h3>Resources</h3>
<p>HTTP deals in <strong>resources</strong>. Each URI points to a resource on the server. Think of URIs as nouns, not verbs, with one URI for each resource. For example, if you want to add the ability to create an article, it might be tempting to create a URI called <code>/create_article</code>. This is wrong, because it conflates the object (the resource) and the action (creation). </p>
<p>Instead, it makes more sense to have a resource called <code>/article</code> and a <strong>method</strong> that lets you create articles.</p>
<h3>HTTP Methods</h3>
<p>HTTP defines several methods, or "verbs", to execute on a resource: <code>HEAD</code>, <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code>, <code>TRACE</code>, <code>OPTIONS</code>, <code>CONNECT</code>, and <code>PATCH</code>. However, the following four are most commonly used in web services:</p>
<h4>GET Method</h4>
<p>To retrieve a resource, issue an HTTP <strong>GET</strong> request. GET requests have no side effects, meaning they do not produce any change in the resource. GET requests do not include a message body, but GET responses usually do.</p>
<h4>POST Method</h4>
<p>To submit data to be processed, issue an HTTP <strong>POST</strong> request. POST requests require a message body, i.e. the data to be processed. </p>
<p>For example, if there is a resource called <code>/article</code> and you want to add a new article, issue a POST request to <code>/article</code> with the content. The server will create a new <em>subsidiary</em> URI under <code>/article</code> - for example, <code>/article/9001</code> - and assign that URI to the content you sent with your POST request.</p>
<p>Important note: POST requests are <em>not</em> idempotent, meaning multiple POST requests will create multiple resources with unique identifiers.</p>
<h4>PUT Method</h4>
<p>To place content at an existing resource, issue an HTTP <strong>PUT</strong> request. For example, if there is a URI <code>/article/9001</code> and you want to replace the content served at that URI, issue a PUT request to that URI with the new content.</p>
<p>Important note: PUT requests <em>are</em> idempotent, i.e. issuing 1 or 5 or 50 identical PUT requests will have the same effect on the resource. <strong>PUT</strong> requests must include a message body (the resource to be placed at the URL). </p>
<h4>DELETE Method</h4>
<p>To remove a resource (and remove its accompanying URI), issue an HTTP <strong>DELETE</strong> request. DELETE requests should be idempotent, i.e. issuing 1 or 5 or 50 identical DELETE requests will delete exactly one resource. DELETE requests do not require a message body.</p>
<h4>Idempotence</h4>
<p>This funny-looking word is crucial to designing an effective web service. A request is <strong>idempotent</strong> if issuing it more than once does not change the resource state beyond issuing it just once. Read that again if you have to.</p>
<p>For example, a DELETE request is idempotent if the first request deletes a resource at a URI, and the second request does nothing because the resource at that URI is already deleted. </p>
<p>For another example, a PUT request is idempotent if the first request creates a resource at a URI, and the second request creates the same resource at the same URI.</p>
<p>A request is <em>not</em> idempotent if issuing it more than once <em>does</em> change the resource. For example, a POST request to add a comment to a document is not idempotent, if issuing the POST request twice adds the comment twice (so that the document contains two identical comments). </p>
<h4>PUT vs. POST</h4>
<p>My original understanding of HTTP methods was that you would use PUT to create a resource and POST to update it. This seems in keeping with common sense, but it breaks down when you apply the all-important filter of idempotence.</p>
<p>An interesting discussion on Stack Overflow <a href="http://stackoverflow.com/questions/630453/put-vs-post-in-rest">tackles this issue</a>, but what convinced me to change my mental model was this observation:</p>
<blockquote>
<p>POST creates a child resource, so POST to <code>/items</code> creates a resources that lives under the <code>/items</code> resource. Eg. <code>/items/1</code>.</p>
<p>PUT is for creating or updating something with a known URL. </p>
</blockquote>
<p>This collision between the inclination to regard PUT as creating and POST as updating is a significant source of confusion about how to well-design a RESTful system, and deserves more attention.</p>
<p>Furthermore, it's tempting to assume that the HTTP verbs line up precisely with the SQL CRUD verbs, but while they're superficially similar, they're not identical. Treating them as such leads to this kind of gotcha. </p>
<p>It's important to keep the logic of HTTP methods separate from the logic of SQL queries, and to develop specialized appropriate logic between the two domains that ensures the data processing on the server produces responses that satisfy the requirements of the HTTP methods (particularly in respect to idempotence).</p>
<h3>Conceiving the Web Service: A Resource/Method Table</h3>
<p>At a conceptual level, a RESTful web service API is a matrix of resources and methods that exposes the functionality of the service to third party applications. Below is an example of what that matrix might look like. </p>
<p>Again, note well that actions are not mapped to URIs. A resource is an <em>object</em>, a <em>noun</em>, and the action inheres to the HTTP Verb, not to the URI. As a result, the same resource URI can serve different responses (corresponding with different actions) depending on the HTTP Verb.</p>
<table>
<caption>REST Resource/Action Matrix</caption>
<thead>
<tr>
<th colspan="4">Request</th>
<th rowspan="2">Server Action</th>
<th rowspan="2">Response</th>
<th rowspan="2">Idempotent</th>
</tr>
<tr>
<th>Resource</th>
<th>Parameters</th>
<th>Method</th>
<th>Data</th>
</tr>
</thead>
<tbody>
</tr>
<tr>
<td>/article</td>
<td></td>
<td>POST</td>
<td>article details</td>
<td>creates a new article</td>
<td>returns confirmation and id</td>
<td class="red">No</td>
</tr>
<tr>
<td>/article</td>
<td>/id</td>
<td>GET</td>
<td></td>
<td>gets article details</td>
<td>returns article details</td>
<td class="green">Yes</td>
</tr>
<tr>
<td>/article</td>
<td>/id</td>
<td>PUT</td>
<td>new article details</td>
<td>updates article details</td>
<td>returns confirmation and updated article details</td>
<td class="green">Yes</td>
</tr>
<tr>
<td>/article</td>
<td>/id</td>
<td>DELETE</td>
<td></td>
<td>deletes an article </td>
<td>returns confirmation of deleted article</td>
<td class="green">Yes</td>
</tr>
</tbody>
</table>
<p>This is the RESTful way to organize a web service: URIs are objects and HTTP Verbs are actions performed on those objects.</p>
<h3>HTTP Response Data Formats</h3>
<p>Every web server is also a RESTful web service, accepting GET and POST requests to particular resources, and then performing actions and serving data in response.</p>
<p>A conventional web server delivers its data in HTML format, with related Javascript (<code>text/jss</code>), CSS (<code>text/css</code>) and image files. HTML is an excellent format for marking up textual data for human use, but it has very limited expressive power for structuring data beyond simple documents.</p>
<p>The most common formats used to transmit structured data across HTTP are <strong>XML</strong> and <strong>JSON</strong>, with an honourable mention for <strong>YAML</strong>.</p>
<h4>XML</h4>
<p><a href="http://www.w3.org/XML/">XML</a>, or eXtensible Markup Language, is a markup (i.e. tag) based syntax based on SGML for formatting structured, text-based data. XML is a format in which to create domain specific markup languages that define particular data structures. </p>
<p>For example, <a href="http://en.wikipedia.org/wiki/RSS">RSS</a> and <a href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a> are XML language standards defined to structure documents published to websites so that the documents can be 'syndicated' to feed readers and third party sites for display.</p>
<p>Likewise, the default underlying structure of Microsoft Office documents since Office 2007 is an XML language called <a href="http://en.wikipedia.org/wiki/Office_Open_XML">OOXML</a>.</p>
<p>XML structures data by defining elements, properties, data types and allowable nesting rules in an XML schema called a <a href="http://en.wikipedia.org/wiki/Document_Type_Definition">Document Type Definition</a>, or DTD. </p>
<p>A given XML document specifies which DTD schema should define its structure with a <a href="http://en.wikipedia.org/wiki/Document_Type_Declaration">Document Type Declaration</a>, or DOCTYPE.</p>
<p>A given XML document can reference multiple DTDs by using namespaces.</p>
<p>Here is a sample XML file containing contact information about a person, taken from <a href="http://en.wikipedia.org/wiki/JSON">Wikipedia</a>.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<age>25</age>
<address>
<streetAddress>21 2nd Street</streetAddress>
<city>New York</city>
<state>NY</state>
<postalCode>10021</postalCode>
</address>
<phoneNumber type="home">212 555-1234</phoneNumber>
<phoneNumber type="fax">646 555-4567</phoneNumber>
</Person>
</code></pre>
<p>XML must be: </p>
<ul>
<li><p><strong>Well-formed</strong> - elements are properly nested, tags are properly closed and match case, special characters are escaped, and Unicode characters are encoded; and </p></li>
<li><p><strong>Valid</strong> - its elements and attributes match the rules defined in the DTD.</p></li>
</ul>
<p>An XML Language called XSLT can be used to map XML documents into other markup languages, e.g. HTML.</p>
<p>XML is in wide use in applications that transfer structured data over the internet.</p>
<h4>JSON</h4>
<p><a href="http://json.org/">JSON</a>, or "JavaScript Object Notation", is a lightweight data format introduced in 2001 by Douglas Crockford.</p>
<p>Pronounced "Jason", JSON is based on JavaScript object literal notation, a syntax for creating objects in JavaScript by literally describing their properties and methods. Here is the JSON equivalent to the XML code in the previous section.</p>
<pre><code>{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber": [
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
]
}
</code></pre>
<p>While the XML above contained 367 characters (not including indentation), the equivalent JSON contains only 272 characters - only three-quarters as large.</p>
<p>JSON supports <strong>lists</strong> (ordered sets of values) and <strong>dictionaries</strong> (unordered collections of key/value pairs) with arbitrary nesting and various data types: <strong>number</strong>, <strong>string</strong>, <strong>boolean</strong>, <strong>list<em>, *</em>object</strong> and <strong>null</strong>. </p>
<p>Like XML, JSON is also in wide use in applications that transfer structured data over the internet.</p>
<p>A major advantage over XML is that the syntax is much simpler and less verbose, which makes it lighter across networks as well as more human-readable.</p>
<p>Mature JSON parsers are available for a wide range of programming languages in addition to JavaScript. Python, for example, <a href="http://docs.python.org/library/json.html">includes a json parser</a> as part of its standard library (as of version 2.6; earlier versions can use the third-party <a href="http://pypi.python.org/pypi/simplejson/">simplejson</a> library). </p>
<p>A decent JSON parser converts an object back and forth between the programming language's native data types and their JSON equivalents. That way, an application can receive a JSON object, convert it into a native object, process it natively, and then convert the final result back to JSON to be dispatched elsewhere.</p>
<h4>YAML</h4>
<p><a href="http://www.yaml.org/">YAML</a>, pronounced to rhyme with "camel", is a recursive acronym meaning "YAML Ain't Markup Language". Whereas JSON is a more minimal data format than XML, YAML takes minimalism to an extreme, eschewing quotation marks, brackets and curly braces altogether in favour of significant indentation and line breaks.</p>
<p>The YAML equivalent to the XML and JSON contact examples above would be:</p>
<pre><code>firstName: John
lastName: Smith
age: 25
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021
phoneNumber:
- type: home
number: 212 555-1234
- type: fax
number: 646 555-4567
</code></pre>
<p>That works out to just 239 characters - including the significant white space.</p>
<hr />
<p><em>Special thanks to <a href="http://socialtech.ca/ade">Adrian Duyzer</a> for reading a draft of this essay and setting me straight on the respective roles of PUT and POST.</em></p>
Ryan McGreal2http://quandyfactory.com/site/13/about2010-06-22T12:00:00ZAbout
<h3>Introduction</h3>
<p>My name is Ryan McGreal, and I live in Hamilton, Ontario, Canada with my family. I work as a web programmer, consultant, writer, editor and troublemaker, though it's mostly the programming that pays the bills. </p>
<h4>Raise the Hammer</h4>
<p>My principal activity that <em>doesn't</em> pay the bills is my role as editor of <a href="http://raisethehammer.org">Raise the Hammer</a>, an online magazine dedicated to sustainable urban revitalization in Hamilton. I also work as the city editor at <a href="http://hmag.ca">H Magazine</a>.</p>
<h4>Hamilton Light Rail</h4>
<p>I am also a proud founding member of <a href="http://hamiltonlightrail.com">Hamilton Light Rail</a>, a community group dedicated to bringing light rail transit to Hamilton.</p>
<h4>Published Essays</h4>
<p>I have written several essays on urban issues that have been published in the <em>Hamilton Spectator</em> and elsewhere over the past five years.</p>
<h4>Contact</h4>
<p>You can reach me via email at <a href="mailto:ryan@quandyfactory.com">ryan@quandyfactory.com</a>.</p>
<h3>This Site</h3>
<p>This is my personal website, repository of essays and projects, and playground for new ideas. </p>
<p><em>Quandy</em> is a portmanteau of "Quick and Dirty", which can be a useful method of approaching problems. "Quick and dirty" has the benefit of being, well, quick, as well as flexible for those cases when initial requirements end up changing (i.e. just about every nontrivial project). </p>
<p>It suggests an iterative approach, on the reasoning that it's easier to build something simple and then make it better than it is to try and spring a fully-formed application from your forehead. </p>
<p>As John Gall famously stated: </p>
<blockquote>
<p>A complex system that works is invariably found to have evolved from a simple system that worked. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work.</p>
</blockquote>
<h3>Eye Quandy</h3>
<h4>Quandy Logo</h4>
<p>The red Quandy logo in the top left corner is courtesy of <strong>Trevor Shaw</strong>, a great local graphics designer and the creative director of <a href="http://www.getjuice.ca/">Juice Creative</a>.</p>
<h4>Footer Image</h4>
<p>The awesome cityscape panorama in the footer was taken by the talented photographer and amateur urbanist <strong>Aaron Segaert</strong>, and is used with permission.</p>
<h3>Interests</h3>
<p>In recent years I have been particularly interested in: the nature of city economies and urban development; the role of public participation and community engagement in creating and sustaining a healthy society; and ways to increase the openness, transparency and responsiveness of organizational governance and policy making.</p>
<h4>Conceptual Overlap</h4>
<p>I admit that my ideas about openness in government and policy making reflect my experience using and developing software: an open, information-sharing approach with peer review results in better results than a closed, proprietary approach based on blind trust.</p>
<h4>Jack of All Trades</h4>
<p>My interests take me all over the place, figuratively, from land use patterns and transportation modes to the global energy situation, geopolitics, social policy, economics and political economy, democratic structures and traditions, broad-based community organizing, local politics and current affairs, architecture, city life, ecology, sustainability, cognitive psychology, and more.</p>
<p>I don't claim expertise in any of these areas, but I am committed to studying the experts and following empirical best practices in these domains. </p>
<h4>Benefit from Shared Expertise</h4>
<p>The great thing about living in an open, knowledge-based culture is that you can benefit from the expertise of others. Once you establish the credibility of expertise, you can use it as a kind of knowledge <a href="http://en.wikipedia.org/wiki/Application_programming_interface">API</a> that allows you to take advantage of the expertise without necessarily knowing everything about the internals.</p>
<p>If not for this ability for non-experts to access expertise, there would be no way for the benefits of that expertise to disseminate into the broader society and inform our policy decisions.</p>
<h3>Programming</h3>
<p>I enjoy programming and have benefited immensely from the vast, rich ecosystem of free and open source software available to programmers today (see "Technical Notes", below).</p>
<h4>Great Time for OK Coders</h4>
<p>I know enough about great programmers and their remarkable contributions to understand that I am not a great programmer. Nevertheless, the rich ecosystem of programming languages, libraries, frameworks and tools means even a duffer like me can be creative and productive - and that's a <a href="http://c2.com/cgi-bin/wiki?GoodThing">Good Thing</a>.</p>
<h4>Productive Modern Languages</h4>
<p>One of the great things about modern programming languages is how highly expressive they are. You can create working code very efficiently, with a minimum of boilerplate. </p>
<p>That means it's easy to develop simple tools that do exactly what you want them to do and no more - and to do them quickly.</p>
<h4>Shared Open Source Software</h4>
<p>Recently I have begun releasing a few such handy tools under a free software / open source licence. You can find my shared resources hosted on <a href="http://github.com/quandyfactory">GitHub</a>. </p>
<p>The code isn't beautiful, but I'm <a href="http://code.google.com/events/io/sessions/MythGeniusProgrammer.html">no genius</a>.</p>
<h3>Website Development</h3>
<p>I do a bit of freelance web application development. Feel free to contact me via email at <a href="mailto:ryan@quandyfactory.com">ryan@quandyfactory.com</a> to inquire about services and rates.</p>
<h4>Outsourced Graphic Design</h4>
<p>I am not a graphic designer, and my own website design tends to the very minimal. However, I do have a good working relationship with a talented graphic designer who can design the layout and colour scheme to reflect your organization.</p>
<p>I am also happy to work with a design that you provide.</p>
<h3>Technical Notes</h3>
<p>There's no particularly good reason why I didn't simply use WordPress or Drupal or some other off-the-shelf blogging software for this site; except that I enjoy building things (also, PHP makes the baby Jesus cry). </p>
<p>Anyway, it's not like I built the site from scratch.</p>
<ul>
<li><p>It runs on <a href="http://nginx.org/en/">nginx</a> and <a href="http://www.apache.org/">Apache</a> on a <a href="http://www.centos.org/">CentOS</a> <a href="http://www.linux.org/">Linux</a> machine hosted by the awesome admins at <a href="http://webfaction.com?affiliate=hammertime">WebFaction</a>. </p></li>
<li><p>It is written in the <a href="http://python.org">Python programming language</a> and uses the lightweight <a href="http://webpy.org">web.py</a> application development framework. </p></li>
<li><p>Web.py talks to Apache via the <a href="http://code.google.com/p/modwsgi/">mod_wsgi</a> server module, which implements the standard <a href="http://www.wsgi.org/wsgi/">Web Services Gateway Interface (WSGI)</a> specification for Python applications to communicate with web servers.</p></li>
<li><p>The site stores its documents in a <a href="http://dev.mysql.com/">MySQL</a> database, to which it connects via the ingenious <a href="http://www.sqlalchemy.org/">SQLAlchemy</a> database toolkit and object-relational mapper (ORM).</p></li>
<li><p>Documents are saved in <a href="http://daringfireball.net/projects/markdown/">Markdown</a> syntax and converted to HTML for display using the <a href="http://code.google.com/p/python-markdown2/">python-markdown2</a> library (which is itself a re-implementation of the original <a href="http://www.freewisdom.org/projects/python-markdown/">python-markdown</a> library).</p></li>
<li><p>It also uses <a href="/projects/5/quandy">Quandy</a>, a library of handy classes and functions that I use frequently in writing web code. </p></li>
</ul>
<p>In other words, I'm sitting here on the shoulders of giants - and the view is grand!</p>
Ryan McGreal2http://quandyfactory.com/blog/59/ubuntu_1004_first_thoughts2010-05-01T12:00:00ZUbuntu 10.04 First Thoughts
<p>Last night I upgraded my Acer Aspire One from Ubuntu 9.10 to 10.04 (I use the regular edition, not the netbook edition). 10.04 is a Long-Term Support (LTS) release, meaning Canonical promises to support the desktop edition for three years and the server edition (which comes without a GUI layer) for five years.</p>
<p>It took all night to download the upgrade (watching the <em>time remaining</em> on the download status dialog brought me back to the halcyon days of the Windows 95 file-transfer time remaining status) but the upgrade itself was painless.</p>
<p>So far, here's what I think:</p>
<h3>Boot Time</h3>
<p>This is the most immediate, obvious improvement in 10.04. True to their commitment, the Ubuntu developers have made big strides in shaving as much as they can off startup and shutdown times.</p>
<p>Startup is visibly faster than 9.10, which didn't really improve much on 9.04. From the power button through the kernel selection to the login screen runs a cool 35-40 seconds. </p>
<p>Add another six or seven seconds after logging in to bring up the desktop, and another two or three seconds to auto-connect to the local wifi network.</p>
<p>One interesting note: 8.10 and 9.04 displayed long lists of command-line messages during bootup, while 9.10 eliminated that for a splash screen. Now I get command-line messages again, albeit only about eight lines and for only a second or two.</p>
<h3>Shutdown</h3>
<p>Shutdown is even nicer: six seconds flat. </p>
<p>I have only two small gripes with the shutdown process:</p>
<ol>
<li><p>The indicator applet on the panel splits the user menu and shutdown menu into two separate dropdowns, but they still sit right beside each other as if they were a single item. It will take a little getting used to.</p></li>
<li><p>The default behaviour for shutdown is to pop up a confirmation dialog, but like 9.10 you can't right-click on it to access preferences and turn off the dialog. The easiest way to fix this is to open up a terminal and start <code>gconf-editor</code>. (If you don't have it installed, fire up the Ubuntu Software Centre and install Configuration Editor.) Expand "Apps" in the tree menu on the left, select the "indicator-session" setting on the right side and check "suppress_logout_restart_shutdown" to turn off shutdown confirmations.</p></li>
</ol>
<h3>Appearance</h3>
<p>It's not brown. Really, that's the main thing. Beyond that, if you've upgraded after already customizing the appearance of 9.10, most of your settings remain intact (with one notable exception, below).</p>
<p>I tried out the new default Ambiance theme and didn't like it. It's just a little too purple and dreary for me. But as before, you can customize the hell out of your window styles via System -> Preferences -> Appearance.</p>
<h3>Window Controls</h3>
<p>In fairness, the window titlebar button positions are less bad than they were when Canonical first proposed moving them to the left side of the window chrome. In the first iteration, the buttons were in the order <code>[-][_][X]</code>, but in the release version they're in the order <code>[X][_][-]</code> with the close button on the very left. </p>
<p>Yet I just don't see a benefit to moving them to the left side that justifies the aggravation of having to unlearn a habit that goes back nearly 20 years. After all, I originally chose Ubuntu in part because it seemed to be the easiest transition from a background in Windows.</p>
<p>Luckily there's an easy way to fix it. Open a terminal and run <code>gconf-editor</code>. In the tree menu on the left click on Apps -> metacity -> general. Double-click on the "button_layout" setting on the right side and replace the text with: <code>menu:minimize,maximize,close</code> to restore the previous behaviour.</p>
<p>A word of warning: if you go into System -> Preferences -> Appearance and change the theme, the window buttons will reset to the left side again.</p>
<h3>Wifi</h3>
<p>Ubuntu 8.10 and 9.04 were a bit painful to get wifi working on an Aspire One. The <em>only</em> thing that worked for me was to download madwifi and compile from source. Every time a major system update installed, I had to reinstall madwifi (<a href="https://help.ubuntu.com/community/CheckInstall">checkinstall</a> didn't work for me).</p>
<p>This changed with 9.10, in which wifi Just Worked, and it still works in 10.04. In fact, it seems to connect considerably faster now - and the little connection icon in the NetworkManager applet looks prettier than the previous one. (With the icon in 9.10, I always had to double-check whether I was looking at the wifi or battery status.)</p>
<h3>Ubuntu One</h3>
<p>I decided to try out Ubuntu One, Canonical's cloud storage offering. Roughly equivalent to significant players (e.g. Dropbox), Ubuntu One offers 2 GB of cloud storage for free with the option to buy 50 GB for $10 per month. Also like Dropbox, you can share individual files and folders publicly.</p>
<p>Note: you access Ubuntu One through your Me menu, not through System -> Administration or System -> Preferences.</p>
<p>Setting up an account is easy enough, though the web interface felt slow and unstable. Actual syncing seems pretty smooth, though I haven't yet had a chance to try and modify files using different systems at the same time. More to come as I play with this.</p>
<p>The syncing options seem fairly impressive. You can even install a Firefox addon to sync your bookmarks.</p>
<p>Ubuntu One also comes with a music store provided by 7Digital. The selection is passable if nowhere near exhaustive, and the prices are not bad. I'd rather see songs in the $0.25-$0.50 range - for me, that's the break-even point against the opportunity cost of downloading free music - but we're moving in the right direction.</p>
<p>The music store also provides MP3s, which will grate Free Software purists but serves the rest of us just fine.</p>
<p>The store integrates closely with the Rhythmbox music player, which suffers most of the aggravations of a full-featured music player but at least can boast that it's not nearly as bloated or clumsy to use as iTunes.</p>
<p>For iPod users who are sick of iTunes and/or itching to run Linux instead of Mac or Windows, you can actually use Rhythmbox to load and sync your iPod.</p>
<h3>Firefox</h3>
<p>There was a hullabaloo when Canonical announced that they were switching the default search engine on Ubuntu Firefox from Google to Yahoo, but they switched back before the final release. Hey, money talks when you're giving your product away for free.</p>
<p>As for Firefox itself, Ubuntu 10.04 ships with version 3.6.3. The lag between Firefox releases and the version available through Ubuntu's package manager was a fairly long-standing aggravation, which led to workarounds like Ubuntuzilla to get newer versions working. </p>
<p>I hope this is a sign that Canonical is committed to staying on top of new Firefox releases.</p>
<h3>Problems</h3>
<p>I only had two real software failures.</p>
<p>Brasero flat-out stopped working, returning an "unknown error" on any attempt to burn a CD or DVD. It looks like a lot of people are having this problem. Sooner than try to fight my way to a fix, I just started using Gnomebaker instead.</p>
<p>Gtk-Gnutella also stopped working. The version in the Lucid repository is two points behind the current version and throws an "ancient version detected" alert; it also fails to connect to the filesharing network. </p>
<p>My attempts to compile the newest version from source (I tried both checkinstall and a straight compilation) produced an application that would crash seconds after opening. I finally gave up and switched to Frostwire.</p>
<p>Otherwise, everything continued to work as expected.</p>
<h3>Summary</h3>
<p>There's certainly a lot more to explore before I've gotten to the bottom of this new edition, but so far I'm impressed. It's fast, solid and stable to use, the ratio of Just Works to Needs Hacking is approaching 1:0, the upgrade retained most of my previous settings without breaking anything, and several gripes I previously had with Ubuntu have been resolved. </p>
<p>Aside from a few annoyances that are fairly easy to work around, I have no major complaints.</p>
Ryan McGreal2http://quandyfactory.com/projects/56/makechart2010-04-27T12:00:00ZMakeChart
<p>Check out the <a href="http://github.com/quandyfactory/MakeChart">Github repository</a> for source and documentation.</p>
<p>Here's an example use, assuming you save makechart.py somewhere in your PATH:</p>
<pre><code>try: import json
except: import simplejson as json
import urllib
import makechart
# chart with world petroleum production data by month from EIA
url = 'http://quandyfactory.com/json/makechart'
output = urllib.urlopen(url)
contents = output.read()
dataset = json.loads(contents)
caption = 'World Oil Production by Month, 2001-2010<br>(Source: EIA)'
unit = 'mbpd'
chart = makechart.make_chart(dataset, caption, unit)
html = makechart.make_html(chart)
file = open('makechart_example.html', 'w')
file.write(html)
file.close
</code></pre>
<p>Note: for the sake of convenience, this example uses a sample dataset in JSON format that is <a href="/json/makechart">hosted on this website</a>.</p>
Ryan McGreal2http://quandyfactory.com/blog/54/shared_awareness:_a_better_way_to_manage_comment_trolls2010-04-15T12:00:00ZShared Awareness: A Better Way to Manage Comment Trolls
<h3>Trolling</h3>
<p>As everyone who has spent more than five minutes on the internet knows, in the absence of personal accountability, some people inevitably turn into assholes.</p>
<p class="image">
<img src="/static/images/internet_dickwad_theory.gif" alt="John Gabriel's Greater Internet Dickwad Theory" title="John Gabriel's Greater Internet Dickwad Theory"><br>
<a href="http://www.pennyarcademerch.com/pat070381.html">
John Gabriel's Greater Internet Dickwad Theory
</a>
</p>
<p>Not many, mind you, but even one determined troll on an internet forum can be enough to bring the entire affair crashing down.</p>
<p>The term "troll" comes originally from the fishing method of dangling a shiny lure out the back of a boat while putting along just quickly enough to grab the interest of a fish. The fish that can't resist the lure is snared on the hook and eaten.</p>
<p>(Of course, the term also connotes ugly, hairy brutes who lurk under bridges waiting to snatch unwary passers-by.)</p>
<p>Trolls posting anonymously on message boards absolutely <em>love</em> to provoke outrage. The troll's objective is not to change anyone's mind; rather, it's to write in such a way as to elicit a sequence of increasingly angry, frustrated replies that drag the discussion further and further off-topic until the original thread is in shambles.</p>
<p>Crude trolls subsist on the meager attention given to their vulgarity; but sophisticated trolls can keep a debate going for days by dancing on the fine line between feigned reasonableness and deliberate obtusity. They are by far the more damaging to online discourse.</p>
<p>What makes trolls disruptive is not the trollish comments themselves, but the chain of outraged replies they manage to elicit. </p>
<p class="image">
<img src="/static/images/xkcd_duty_calls.png" alt="Duty Calls" title="What do you want me to do? LEAVE? Then they'll keep being wrong!"><br>
<a href="http://xkcd.com/386/">
Duty Calls
</a>
</p>
<p>Successfully managing trolls requires understanding why this happens and breaking the chain of replies.</p>
<h3>Shared Awareness</h3>
<p>Trolls attract replies by exploiting the general absence of <strong>shared awareness</strong> on most mediated communications platforms. Shared awareness is a special state of meta-knowledge among collaborators that allows them to act cooperatively on the knowledge.</p>
<p>If I know something and you know something but I don't know that you know it and you don't know that I know it, we can't build on that knowledge even though we both know the same thing.</p>
<p>Shared awareness is not reached until: I know something, you know something, I know that you know, you know that I know, I know that you know that I know, and you know that I know that you know. (Whew!)</p>
<p>Once we all know that we all know the thing, we can then act on it. Without that shared awareness, our ability to put the information to use is sharply curtailed.</p>
<p>Now, sometimes the absence of shared awareness is a blessing. There are many potentially socially awkward situations - say, someone in a room full of people passes wind - in which the absence of shared awareness of who farted means everyone can take a position of <a href="http://en.wikipedia.org/wiki/Plausible_deniability">plausible deniability</a>. </p>
<p>Not only does the culprit avoid embarrassment, but also the other parties don't have to deal with the discomfort of having to address the fact that one of them farted. After all, most people don't like confrontations.</p>
<h3>Someone is Wrong on the Internet!</h3>
<p>In a conventional online comment system, several participants may each know something, but they do not necessarily have shared awareness about it (everyone knows that everyone knows).</p>
<p>When a troll posts a comment, for example, other participants may decide independently that the comment is inappropriate and/or wrong and/or offensive, but they have no way of knowing whether anyone else feels the same way.</p>
<p>A conscientious forum-goer could just ignore the troll and hope for the best, but <em>silence is affirmation</em>, and a comment left to stand unchallenged starts to look like it represents the prevailing view of the forum participants.</p>
<p>Hence, the conscientious forum-goer feels no choice but to reply to the troll, if only to assure others that at least someone else disagrees with it. </p>
<p>Now the fish is hooked, and a skillful troll can keep that fish on the line for a long time. </p>
<h3>Collateral Damage</h3>
<p>In the meantime, other fish get scared away by the thrashing. </p>
<p>Pointless, unending debates between trolls and earnest opponents do two things:</p>
<ol>
<li>They disrupt and crowd out legitimate discussion; and</li>
<li>They deter other potential commenters from getting involved, lest they be trolled as well.</li>
</ol>
<p>Eventually, the community starts to dissipate altogether. At this point, the troll - really, a parasite (if you'll forgive the switched metaphor) - abandons the dying host and sets off in search of a fresh victim.</p>
<p>The important thing to remember is that the damage takes place not only because the troll posts a comment <em>but also because an earnest commenter decides to reply</em>. </p>
<p>In turn, earnest commenters get into it with trolls because in the absence of shared awareness, they have no other way to know whether the community as a whole accepts or rejects the troll's arguments. </p>
<p>Worst of all, the very dialogue with the troll, undertaken for the purpose of invalidating the troll's position, actually deters others from sharing their own positions and clearing up the matter.</p>
<h3>Three Points of Attack</h3>
<p>The three necessary conditions for a troll disrupting a forum are:</p>
<ol>
<li>An absence of shared awareness;</li>
<li>A troll; and</li>
<li>A well-meaning opponent to debate with the troll.</li>
</ol>
<p>It's safe to generalize that any online forum will have both trolls and well-meaning opponents willing to debate with them. Since most online forums also don't have shared awareness, that means all three necessary conditions are likely to be present and disruption is likely to follow.</p>
<p>Since all three conditions are <em>necessary</em> for disruption to take place, we have three points of attack in trying to prevent it:</p>
<ol>
<li>Establish shared awareness;</li>
<li>Block the trolls; or</li>
<li>Block the well-meaning replies.</li>
</ol>
<p>Of the three options, #1 is the most promising. If you can establish a shared awareness that the troll is inappropriate - i.e. everyone knows that everyone knows that the troll is not representative - then well-meaning opponents no longer feel obliged to reply. </p>
<p>In turn, since the objective of a troll is to provoke replies, a troll who can't get anyone to take the bait will eventually give up and move on to another forum.</p>
<p>So how do we go about establishing shared awareness on a text-based communications forum?</p>
<h3>Clear Understanding of Rules</h3>
<p>The first step to shared awareness is for everyone on the forum to have a clear understanding of the rules and a clear set of expectations on now to behave and how others should behave. It's not enough just to say of trolling that <a href="http://en.wikipedia.org/wiki/I_know_it_when_I_see_it">we know it when we see it</a></p>
<p>The rules should be simple, straightforward, fair, and agreeable to the members. Ideally, they should participate in determining what the rules will be. That way, the members have a sense of investment and ownership in the policies that govern their actions on the forum.</p>
<p>However, the rules should probably include some variation on the following:</p>
<ul>
<li>Maintain a civil and polite tone, even when disagreeing with someone.</li>
<li>Argue from evidence and cite your sources.</li>
<li>Do not use rude or insulting language.</li>
<li>Do not post comments that are needlessly inflammatory, seek to provoke an emotional reaction from others, are attempts to disrupt and derail the discussion, or abuse evidence and reasoning to defend an unjustifiable conclusion.</li>
<li>Do not post comments that are off-topic.</li>
</ul>
<p>The important thing is that the participants feel invested in community standards that define them as civil, reasonable and responsible. Again, most people - even on the internet - like to think of themselves in these terms and actually value the personal exchanges they get to have on socially functional online forums.</p>
<p>A pseudonymous screen name might be less personal than a real name, but it still inheres to a real personal identity, and people can still form relationships while communicating on the internet - <em>if</em> their community is successful in establishing and maintaining a shared awareness of their values.</p>
<h3>Communicate Without Posting a Reply</h3>
<p>By themselves, codes of conduct are only useful insofar as people see them being applied fairly and consistently. </p>
<p>For inappropriate comments, there needs to be a mechanism for members of the community to <em>flag them as inappropriate</em> without actually posting replies; and that flag must be <em>visible to everyone</em> so that an individual looking at the comment can see how many other people have already flagged it.</p>
<p>If you have used <a href="http://reddit.com">reddit</a>, <a href="http://digg.com">Digg</a>, or <a href="http://news.ycombinator.com">Hacker News</a>, you may have already have experienced such a mechanism at work. In these three link sharing sites, registered users can up-vote or down-vote both submitted articles and user comments. </p>
<p>While each site works a little bit differently, a given article's or comment's score reflects some combination of the number of upvotes, the number of downvotes, the 'reputations' of the users who assigned upvotes and downvotes, and the amount of time that has passed since the article or comment was posted. </p>
<p>Some sites introduce an additional constraint in that registered users do not gain the ability to downvote comments until after they have first attained a minimum threshold of reputation based on how other users have upvoted and downvoted <em>their</em> articles and comments.</p>
<p>Hacker News also starts fading the text colour of comments with net negative scores. The benefit to this is that it sends a strong visual message about how the community feels about the comment.</p>
<h3>Remove the Incentive</h3>
<p>So what happens after you implement this form of community moderation? Earnest, well-meaning commenters can see for themselves that the community has rejected a troll and hence no longer feel obliged to set the record straight in a reply. </p>
<p>Eventually, the troll gets bored at not being able to elicit any more replies and moves on.</p>
<p>This is the key to successful community moderation: <strong>establishing shared awareness removes the incentive to reply to trolls, which in turn removes the incentive to troll</strong>.</p>
<p>To borrow a phrase from <a href="http://en.wikiquote.org/wiki/John_Gilmore">John Gilmore</a>, the other forum members learn to treat the trolls as damage and route around them. Eventually the trolls give up.</p>
<p>It might take a while to establish shared awareness, but the forum admins must be patient and remain steadfast in the face of what is likely to be frenetic opposition from the trolls before they finally quit. </p>
<p>Have no doubt: the trolls will immediately understand what is happening, and will fight to undermine it with every rhetorical tool at their disposal, accusing you of censorship, tyranny, megalomania and anything else they can think of. They will fling a litany of abuse at you in the hope that some of it will stick.</p>
<h3>Free and Voluntary</h3>
<p>The best way to fend off these attacks is to ensure that the moderation is free, voluntary, and non-censoring. The following guidelines seem to work well:</p>
<ol>
<li><p>Regularly reinforce community standards by having the policy displayed prominently on the site and reminding users of their important role in maintaining those standards.</p></li>
<li><p>Troll comments can visually represent the negative judgments of their peers - for example by fading in colour or shrinking in size in proportion to the negativity of their score - but they should not disappear completely. (Note: it's reasonable to make an exception for spam and just delete it.)</p></li>
<li><p>Moderation ought to apply directly to comments, not to the users making them. People respond to incentives, and some trolls actually stop trolling and start participating responsibly when their trolls are voted down but their fair posts are voted up.</p></li>
<li><p>Similarly, blacklisting trollish users generally doesn't work. As long as it's easy to create <a href="http://en.wikipedia.org/wiki/Sockpuppet_%28Internet%29">sockpuppet accounts</a> with throwaway email addresses, forums behave like badly applied wallpaper: when you push a bubble down, it just pops up somewhere else.</p></li>
</ol>
<h3>Censorship</h3>
<p>Finally, a few words on censorship as an alternative method of blocking trolls:</p>
<p>Censorship is a slippery slope. Deciding which comments to delete is ultimately a judgment call, and people who are emotionally invested in the success of a forum are notoriously poor at remaining objective and applying standards consistently. </p>
<p>There's a risk that legitimate comments will get the axe. Even worse, there's a risk that an atmosphere of censorship will deter people from participating - the very problem that moderation was introduced to solve!</p>
<p>Finally, censorship gives the trolls strong rhetorical ammunition to accuse you of heavy-handedness and elicit sympathy from other participants. The perceived lack of transparency over which comments are acceptable puts everyone into an oppositional stance, and the trolls will be watching carefully for examples of hypocrisy.</p>
<p>Both philosophically and practically, censorship is at least as harmful as its targets. It depends naively on the consistent objectivity and benevolence of the moderators, introduces a <a href="http://en.wikipedia.org/wiki/Chilling_effect_%28term%29">chilling effect</a> on participants who may hold legitimate beliefs that break with the majority, and arms trolls with a credible claim that their rights are being violated.</p>
Ryan McGreal2http://quandyfactory.com/projects/40/pytoc2010-04-15T12:00:00ZPyToc
<h3>Introduction</h3>
<p>PyToc generates a table of contents for an HTML document based on headings, with anchor links from the TOC to specific headings.</p>
<h3>Download</h3>
<p>You can download the latest version of PyToc from its github repository:</p>
<ul>
<li><a href="http://github.com/quandyfactory/PyToc">http://github.com/quandyfactory/PyToc</a></li>
</ul>
<h3>Requirements</h3>
<ul>
<li>Python 2.5 or 2.6</li>
<li><a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> 3.0.8</li>
</ul>
<h3>Using PyToc</h3>
<p>You can see the code in action on this very page!</p>
<p>It's pretty simple to use. <a href="http://github.com/quandyfactory/PyToc">Download</a> <code>pytoc.py</code> and save it somewhere in your PATH. </p>
<p>Here's a demonstration:</p>
<pre><code>>>> import urllib
>>> import pytoc
>>> url = 'http://quandyfactory.com/projects/40/pytoc'
>>> page = urllib.urlopen(url)
>>> html = page.read()
>>> toc = pytoc.Toc(html_in=html)
>>> toc.make_toc()
True
>>> toc.html_toc # returns an HTML table of contents
>>> toc.html_out # returns the html with anchors and numbering in headings
>>> toc.toc_list # returns a list of tuples in the form (section number, title)
</code></pre>
<h4>Input Properties</h4>
<p>The following are input properties you enter to generate the table of contents.</p>
<ul>
<li><p><code>html_in</code> - The HTML document for which you want to generate a table of contents.</p>
<p>This is the only necessary property to assign. The rest have default values that may meet your needs.</p></li>
<li><p><code>levels</code> - A list of numbers corresponding to the heading levels you want to include in your TOC.</p>
<p>E.g. [3, 4] would include <code><h3></code> and <code><h4></code> headings. Default is [3, 4].</p></li>
<li><p><code>id</code> - The base id of the HTML table of contents to be generated. Default is "toc".</p></li>
<li><p><code>title</code> - The title of the generated table of contents. Default is "Contents".</p></li>
</ul>
<h4>Methods</h4>
<ul>
<li><code>make_toc()</code> - this generates the table of contents and populates the output properties. Returns True when complete.</li>
</ul>
<h4>Output Properties</h4>
<p>After calling the <code>make_toc()</code> method, the following output properties are populated with values.</p>
<ul>
<li><p><code>html_out</code> - The same as <code>html_in</code> except with the TOC anchors and numbering included in the headings.</p></li>
<li><p><code>html_toc</code> - The generated HTML table of contents.</p></li>
<li><p><code>toc_list</code> - A list of tuples containing the anchors and headings, in case you would rather roll your own HTML table of contents.</p></li>
</ul>
<p>That's it, really.</p>
<h3>History</h3>
<p>This library started out as one-off code to generate a table of contents for a long document that I'm converting from MS Word format over to HTML. </p>
<p>The existing Word document has had many contributors and editors over the years and the format is a shambles. The table of contents is a mess and the headings are all over the place. (Thanks, WYSIWYG.) </p>
<p>I converted the whole thing into <a href="http://daringfireball.net/projects/markdown/" title="John Gruber's Markdown">Markdown</a>, a simple plain-text formatting syntax that converts to clean, structural HTML. </p>
<p>I still wanted the final document to have a table of contents, but I didn't want to have to go through the bother of maintaining the thing - especially if I ever wanted to add a new section in the middle, which would require a re-numbering of all the subsequent sections and subsections.</p>
<p>I whipped up a simple parser that walked the document and dynamically generated a table of contents, plus anchors in the document so the section headings listed in the contents could straight down to the sections themselves.</p>
<h3>Need for Flexibility</h3>
<p>It worked, but the code was brittle. It required the HTML formatting to be very strict, e.g. the following would work:</p>
<pre><code><h3>Some subheading title</h3>
</code></pre>
<p>but the following would not work:</p>
<pre><code><h3>
Some subheading title
</h3>
</code></pre>
<p>Documents generated using <a href="http://code.google.com/p/python-markdown2/">python-markdown2</a> would work pretty consistently, but documents generated using, say, <a href="http://www.freewisdom.org/projects/python-markdown/">python-markdown</a> would not, since the latter produces messier HTML output. </p>
<p>Of course, with documents produced using other means, all bets were off.</p>
<p>Anyway, I decided that if this was going to be at all useful as a general-purpose tool, it needed to be more flexible and forgiving. Of course, if you're programming in python, parsing HTML and want to be flexible and forgiving, there's no better tool than the mighty <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> parsing library.</p>
<p>So I re-wrote it using BeautifulSoup.</p>
Ryan McGreal2http://quandyfactory.com/projects/51/pycouchcontacts2010-04-12T12:00:00ZPyCouchContacts
<p>Coming soon.</p>
Ryan McGreal2http://quandyfactory.com/blog/50/couchdb_working_notes2010-04-09T12:00:00ZCouchDB Working Notes
<p>Note: this article is very much a work in progress. It functions mainly as a place where I can document what I learn about CouchDB as I play around with it and get a progressively better sense of what it does and how it works.</p>
<h3>Summary</h3>
<p>CouchDB is a non-relational database server built in Erlang that stores its data as JSON and communicates RESTfully over HTTP.</p>
<h3>Install CouchDB</h3>
<p>First, you need to install CouchDB. If you're using a civilized operating system with a package manager, this won't be difficult.</p>
<pre><code>ryan@home ~$ sudo apt-get install CouchDB
</code></pre>
<p>The package manager will install CouchDB and all its dependencies. The installation script will finish with this hopeful line:</p>
<pre><code> * Starting database server CouchDB
</code></pre>
<p>That's it. Couch is up and running.</p>
<h3>RESTful API</h3>
<p>The first thing to know about CouchDB is that it that you connect to it over HTTP using the standard HTTP "verbs" like GET, PUT, POST and DELETE - the very same protocol that browsers use to connect to web servers. </p>
<p>This is important to understand: you don't need database drivers or clients or anything else to interact with CouchDB. You just need to be able to send an HTTP request to the CouchDB server and receive the response.</p>
<p>You can prove this by opening your browser and navigating to <a href="http://localhost:5984">http://localhost:5984</a>. It should return something like this:</p>
<pre><code>{"CouchDB": "Welcome", "version": "0.10.0"}
</code></pre>
<p>So far, so good. But what are you looking at?</p>
<h3>JSON</h3>
<p>If you've built any Ajax web apps in the past few years, the output from the CouchDB web server should be familiar to you. It's <a href="http://json.org/">JSON</a>, or JavaScript Object Notation, the lightweight data format introduced by Douglas Crockford. </p>
<p>(BTW if you write JavaScript but haven't read Crockford's book <cite><a href="http://www.amazon.ca/exec/obidos/ASIN/0596517742/wrrrldwideweb">JavaScript: The Good Parts</a></cite>, I highly recommend it. Chances are you're Doing It Wrong today.)</p>
<p>JSON is based on JavaScript object literal notation, a method of creating objects in JavaScript by literally describing their properties and methods:</p>
<pre><code>myObject = {
name: "Ryan McGreal",
age: 36,
emails: ["ryan@quandyfactory.com", "editor@raisethehammer.org"],
doSomething: function() {
alert("This is a useful method!");
}
}
</code></pre>
<p>JSON supports arrays and dictionaries with nesting and various data types (number, string, boolean, array, object and null). It also supports schemas. </p>
<p>A major advantage over XML is that the syntax is much simpler and less verbose, which makes it lighter across networks as well as more human-readable.</p>
<p>While it's possible to evaluate JSON as JavaScript using <code>eval()</code>, it's not recommended (for what I hope are obvious reasons). It's much better to use a JSON parser. </p>
<p>The good news is that there are already JSON parsers for wide range of programming languages in addition to JavaScript. Python, for example, <a href="http://docs.python.org/library/json.html">includes the <code>json</code> module</a> as part of the standard library (as of version 2.6). There are also libraries for PHP, Ruby, Perl, Java, Scala, Erlang, Common Lisp, and Clojure, among others.</p>
<h3>Create a CouchDB Database</h3>
<p>Given that you connect to CouchDB over HTTP, it should not surprise you to learn that you execute actions against CouchDB using the HTTP request method 'verbs': GET, PUT, POST and DELETE. </p>
<p>As a result, any programming language that can communicate over HTTP can connect to a CouchDB server.</p>
<p>Let's create a new database. For simplicity's sake I'll connect to the CouchDB server on the command line using <a href="http://curl.haxx.se/">curl</a>. The -X command line argument specifies which HTTP request method to use.</p>
<pre><code>ryan@home ~$ curl -X PUT http://localhost:5984/mydb
</code></pre>
<p>CouchDB returns the following response (in JSON format, or course):</p>
<pre><code>{"ok": true}
</code></pre>
<p>You now have a CouchDB database called <code>mydb</code>. Prove it by running a GET request against the URL for your database:</p>
<pre><code>ryan@home ~$ curl -X GET http://localhost:5984/mydb
</code></pre>
<p>Check it out: your database has a URL!</p>
<p>CouchDB will return a summary of the database properties (I've added whitespace to the CouchDB JSON responses to aid readability):</p>
<pre><code>{
"db_name": "mydb",
"doc_count": 0,
"doc_del_count": 0,
"update_seq": 0,
"purge_seq": 0,
"compact_running": false,
"disk_size": 79,
"instance_start_time": "1276950495049303",
"dis_format_version": 4
}
</code></pre>
<p>Notice the <code>doc_count</code> property of 0. We should fix that by adding a document. </p>
<h3>Add a Document</h3>
<p>You add documents to a database using the HTTP POST method (the same method HTML forms use to send form data to the server).</p>
<pre><code>ryan@home ~$ curl -X POST http://localhost:5984/mydb \
--header 'Content-Type: application/json' \
--data '{"title": "My First CouchDB Document", "author": "Ryan McGreal", \
"date_posted": "2010-04-09 11:38:26", "section": "blog", \
"content": "This is my first-ever CouchDB document. Niiice." }'
</code></pre>
<p>CouchDB returns a response like the following:</p>
<pre><code>{
"ok": true,
"id": "bf58234234aed2389dcb23423",
"rev": "1-4ac239847fea987bd2340"
}
</code></pre>
<p>Let's take a look at what just happened. </p>
<p>We executed an HTTP POST request with a Content-Type header of "application/json" (since we're sending the data in JSON format) and a JSON object for the posted data. The JSON object includes the following keys and values:</p>
<ul>
<li><strong>title</strong>: My First CouchDB Document</li>
<li><strong>author</strong>: Ryan McGreal</li>
<li><strong>date_posted</strong>: 2010-04-09 11:38:26</li>
<li><strong>section</strong>: blog</li>
<li><strong>content</strong>: This is my first-ever CouchDB document. Niiice. </li>
</ul>
<p>CouchDB accepted the JSON object, parsed it to ensure that it's valid JSON, and then created a document in the mydb database with the content you provided. </p>
<p>It also issued the document with an ID and a revision ID, which it included in the response so that you can access the document later. </p>
<p>The revision ID is additionally beneficial: you've got version control built into your database. CouchDB also serves revision numbers as HTTP ETags, so you can take advantage of caching.</p>
<h3>View a Document</h3>
<p>Let's take a look at the document we just created.</p>
<pre><code>ryan@home ~$ curl -X GET http://localhost:5984/mydb/bf58234234aed2389dcb23423
</code></pre>
<p>Your document has a URL, too!</p>
<p>CouchDB returns the following response:</p>
<pre><code>{
"ok": true,
"id": "bf58234234aed2389dcb23423",
"rev": "1-4ac239847fea987bd2340",
"title": "My First CouchDB Document",
"author": "Ryan McGreal",
"date_posted": "2010-04-09 11:38:26",
"section": "blog",
"content": "This is my first-ever CouchDB document. Niiice."
}
</code></pre>
<p>There it is. You can access its properties and values just like you would a recordset. </p>
<p>The difference is that the CouchDB data is formatted in JSON and can be nested - i.e. an object's property could be an array or another object with its own keys and values - rather than forced into a flat table.</p>
<h3>Add Another Document</h3>
<p>Let's try adding a document with nested data:</p>
<pre><code>ryan@home ~$ curl -X POST http://localhost:5984/mydb \
--header 'Content-Type: application/json' \
--data '{"title": "Some Handy Links", "author": "Ryan McGreal", \
"links": ["http://quandyfactory.com", "http://raisethehammer.org", \
"http://hamilton350.com"]}'
</code></pre>
<p>CouchDB responds:</p>
<pre><code>{
"ok": true,
"id": "e6ed2389dcb26100caeg3423",
"rev": "1-7c21a0fd39fea987bd2340"
}
</code></pre>
<p>Now we have two documents in our database with different sets of fields - you're not forced to map your data into a standardized set of properties. </p>
<p>If we tried to do this in a traditional RDBMS, our documents table would have to have a <code>links</code> column with a Null value in the first document, as well as a <code>content</code> column with a Null value in the second document.</p>
<p>With CouchDB, you can give your documents arbitrary fields and values depending on what's applicable for each document.</p>
<h3>Update a Document</h3>
<p>[Coming Soon]</p>
<h3>Data Views</h3>
<p>[Coming Soon]</p>
<h3>Misc.</h3>
<p>Let's create another database.</p>
<pre><code>ryan@home ~$ curl -X PUT http://localhost:5984/mydb
</code></pre>
<p>Wait a minute; didn't we just create a database called <code>mydb</code>?</p>
<p>CouchDB returns this response:</p>
<pre><code>{
"error": "file_exists",
"reason": "The database could not be created, the file already exists."
}
</code></pre>
<p>Whew, dodged a bullet there. CouchDB doesn't let you accidentally overwrite an existing database.</p>
<p>At any time you can get an array of all the databases on your server with the following GET request:</p>
<pre><code>ryan@home ~$ curl -X GET http://localhost:5984/_all_dbs
["mydb"]
</code></pre>
<p>There's plenty more, but this should be enough to get you started thinking about how you might use CouchDB in projects whose data models don't necessarily lend themselves to strict relational structures.</p>
<h3>Utils Web Interface</h3>
<p>One last thing: CouchDB also provides a web interface with some handy utilities for navigating around the server and its databases. </p>
<p>Just load <a href="http://localhost:5984/_utils">http://localhost:5984/_utils</a> in your browser to see it.</p>
Ryan McGreal2http://quandyfactory.com/projects/49/gitiot2010-04-07T12:00:00ZGitiot
<p>Gitiot is a really simple cross-platform GUI wrapper for the most minimal useful subset of git's awesome power; i.e. one-button commit and push-to-master for people who want revision control but don't want to learn the command line.</p>
<p>Download the repository on <a href="http://github.com/quandyfactory/Gitiot">github</a>.</p>
Ryan McGreal2