<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>offsetdesign</title>
	<atom:link href="http://www.offsetdesign.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.offsetdesign.co.uk</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 04:13:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The raspberry has landed</title>
		<link>http://www.offsetdesign.co.uk/2012/the-raspberry-has-landed/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-raspberry-has-landed</link>
		<comments>http://www.offsetdesign.co.uk/2012/the-raspberry-has-landed/#comments</comments>
		<pubDate>Tue, 08 May 2012 04:13:11 +0000</pubDate>
		<dc:creator>sstagg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.offsetdesign.co.uk/?p=138</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img title="" class="alignnone" alt="image" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/05/wpid-20120505_130439.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.offsetdesign.co.uk/2012/the-raspberry-has-landed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New york at Christmas</title>
		<link>http://www.offsetdesign.co.uk/2012/new-york-at-christmas/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-york-at-christmas</link>
		<comments>http://www.offsetdesign.co.uk/2012/new-york-at-christmas/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:51:45 +0000</pubDate>
		<dc:creator>sstagg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.offsetdesign.co.uk/?p=89</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-15/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04120-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-16/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04125-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-17/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC041321-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-18/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC041461-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-19/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC041541-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-20/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04171-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-21/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04185-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-22/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04186-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-23/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC041961-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/rockerfeller-2/' title='rockerfeller'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/rockerfeller1-150x150.jpg" class="attachment-thumbnail" alt="rockerfeller" title="rockerfeller" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-24/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03996-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-25/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04011-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-26/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04034-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-27/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04041-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-28/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04044-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-29/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04055-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-30/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04062-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-31/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04071-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-32/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04081-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-33/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04092-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-34/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04101-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-35/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC04106-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-36/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03832-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-37/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03839-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-38/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03864-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-39/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03865-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-40/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03874-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-41/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03902-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-42/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03936-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-43/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03939-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-44/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03946-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-45/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03956-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-46/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03967-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-47/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03978-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-48/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC038054-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-49/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC038102-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-50/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC038142-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-51/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03815-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-52/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC038241-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-53/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC038281-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-54/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03829-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>
