<?xml version='1.0'?><rss xmlns:admin='http://webns.net/mvcb/' version='2.0' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <channel>
    <title>random code</title>
    <link>http://rjp.frottage.org/codeblog</link>
    <description/>
    <dc:language>en-us</dc:language>
    <dc:creator/>
    <dc:date>2005-11-16T14:32:27+00:00</dc:date>
    <admin:generatorAgent rdf:resource='http://hobix.com/?v=0.4'/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <item><title>Ugly Code, Part 1</title><link>http://rjp.frottage.org/codeblog/ugly_ruby_part_1.html</link><guid isPermaLink='false'>ugly_ruby_part_1@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-11-16T14:32:27+00:00</dc:date><description>&amp;#9;&lt;p&gt;Inspired by &lt;a href=&quot;http://arstechnica.com/columns/linux/linux-20051002.ars&quot;&gt;Monitoring network traffic with Ruby and Pcap&lt;/a&gt; .  The &lt;a href=&quot;http://www.goto.info.waseda.ac.jp/~fukusima/ruby/pcap/doc/Pcaplet.html&quot;&gt;pcaplet library for Ruby&lt;/a&gt; already seems to supports a couple of the modifications I suggest, though the documentation is sketchy.&lt;/p&gt;


&amp;#9;&lt;h2&gt;Arcane parameters&lt;/h2&gt;


&lt;pre class=&quot;bad&quot;&gt;&lt;code&gt;# create a sniffer that grabs the first 1500 bytes of each packet 
$network = Pcaplet.new(&apos;-s 1500&apos;)  &lt;/code&gt;&lt;/pre&gt;

&amp;#9;&lt;p&gt;Bloody Perl people.  Variables prefixed with $ are global in Ruby and a bad idea to use willy-nilly.  But that&amp;#8217;s a side point to this line: what the hell is that &amp;#8221;-s 1500&amp;#8221; all about?  Arcane command-line arguments have no place in a scripting language object class.  Much better to use named parameters or a method call to set the grab length.&lt;/p&gt;


&lt;pre class=&quot;good&quot;&gt;&lt;code&gt;network = Pcaplet.new(grabsize =&gt; 1500) 
# or 
network = Pcaplet.new().grabsize(1500) &lt;/code&gt;&lt;/pre&gt;

&amp;#9;&lt;h2&gt;Where&amp;#8217;s a delegating factory when you need one?&lt;/h2&gt;


&lt;pre class=&quot;bad&quot;&gt;&lt;code&gt;# create a filter that uses our query string and the sniffer we just made 
$filter = Pcap::Filter.new(&apos;tcp and dst port 80&apos;, $network.capture)
# add the new filter to the sniffer 
$network.add_filter($filter) &lt;/code&gt;&lt;/pre&gt;
(More globals.  Ick.)  What&amp;#8217;s &lt;code&gt;$network.capture&lt;/code&gt; and why is it being passed to a Pcap::Filter constructor?  Why do you have to add it to the &lt;code&gt;$network&lt;/code&gt; object later?

&amp;#9;&lt;p&gt;Why not just use a delegating factory (if that&amp;#8217;s the right term)?&lt;/p&gt;


&lt;pre class=&quot;good&quot;&gt;&lt;code&gt;network.add_filter(&quot;tcp and dst port 80&quot;) &lt;/code&gt;&lt;/pre&gt;
Let the network object figure out that you&amp;#8217;ve passed a string, create a filter object with whatever arcane parameters it needs, and attach it.  Less thinking for me, happiness all round!

&amp;#9;&lt;p&gt;&lt;em&gt;Update: Looking at the class code is amusing: if you pass a filter object to add_filter, it seems to grab the string you used to create it!&lt;/em&gt;&lt;/p&gt;


&amp;#9;&lt;h2&gt;Ugly iteration&lt;/h2&gt;


&lt;pre class=&quot;bad&quot;&gt;&lt;code&gt;# iterate over every packet that goes through the sniffer
for p in $network &lt;/code&gt;&lt;/pre&gt;
Ugh.  Hidden iterators: bad.  Single letter variables: bad.
&lt;pre class=&quot;good&quot;&gt;&lt;code&gt;for packet in network.packets # all packets 
# or 
for packet in network.captured # does captured imply filtered? 
# or  
for packet in network.filtered_packets # just the filtered ones, ta &lt;/code&gt;&lt;/pre&gt;