<a href='http://www.offsetdesign.co.uk/2012/new-york-at-christmas/sony-dsc-55/' title='SONY DSC'><img width="150" height="150" src="http://www.offsetdesign.co.uk/wp-content/uploads/2012/01/DSC03830-150x150.jpg" class="attachment-thumbnail" alt="SONY DSC" title="SONY DSC" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.offsetdesign.co.uk/2012/new-york-at-christmas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cartesian products in bash?</title>
		<link>http://www.offsetdesign.co.uk/2011/cartesian-products-in-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cartesian-products-in-bash</link>
		<comments>http://www.offsetdesign.co.uk/2011/cartesian-products-in-bash/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 18:02:21 +0000</pubDate>
		<dc:creator>sstagg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cartesian]]></category>
		<category><![CDATA[fish]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.offsetdesign.co.uk/?p=37</guid>
		<description><![CDATA[Given a directory with 2 sub-directories, A and B, this snippet will output: quartz ~/&#62;; ls A B quartz ~/&#62; ls -d1 */../*/ &#124; sed 's;/../;-&#62;;g;s;/;;g' A-&#62;A A-&#62;B B-&#62;A B-&#62;B]]></description>
			<content:encoded><![CDATA[<p>Given a directory with 2 sub-directories, A and B, this snippet will output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">quartz ~<span style="color: #000000; font-weight: bold;">/&gt;</span>; <span style="color: #c20cb9; font-weight: bold;">ls</span>
A B
quartz ~<span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-d1</span> <span style="color: #000000; font-weight: bold;">*/</span>..<span style="color: #000000; font-weight: bold;">/*/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s;/../;-&gt;;g;s;/;;g'</span>
A-<span style="color: #000000; font-weight: bold;">&gt;</span>A
A-<span style="color: #000000; font-weight: bold;">&gt;</span>B
B-<span style="color: #000000; font-weight: bold;">&gt;</span>A
B-<span style="color: #000000; font-weight: bold;">&gt;</span>B</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.offsetdesign.co.uk/2011/cartesian-products-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weighted sampling of items in Python</title>
		<link>http://www.offsetdesign.co.uk/2011/weighted-sampling-of-items-in-python/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=weighted-sampling-of-items-in-python</link>
		<comments>http://www.offsetdesign.co.uk/2011/weighted-sampling-of-items-in-python/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 02:34:36 +0000</pubDate>
		<dc:creator>sstagg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[sampling]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[weighted]]></category>

		<guid isPermaLink="false">http://www.offsetdesign.co.uk/?p=33</guid>
		<description><![CDATA[Let&#8217;s say you need to produce realistically distributed random selections from a list. For example, let&#8217;s say you&#8217;re writing a US meteor simulation game, and want to select the state the meteor will land in. Assuming that the impact site will be completely geographically random, then the following example will select a state, with a [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you need to produce realistically distributed random selections from a list.</p>
<p>For example, let&#8217;s say you&#8217;re writing a US meteor simulation game, and want to select the state the meteor will land in.  Assuming that the impact site will be completely geographically random, then the following example will select a state, with a statistically accurate weighting.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">states = <span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">&quot;Alabama&quot;</span>: <span style="color: #ff4500;">52419</span>,
    <span style="color: #483d8b;">&quot;Alaska&quot;</span>: <span style="color: #ff4500;">663267</span>,
    <span style="color: #483d8b;">&quot;Arizona&quot;</span>: <span style="color: #ff4500;">113998</span>,
    <span style="color: #483d8b;">&quot;Arkansas&quot;</span>: <span style="color: #ff4500;">53179</span>,
    <span style="color: #483d8b;">&quot;California&quot;</span>: <span style="color: #ff4500;">163695</span>,
    <span style="color: #483d8b;">&quot;Colorado&quot;</span>: <span style="color: #ff4500;">104093</span>,
    <span style="color: #483d8b;">&quot;Connecticut&quot;</span>: <span style="color: #ff4500;">5544</span>,
    <span style="color: #483d8b;">&quot;Delaware&quot;</span>: <span style="color: #ff4500;">2489</span>,
    <span style="color: #483d8b;">&quot;District of Columbia&quot;</span>: <span style="color: #ff4500;">68</span>,
    <span style="color: #483d8b;">&quot;Florida&quot;</span>: <span style="color: #ff4500;">65755</span>,
    <span style="color: #483d8b;">&quot;Georgia&quot;</span>: <span style="color: #ff4500;">59425</span>,
    <span style="color: #483d8b;">&quot;Hawaii&quot;</span>: <span style="color: #ff4500;">10931</span>,
    <span style="color: #483d8b;">&quot;Idaho&quot;</span>: <span style="color: #ff4500;">83570</span>,
    <span style="color: #483d8b;">&quot;Illinois&quot;</span>: <span style="color: #ff4500;">57914</span>,
    <span style="color: #483d8b;">&quot;Indiana&quot;</span>: <span style="color: #ff4500;">36418</span>,
    <span style="color: #483d8b;">&quot;Iowa&quot;</span>: <span style="color: #ff4500;">56271</span>,
    <span style="color: #483d8b;">&quot;Kansas&quot;</span>: <span style="color: #ff4500;">82276</span>,
    <span style="color: #483d8b;">&quot;Kentucky&quot;</span>: <span style="color: #ff4500;">40410</span>,
    <span style="color: #483d8b;">&quot;Louisiana&quot;</span>: <span style="color: #ff4500;">51840</span>,
    <span style="color: #483d8b;">&quot;Maine&quot;</span>: <span style="color: #ff4500;">35385</span>,
    <span style="color: #483d8b;">&quot;Maryland&quot;</span>: <span style="color: #ff4500;">12407</span>,
    <span style="color: #483d8b;">&quot;Massachusetts&quot;</span>: <span style="color: #ff4500;">10555</span>,
    <span style="color: #483d8b;">&quot;Michigan&quot;</span>: <span style="color: #ff4500;">96716</span>,
    <span style="color: #483d8b;">&quot;Minnesota&quot;</span>: <span style="color: #ff4500;">86938</span>,
    <span style="color: #483d8b;">&quot;Mississippi&quot;</span>: <span style="color: #ff4500;">48431</span>,
    <span style="color: #483d8b;">&quot;Missouri&quot;</span>: <span style="color: #ff4500;">69704</span>,
    <span style="color: #483d8b;">&quot;Montana&quot;</span>: <span style="color: #ff4500;">147042</span>,
    <span style="color: #483d8b;">&quot;Nebraska&quot;</span>: <span style="color: #ff4500;">77353</span>,
    <span style="color: #483d8b;">&quot;Nevada&quot;</span>: <span style="color: #ff4500;">110560</span>,
    <span style="color: #483d8b;">&quot;New Hampshire&quot;</span>: <span style="color: #ff4500;">9350</span>,
    <span style="color: #483d8b;">&quot;New Jersey&quot;</span>: <span style="color: #ff4500;">8722</span>,
    <span style="color: #483d8b;">&quot;New Mexico&quot;</span>: <span style="color: #ff4500;">121589</span>,
    <span style="color: #483d8b;">&quot;New York&quot;</span>: <span style="color: #ff4500;">54556</span>,
    <span style="color: #483d8b;">&quot;North Carolina&quot;</span>: <span style="color: #ff4500;">53818</span>,
    <span style="color: #483d8b;">&quot;North Dakota&quot;</span>: <span style="color: #ff4500;">70700</span>,
    <span style="color: #483d8b;">&quot;Ohio&quot;</span>: <span style="color: #ff4500;">44825</span>,
    <span style="color: #483d8b;">&quot;Oklahoma&quot;</span>: <span style="color: #ff4500;">69899</span>,
    <span style="color: #483d8b;">&quot;Oregon&quot;</span>: <span style="color: #ff4500;">98380</span>,
    <span style="color: #483d8b;">&quot;Pennsylvania&quot;</span>: <span style="color: #ff4500;">46056</span>,
    <span style="color: #483d8b;">&quot;Rhode Island&quot;</span>: <span style="color: #ff4500;">1545</span>,
    <span style="color: #483d8b;">&quot;South Carolina&quot;</span>: <span style="color: #ff4500;">32020</span>,
    <span style="color: #483d8b;">&quot;South Dakota&quot;</span>: <span style="color: #ff4500;">77353</span>,
    <span style="color: #483d8b;">&quot;Tennessee&quot;</span>: <span style="color: #ff4500;">42144</span>,
    <span style="color: #483d8b;">&quot;Texas&quot;</span>: <span style="color: #ff4500;">268580</span>,
    <span style="color: #483d8b;">&quot;Utah&quot;</span>: <span style="color: #ff4500;">84898</span>,
    <span style="color: #483d8b;">&quot;Vermont&quot;</span>: <span style="color: #ff4500;">9615</span>,
    <span style="color: #483d8b;">&quot;Virginia&quot;</span>: <span style="color: #ff4500;">42774</span>,
    <span style="color: #483d8b;">&quot;Washington&quot;</span>: <span style="color: #ff4500;">71300</span>,
    <span style="color: #483d8b;">&quot;West Virginia&quot;</span>: <span style="color: #ff4500;">24230</span>,
    <span style="color: #483d8b;">&quot;Wisconsin &quot;</span>: <span style="color: #ff4500;">65498</span>,
    <span style="color: #483d8b;">&quot;Wyoming&quot;</span>: <span style="color: #ff4500;">97813</span> <span style="color: black;">&#125;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> weighted<span style="color: black;">&#40;</span>states<span style="color: black;">&#41;</span></pre></div></div>

<p>Here is the function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">collections</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">bisect</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> weighted<span style="color: black;">&#40;</span>items<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># items looks like:  {&quot;A&quot;: 1, &quot;B&quot;: 2, &quot;C&quot;: 10}</span>
    total = <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>items.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    weighted = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#93;</span>
    weights = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    current = <span style="color: #ff4500;">0</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> item, weight <span style="color: #ff7700;font-weight:bold;">in</span> items.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        weighted.<span style="color: black;">append</span><span style="color: black;">&#40;</span>item<span style="color: black;">&#41;</span>
        weights.<span style="color: black;">append</span><span style="color: black;">&#40;</span>current<span style="color: black;">&#41;</span>
        current += weight
    <span style="color: #ff7700;font-weight:bold;">return</span> weighted<span style="color: black;">&#91;</span><span style="color: #dc143c;">bisect</span>.<span style="color: #dc143c;">bisect</span><span style="color: black;">&#40;</span>weights, <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, total-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">test</span><span style="color: black;">&#40;</span>items, samples<span style="color: black;">&#41;</span>:
    factor = samples <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>/<span style="color: #008000;">float</span><span style="color: black;">&#40;</span><span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>items.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    results = <span style="color: #dc143c;">collections</span>.<span style="color: black;">Counter</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>weighted<span style="color: black;">&#40;</span>items<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>samples<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    results = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>item, count / factor<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> item, count <span style="color: #ff7700;font-weight:bold;">in</span> results.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pprint</span>
    <span style="color: #dc143c;">pprint</span>.<span style="color: #dc143c;">pprint</span><span style="color: black;">&#40;</span><span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #dc143c;">test</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;a&quot;</span>: <span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;b&quot;</span>: <span style="color: #ff4500;">2</span>, <span style="color: #483d8b;">&quot;c&quot;</span>: <span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span>, <span style="color: #ff4500;">100000</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.offsetdesign.co.uk/2011/weighted-sampling-of-items-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Less.css and Controlling Element Size</title>
		<link>http://www.offsetdesign.co.uk/2011/less-css-and-controlling-element-size/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=less-css-and-controlling-element-size</link>
		<comments>http://www.offsetdesign.co.uk/2011/less-css-and-controlling-element-size/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 14:11:24 +0000</pubDate>
		<dc:creator>sstagg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[box model]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[less.css]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://wp.offsetdesign.co.uk/?p=22</guid>
		<description><![CDATA[Those of you (implicitly or explicitly) familiar with the css Box model will know that managing the width/height of elements that have padding applied can be a pain.  Getting that number just right after adding borders, subtracting padding, and failing to finger-count is just boring, and error-prone, and that&#8217;s before the guy you&#8217;re designing for requests that [...]]]></description>
			<content:encoded><![CDATA[<p>Those of you (implicitly or explicitly) familiar with the css <a title="Box Model" href="http://www.w3.org/TR/CSS2/box.html" target="_blank">Box model</a> will know that managing the width/height of elements that have padding applied can be a pain.  Getting that number just right after adding borders, subtracting padding, and failing to finger-count is just boring, and error-prone, and that&#8217;s <strong>before</strong> the guy you&#8217;re designing for requests that everything be <em>compressed a bit</em>, or &#8220;just move that text down a pixel or two&#8221;.</p>
<p>One of the best features of <a href="http://lesscss.org/" target="_blank">less.css</a> is the ability to do simple maths with variables.  I&#8217;ve started using a simple pattern for controlling the height of elements more simply.  The variable scoping rules in less.css are sane, meaning that variables defined within a selector block are only valid within that block, so it&#8217;s possible to safely define the following block:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.bar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #a1a100;">@height: 28px;</span>
    <span style="color: #a1a100;">@text-offset: 6px;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #a1a100;">@height - @text-offset;</span>
    <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #a1a100;">@text-offset;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Without worrying about <code>height</code>, and <code>top-padding</code> spilling out into other blocks. It sould also be pretty trivial to define a <a href="http://lesscss.org/#-parametric-mixins" target="_blank">parametric mixin</a> to make this more-reusable, but that&#8217;s left as an excercise for the reader.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.offsetdesign.co.uk/2011/less-css-and-controlling-element-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