&amp;#9;&lt;h2&gt;Filtering confusion&lt;/h2&gt;


&lt;pre class=&quot;bad&quot;&gt;&lt;code&gt;# print packet data for each packet that matches the filter 
puts p.tcp_data if $filter =~ p &lt;/code&gt;&lt;/pre&gt;
Why is it testing the packet data against the filter if it already attached the filter to the sniffer?  Does adding a filter to the sniffer not actually filter the packets?  (It does.)

Later on, when there&amp;#8217;s three filters applied, it makes sense as you don&amp;#8217;t know why your packet has been captured unless you manually check against the filters but that just implies a callback-driven mechanism would be a good idea.
&lt;pre class=&quot;good&quot;&gt;&lt;code&gt;network.add_filter(&apos;tcp and src port 5190&apos;, proc { aim_recv })
network.add_filter(&apos;tcp and dst port 5190&apos;, proc { aim_send }) 
# etc. &lt;/code&gt;&lt;/pre&gt;</description></item><item><title>More Constrained Tube Journeys</title><link>http://rjp.frottage.org/codeblog/more_constrained_tube_journeys.html</link><guid isPermaLink='false'>more_constrained_tube_journeys@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-11-08T12:09:44+00:00</dc:date><description>On the way back from New Eltham this evening, I started pondering some more constrained tube journeys:
&amp;#9;&lt;ul&gt;
&amp;#9;&lt;li&gt;shortest journey with at least one non-interchange (no circle on the tube map) station on each line (Waterloo &amp;#38; City exempted) starting and ending at an interchange (stations on two lines only count for one line at a time).&lt;/li&gt;
&amp;#9;&amp;#9;&lt;li&gt;the longest journey only using interchange stations (black/white circle but only tube lines and with different lines than its neighbours&amp;#8212;Farringdon doesn&amp;#8217;t count, for example.)&lt;/li&gt;
&amp;#9;&lt;/ul&gt;


&amp;#9;&lt;p&gt;For the first one, I can do it in 30 stations (solution later).  For the second, the best I&amp;#8217;ve got so far is 11.&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;em&gt;[11:11, 8th November.  19 stations for the second one.]&lt;/em&gt;&lt;/p&gt;</description></item><item><title>dc mandelbrot generator</title><link>http://rjp.frottage.org/codeblog/dc_mandelbrot_20050811_1258.html</link><guid isPermaLink='false'>dc_mandelbrot_20050811_1258@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T10:47:29+00:00</dc:date><description>I wrote this about seven years ago, probably something to do with my 1994 version that I wrote in &lt;span class=&quot;caps&quot;&gt;FALSE&lt;/span&gt;.
&lt;pre&gt;2k64sw32sh7sz[.]0:p[,]1:p[:]2:p[o]3:p[*]4:p[O]5:p[@]6:p[ ]lz:p5lw/si4
lh/sj0 2-dsxsu0 2-dsysv[0 2-dsxsu[luSalvSblzdsnSq[lqSn0Sq]Sm[ladd*SoSs
LoLslb2** SoSsLoLslbd*-lu+Salv+Sbclad*lbd*+4&lt;mlqd1-Sq0&lt;g]sglgxlad*lbd*
+4 0sr[1sr]st&gt;tLrln;pPlilu+ Sulu2&gt;h]sh lhx[]pljlv+Svlv2&gt;f]sflfx&lt;/pre&gt;

&amp;#9;&lt;p&gt;Put that in a file and &amp;#8220;dc &lt; file&amp;#8221;.&lt;/p&gt;</description></item><item><title>Random idea #1: Autopano</title><link>http://rjp.frottage.org/codeblog/autopano_20050419_1111.html</link><guid isPermaLink='false'>autopano_20050419_1111@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T09:47:54+00:00</dc:date><description>&amp;#9;&lt;ul&gt;
&amp;#9;&lt;li&gt;use autopano to line up the two halves of a red-green stereoscope&lt;/li&gt;
&amp;#9;&amp;#9;&lt;li&gt;use autopano to identify pictures which are similar&lt;/li&gt;
&amp;#9;&lt;/ul&gt;</description></item><item><title>Diagram of the 14 stop solution</title><link>http://rjp.frottage.org/codeblog/diagram_20050107_2107.html</link><guid isPermaLink='false'>diagram_20050107_2107@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T10:48:30+00:00</dc:date><description>&amp;#9;&lt;p&gt;&lt;img src=&quot;http://rjp.frottage.org/images/2005/01/07/14tubestops.png&quot; title=&quot;14 stop solution&quot; alt=&quot;14 stop solution&quot; /&gt;&lt;/p&gt;</description></item><item><title>Constrained Tube Journeys, #3</title><link>http://rjp.frottage.org/codeblog/tubes_3_20050101_0245.html</link><guid isPermaLink='false'>tubes_3_20050101_0245@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T10:52:38+00:00</dc:date><description>&amp;#9;&lt;p&gt;Standing at East Putney after New Year, I thought of two more constrained tube journeys to try and figure out.&lt;/p&gt;


&amp;#9;&lt;ul&gt;
&amp;#9;&lt;li&gt;The trip enclosing the biggest area without backtracking&lt;/li&gt;
&amp;#9;&amp;#9;&lt;li&gt;The shortest trip involving each line just once&lt;/li&gt;
&amp;#9;&lt;/ul&gt;


&amp;#9;&lt;p&gt;For the first one, something like: Rayners Lane, Acton Town, Victoria, Stockwell, London Bridge, Stratford, Liverpool Street, Baker Street, Rayners Lane.  Unfortunately, &lt;a href=&quot;http://trac.frottage.org/rjp2/file/scripts/tubes.d&quot;&gt;tubes.d&lt;/a&gt; doesn&amp;#8217;t have the necessary information for a script to calculate the area enclosed by journey yet.&lt;/p&gt;


&amp;#9;&lt;p&gt;For the second (ignoring the &lt;span class=&quot;caps&quot;&gt;DLR&lt;/span&gt; for now), something like: Shoreditch (ELL) Whitechapel (HamCity) Aldgate East (District) Tower Hill (Circle) Aldgate (Metro) Liverpool Street (Central) Bank (WaterlooCity) Waterloo (Jubilee) Green Park (Victoria) Oxford Circus (Bakerloo) Piccadilly Circus (Piccadilly) Leicester Square (Northern) Tottenham Court Road.  A total of 14 stops with only 1 non-interchange.  Since you need 13 stops as a minimum for 12 lines, that&amp;#8217;s pretty good.&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;em&gt;update, 20050102: A quick hack with Prolog seems to imply that there&amp;#8217;s no 13 stop solution at all.  More about this later.&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Constrained Tube Journeys, #4</title><link>http://rjp.frottage.org/codeblog/tubes_4_20050102_0130.html</link><guid isPermaLink='false'>tubes_4_20050102_0130@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T10:51:02+00:00</dc:date><description>&amp;#9;&lt;p&gt;Is it possible to visit all the lines in alphabetic order?  (i.e. Bakerloo, Central, Circle, District, East London, Hammersmith&amp;#38;City, Jubilee, Metropolitan, Northern, Piccadilly, Victoria, Waterloo&amp;#38;City)&lt;/p&gt;


&amp;#9;&lt;p&gt;Since there&amp;#8217;s no interchange between the Victoria line and the Waterloo&amp;#38;City line, the answer is no.  If you cheat and use the Waterloo&amp;#38;City line first (from Bank to Waterloo), the answer is, well, I don&amp;#8217;t know yet.  Maybe.&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;em&gt;update, 0147: There&amp;#8217;s also no sensible way of going District, East London, Hammersmith&amp;#38;City.&lt;/em&gt;&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;em&gt;update, 0149: Although including the &lt;span class=&quot;caps&quot;&gt;DLR&lt;/span&gt; would fix that problem and gives a possible solution (which this margin is too small to contain!)&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Constrained Tube Journeys, #2</title><link>http://rjp.frottage.org/codeblog/alphabetic_tubes_20041222_1300.html</link><guid isPermaLink='false'>alphabetic_tubes_20041222_1300@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T10:53:51+00:00</dc:date><description>&amp;#9;&lt;p&gt;After finding sequences of alphabetically ordered tube stations, I wondered if there were any strictly alphabetical sequences.  Modifying &lt;a href=&quot;http://trac.frottage.org/rjp2/file/scripts/tubesequence.pl&quot;&gt;tubesequence.pl&lt;/a&gt; was fairly easy (the commented out code) but there&amp;#8217;s only one: &lt;em&gt;Ravenscourt Park, Stamford Brook, Turnham Green&lt;/em&gt;.&lt;/p&gt;</description></item><item><title>More Constrained Tube Journeys</title><link>http://rjp.frottage.org/codeblog/more_tubes_20041222_1100.html</link><guid isPermaLink='false'>more_tubes_20041222_1100@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T11:02:01+00:00</dc:date><description>Whilst standing at Piccadilly Circus waiting for a westbound Piccadilly Line tube, I noticed that the last six stops all began with the letter &amp;#8216;H&amp;#8217; (Hounslow East, Hounslow Central, Hounslow West, Hatton Cross, Heathrow Terminal 4, Heathrow Terminal 1,2,3).  That got me wondering what the longest sequence of alphabetically ordered stations was.  One &lt;a href=&quot;http://trac.frottage.org/rjp2/file/scripts/tubesequence.pl&quot;&gt;Perl script&lt;/a&gt; later (using &lt;a href=&quot;http://trac.frottage.org/rjp2/file/scripts/tubes.d&quot;&gt;tubes.d&lt;/a&gt; from earlier) and the longest sequences, all of 6 stops, are:
&amp;#9;&lt;ul&gt;
&amp;#9;&lt;li&gt;BakerStreet &rarr; BondStreet &rarr; GreenPark &rarr; HydeParkCorner &rarr; Knightsbridge &rarr; SouthKensington&lt;/li&gt;
&amp;#9;&amp;#9;&lt;li&gt;BaronsCourt &rarr; EarlsCourt &rarr; GloucesterRoad &rarr; HighStreetKensington &rarr; NottingHillGate &rarr; Queensway&lt;/li&gt;
&amp;#9;&amp;#9;&lt;li&gt;Borough &rarr; Elephant_Castle &rarr; Kennington &rarr; Oval &rarr; Stockwell &rarr; Vauxhall&lt;/li&gt;
&amp;#9;&lt;/ul&gt;


&amp;#9;&lt;p&gt;Three sequences of length 6, none on a single line.&lt;/p&gt;</description></item><item><title>Constrained Tube Map</title><link>http://rjp.frottage.org/codeblog/tubemap_20041203_1745.html</link><guid isPermaLink='false'>tubemap_20041203_1745@http://rjp.frottage.org/codeblog</guid><dc:subject>.</dc:subject><dc:creator>rjp</dc:creator><dc:date>2005-08-27T11:07:48+00:00</dc:date><description>&amp;#9;&lt;p&gt;Given &lt;a href=&quot;http://www.geofftech.co.uk/tube/sillymaps/milesdistances.gif&quot;&gt;the distances between tube stations&lt;/a&gt;, can a tool like &lt;a href=&quot;http://www.graphviz.org/&quot;&gt;neato&lt;/a&gt; lay out the tube stations in anything like the correct layout?
After &lt;a href=&quot;http://rjp.frottage.org/misc/tubedistances/data.txt&quot;&gt;typing in all the stations and distances&lt;/a&gt;, &lt;a href=&quot;http://rjp.frottage.org/misc/tubedistances/process.pl&quot;&gt;processing the data in graphviz format&lt;/a&gt;, and running it through neato, the answer is &lt;em&gt;almost, but not quite&lt;/em&gt;.&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;img src=&quot;http://rjp.frottage.org/images/2004/12/04/thumbnail.png&quot; title=&quot;neato tube map&quot; alt=&quot;neato tube map&quot; /&gt;&lt;/p&gt;


&amp;#9;&lt;p&gt;&lt;a href=&quot;http://rjp.frottage.org/images/2004/12/04/bigneatotubemap.png&quot;&gt;[550k &lt;span class=&quot;caps&quot;&gt;PNG&lt;/span&gt;]&lt;/a&gt; &lt;a href=&quot;http://rjp.frottage.org/images/2004/12/04/finalmap.svgz&quot;&gt;[SVGZ]&lt;/a&gt;&lt;/p&gt;</description></item></channel>
</rss>
