<?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>John Stanfield dot com</title>
	<atom:link href="http://johnstanfield.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://johnstanfield.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Jul 2010 15:01:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>test</title>
		<link>http://johnstanfield.com/?p=504</link>
		<comments>http://johnstanfield.com/?p=504#comments</comments>
		<pubDate>Thu, 22 Jul 2010 15:00:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=504</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=504</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Script for Combinations and Permutations</title>
		<link>http://johnstanfield.com/?p=491</link>
		<comments>http://johnstanfield.com/?p=491#comments</comments>
		<pubDate>Thu, 22 Jul 2010 14:02:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=491</guid>
		<description><![CDATA[
I was looking for a quick and easy solution to finding the combinations and permutations of the elements of an array.  Below is a script that (I believe) returns either with a handful of options.
Note that there are 27 permutations of a three-item set, but the script below returns 39 because there are 39 [...]]]></description>
			<content:encoded><![CDATA[<div style="width: 550px;">
I was looking for a quick and easy solution to finding the combinations and permutations of the elements of an array.  Below is a script that (I believe) returns either with a handful of options.</p>
<p>Note that there are 27 permutations of a three-item set, <strong>but</strong> the script below returns 39 because there are 39 ways of combining <em>some or all</em> of the items in a three-item set (i.e. in addition to the 27 permutations of 1, 2, <em>and</em> 3, there are also 12 permutations of 1, 2, <em>or</em> 3.)</p>
<p><strong>The code</strong></p>
<pre class="brush:ruby; toolbar:false; gutter:false">
Array.class_eval do
  # return hash with
  #   keys being unique elements of self;
  #   values being number of occurrences of those elements
  # similar to SQL select x,count(1) from y group by x
  # [1,3,3,9,9,9,9].count_distinct
  #  => {1=>1, 3=>2, 9=>4}
  def count_distinct
    c={}
    self.each{|x|c[x]=(c[x]||0)+1}
    c
  end
end

def permute(i,els,perms,options)
  els.each{|e|
    if (i.size+1)&lt;=options[:max_size]
      nxt=i.dup&lt;&lt;e
      perms&lt;&lt;nxt if nxt.size>=options[:min_size]
      permute(nxt,els,perms,options)
    end
  }
end

def easy_permute(elements,min=1,max=elements.size)
  permutations=[]
  options={:min_size=>min,:max_size=>max}
  permute([],elements,permutations,options)
  permutations
end

def easy_combine(elements,min=1,max=elements.size,max_repetitions=nil)
  puts "min is #{min}"
  permutations=easy_permute(elements,min,max)
  permutations.each{|x|x.sort!}.sort!
  permutations.uniq!
  permutations.delete_if{|x|
    x.count_distinct.values.detect{|y|
      y>max_repetitions}} if max_repetitions
  permutations
end
</pre>
<p><strong>Usage and testing&#8230;</strong></p>
<pre class="brush:ruby; toolbar:false; gutter:false">
test_combine=easy_combine(['a','b','c'])
test_combine_3=easy_combine(['a','b','c'],3)
test_combine_3_no_rep=easy_combine(['a','b','c'],3,3,1)
test_permute=easy_permute(['a','b','c'])
test_permute_3=easy_permute(['a','b','c'],3)

msg= "=========================\n"
msg&lt;&lt;"COMBINATIONS (#{test_combine.size})\n"
test_combine.each {|x|msg&lt;&lt;x.join(',')&lt;&lt;"\n"};nil

msg&lt;&lt;"=========================\n"
msg&lt;&lt;"COMBINATIONS OF 3 (#{test_combine_3.size})\n"
test_combine_3.each {|x|msg&lt;&lt;x.join(',')&lt;&lt;"\n"};nil

msg&lt;&lt;"=========================\n"
msg&lt;&lt;"COMBINATIONS OF 3 WITH NO REPETITION (#{test_combine_3_no_rep.size})\n"
test_combine_3_no_rep.each {|x|msg&lt;&lt;x.join(',')&lt;&lt;"\n"};nil

msg&lt;&lt;"=========================\n"
msg&lt;&lt;"PERMUTATIONS (#{test_permute.size})\n"
test_permute.each {|x|msg&lt;&lt;x.join(',')&lt;&lt;"\n"};nil

msg&lt;&lt;"=========================\n"
msg&lt;&lt;"PERMUTATIONS OF 3 (#{test_permute_3.size})\n"
test_permute_3.each {|x|msg&lt;&lt;x.join(',')&lt;&lt;"\n"};nil

puts msg
</pre>
<pre style="font-family:courier">
=========================
COMBINATIONS (19)
a
a,a
a,a,a
a,a,b
a,a,c
a,b
a,b,b
a,b,c
a,c
a,c,c
b
b,b
b,b,b
b,b,c
b,c
b,c,c
c
c,c
c,c,c
=========================
COMBINATIONS OF 3 (10)
a,a,a
a,a,b
a,a,c
a,b,b
a,b,c
a,c,c
b,b,b
b,b,c
b,c,c
c,c,c
=========================
COMBINATIONS OF 3 WITH NO REPETITION (1)
a,b,c
=========================
PERMUTATIONS (39)
a
a,a
a,a,a
a,a,b
a,a,c
a,b
a,b,a
a,b,b
a,b,c
a,c
a,c,a
a,c,b
a,c,c
b
b,a
b,a,a
b,a,b
b,a,c
b,b
b,b,a
b,b,b
b,b,c
b,c
b,c,a
b,c,b
b,c,c
c
c,a
c,a,a
c,a,b
c,a,c
c,b
c,b,a
c,b,b
c,b,c
c,c
c,c,a
c,c,b
c,c,c
=========================
PERMUTATIONS OF 3 (27)
a,a,a
a,a,b
a,a,c
a,b,a
a,b,b
a,b,c
a,c,a
a,c,b
a,c,c
b,a,a
b,a,b
b,a,c
b,b,a
b,b,b
b,b,c
b,c,a
b,c,b
b,c,c
c,a,a
c,a,b
c,a,c
c,b,a
c,b,b
c,b,c
c,c,a
c,c,b
c,c,c
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=491</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Script for Combinations</title>
		<link>http://johnstanfield.com/?p=460</link>
		<comments>http://johnstanfield.com/?p=460#comments</comments>
		<pubDate>Fri, 16 Jul 2010 13:17:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=460</guid>
		<description><![CDATA[Say you have the set 1,2,3,4,5,6 and you want to know all combinations, not permutations, of the set.  Here is a Ruby script to do so.

elements=[1,2,3,4,5,6]
t1=Time.now
combinations=[]
elements.each_with_index do &#124;element,i&#124;
  # the by-itself combination
  combinations&#60;&#60;[element]
  # the last item's combinations are already defined
  unless i==elements.size-1
    elements[(i+1)..(elements.size-1)].each do &#124;next_element&#124;
  [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have the set 1,2,3,4,5,6 and you want to know all <a href="http://www.mathsisfun.com/combinatorics/combinations-permutations.html">combinations, not permutations,</a> of the set.  Here is a Ruby script to do so.</p>
<pre class="brush:ruby; toolbar:false; gutter:false">
elements=[1,2,3,4,5,6]
t1=Time.now
combinations=[]
elements.each_with_index do |element,i|
  # the by-itself combination
  combinations&lt;&lt;[element]
  # the last item's combinations are already defined
  unless i==elements.size-1
    elements[(i+1)..(elements.size-1)].each do |next_element|
      combinations&lt;&lt;(combinations.last.dup&lt;&lt;next_element)
    end
  end
end
t2=Time.now
combinations.each {|c|puts c.join(',')}
puts "it took #{(t2-t1)*1000}ms to generate this set"
</pre>
<p>and the output:</p>
<pre style="font-family:courier">
1
1,2
1,2,3
1,2,3,4
1,2,3,4,5
1,2,3,4,5,6
2
2,3
2,3,4
2,3,4,5
2,3,4,5,6
3
3,4
3,4,5
3,4,5,6
4
4,5
4,5,6
5
5,6
6
it took 8ms to generate this set
</pre>
<p>It also works with words.  The real-world case for this is that I&#8217;m working on a keyword co-occurrence database.  I want to know, out of a given set of survey responses, the frequency of words which appear in the same sentence.  For the given sentence <em>I love Ruby, it is such a great programming language &#8212; and powerful, too.</em>, with the common words removed&#8230;</p>
<div style="width: 550px">
<pre class="brush:ruby; toolbar:false; gutter:false">
elements=["love","Ruby","great","programming","language","powerful"]
</pre>
</div>
<p>and the output:</p>
<pre style="font-family:courier">
love
love,Ruby
love,Ruby,great
love,Ruby,great,programming
love,Ruby,great,programming,language
love,Ruby,great,programming,language,powerful
Ruby
Ruby,great
Ruby,great,programming
Ruby,great,programming,language
Ruby,great,programming,language,powerful
great
great,programming
great,programming,language
great,programming,language,powerful
programming
programming,language
programming,language,powerful
language
language,powerful
powerful
it took 13ms to generate this set
</pre>
<p><strong>This script doesn&#8217;t handle large sets!</strong></p>
<pre style="font-family:courier">
elements=(1..500).to_a
it took 30819ms to generate this set    

elements=(1..5000).to_a
#my computer crashed from lack of memory!
</pre>
<p><strong>But if you can reduce the depth of combinations&#8230;</strong></p>
<p>There isn&#8217;t much value (at least in the context of what I am doing!) in indexing every possible combination of words in a large text.  Really, I only need maybe four-word combinations.  This script will work with a large text because the result set is relatively small because it limits the combination depth to three elements.</p>
<pre class="brush:ruby; gutter:false; toolbar:false">
max=3
elements=[1,2,3,4,5,6]
t1=Time.now
combinations=[]
elements.each_with_index do |element,i|
  # the by-itself combination
  combinations&lt;&lt;[element]
  # the last item's combinations are already defined
  unless i==elements.size-1
    elements[(i+1)..(elements.size-1)].each do |next_element|
      c=combinations.last.dup&lt;&lt;next_element
      c.delete_at(1) until c.size<=max
      combinations&lt;&lt;c
    end
  end
end
t2=Time.now
combinations.each {|c|puts c.join(',')}
puts "it took #{t2-t1}ms to generate this set"
</pre>
<pre style="font-family:courier">
1
1,2
1,2,3
1,3,4
1,4,5
1,5,6
2
2,3
2,3,4
2,4,5
2,5,6
3
3,4
3,4,5
3,5,6
4
4,5
4,5,6
5
5,6
6
it took 13ms to generate this set
</pre>
<p>Now I can work with large texts!</p>
<pre style="font-family:courier">
elements=(1..5000).to_a
it took 28370ms to generate this set
</pre>
<p>Now I have what I need to build a database index representing combinations of words in sentences.  From there, I can find all sentences with, say, <em>powerful</em> and <em>language</em> in them (because all sentences will be indexed according to the combinations of words that appear in them).  However, knowing to look for <em>powerful</em> and <em>language</em> in advance is not my goal -- I want the database to tell me the most frequent co-occurrences, so that I can examine them.  My goal is to have the database tell me, in essence, <em>the most common combination of words the combination of <strong>problem</strong> and <strong>feature</strong></em> so that I can pinpoint what people are talking about without having to read every single sentence.  (I'm pretty sure this is impossible since people might not use the same terminology even though they're all talking about the same thing).</p>
<p>But more on this topic later...</p>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=460</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set Modified Time to Date and Time Picture was Taken (in Linux)</title>
		<link>http://johnstanfield.com/?p=445</link>
		<comments>http://johnstanfield.com/?p=445#comments</comments>
		<pubDate>Sun, 23 May 2010 03:24:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=445</guid>
		<description><![CDATA[Oh no!  I just moved 3 gigs of pictures, afterwards realizing that the modified-time was changed from the time the picture was taken to the time the file was moved.  What a mess, I thought, since I always refer to the modified-time when I wonder when a picture was taken.
exiv2 and touch to [...]]]></description>
			<content:encoded><![CDATA[<p>Oh no!  I just moved 3 gigs of pictures, afterwards realizing that the modified-time was changed from the time the picture was taken to the time the file was moved.  What a mess, I thought, since I always refer to the modified-time when I wonder when a picture was taken.</p>
<p><span style="font-family:courier">exiv2</span> and <span style="font-family:courier">touch</span> to the rescue!</p>
<p><span style="font-family:courier">exiv2</span> will tell you, among a ton of other things, the time the picture was taken, and <span style="font-family:courier">touch</span> will allow you to change the modified-time of the image. </p>
<p><strong>Note:</strong>Any command below, spread across multiple lines, is done so for clarity.  To use the command, the line breaks must be removed such that the entire command is on one line!</p>
<p>This is the output of <span style="font-family:courier">exiv2</span>:</p>
<pre style="font-family:courier; border: solid 1px #cecece;">
File name       : my_picture.jpg
File size       : 77443 Bytes
MIME type       : image/jpeg
Image size      : 425 x 543
Camera make     : Canon
Camera model    : Canon PowerShot SD1100 IS
Image timestamp : 2010:04:26 20:06:07
Image number    : 100-2025
Exposure time   : 1/60 s
Aperture        : F4.9
Exposure bias   : 0
Flash           : Yes, auto, red-eye reduction
Flash bias      : 0 EV
Focal length    : 18.6 mm
Subject distance: 266
ISO speed       : 250
Exposure mode   : Easy shooting (Auto)
Metering mode   : Multi-segment
Macro mode      : Off
Image quality   : Fine
Exif Resolution : 1848 x 2360
White balance   : Auto
Thumbnail       : JPEG, 7866 Bytes
Copyright       :
Exif comment    :
</pre>
<p>Now you just use <span style="font-family:courier">grep</span> to find the Image timestamp line:</p>
<pre style="font-family:courier; border: solid 1px #cecece;">
exiv2 my_image.jpg | grep timestamp
Image timestamp : 2010:04:26 20:06:07
</pre>
<p>Now use <span style="font-family:courier">awk</span> to massage that date into <em>almost</em> the <span style="font-family:courier">touch</span>-required format of <span style="font-family:courier">YYYYMMDDHHMM.SS</span></p>
<p><span style="font-family:courier"></span></p>
<pre style="font-family:courier; border: solid 1px #cecece;">
exiv2 my_image.jpg |
  grep timestamp |
    awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}'
2010:04:26 20 06 . 07
</pre>
<p>Now use <span style="font-family:courier">sed</span> to remove the space and colons to complete the formatting<br />
<span style="font-family:courier"></span></p>
<pre style="font-family:courier; border: solid 1px #cecece;">
exiv2 my_image.jpg |
  grep timestamp |
    awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}'  |
      sed 's/[:, ]//g'
201004262006.07
</pre>
<p>And the final command, to actually touch an image:</p>
<pre style="font-family:courier; border: solid 1px #cecece;">
touch my_image.jpg -t
  `exiv2 my_image.jpg |
    grep timestamp |
      awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}' |
        sed 's/[:, ]//g'`
</pre>
<p>For an entire directory:</p>
<pre style="font-family:courier; border: solid 1px #cecece;">
find *.jpg |
  while read f; do
    touch "${f}" -t `
      exiv2 "${f}" |
        grep timestamp |
          awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}' |
            sed 's/[:, ]//g'`;
  done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=445</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use ImageMagick&#8217;s convert Command Instead of jpegorient in KDE</title>
		<link>http://johnstanfield.com/?p=429</link>
		<comments>http://johnstanfield.com/?p=429#comments</comments>
		<pubDate>Thu, 20 May 2010 02:46:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=429</guid>
		<description><![CDATA[
One annoying thing that has plagued my laptop is that right-clicking a JPEG in Dolphin makes a menu fly out with unusable options to rotate and flip the image.  They don&#8217;t work because jpegorient doesn&#8217;t come with openSUSE 11.1, and I don&#8217;t know what it is or how to get it.  I&#8217;ve been [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://johnstanfield.com/wp-content/uploads/2010/05/snapshot11.png" alt="snapshot1" title="snapshot1" width="507" height="210" class="alignnone size-full wp-image-441" /></p>
<p>One annoying thing that has plagued my laptop is that right-clicking a JPEG in Dolphin makes a menu fly out with unusable options to rotate and flip the image.  They don&#8217;t work because jpegorient doesn&#8217;t come with openSUSE 11.1, and I don&#8217;t know what it is or how to get it.  I&#8217;ve been using the convert command (a part of ImageMagick) from a command line, so I wondered if I could make the Actions menu use it as well.  </p>
<p>I edited the ServiceMenu file for the Actions menu, which is at <span style="font-family:courier">/usr/share/kde4/services/ServiceMenus/jpegorient.desktop</span> on my computer.  You can execute <span style="font-family:courier">locate jpegorient.desktop</span> or <span style="font-family:courier">find jpegorient.desktop</span> if you don&#8217;t see it at that path.  The changes are below in bold.</p>
<div style="border:solid 1px #cecece">
[Desktop Action jpegRot90]<br />
Name=Rotate Clockwise<br />
Icon=object-rotate-right<br />
<strong>Exec=convert -rotate 90 %F %F<br />
</strong></p>
<p>[Desktop Action jpegRot270]<br />
Name=Rotate Counter-Clockwise<br />
Icon=object-rotate-left<br />
<strong>Exec=convert -rotate 270 %F %F<br />
</strong><br />
#[Desktop Action jpegRot180]<br />
#Name=Rotate 180<br />
#Icon=misc<br />
#Exec=jpegorient +180 %F</p>
<p>[Desktop Action jpegFlipV]<br />
Name=Flip Vertically<br />
Icon=2uparrow<br />
<strong>Exec=convert -flip %F %F</strong></p>
<p>[Desktop Action jpegFlipH]<br />
Name=Flip Horizontally<br />
Icon=2rightarrow<br />
<strong>Exec=convert -flop %F %F<br />
</strong>
</div>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=429</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Without Password</title>
		<link>http://johnstanfield.com/?p=403</link>
		<comments>http://johnstanfield.com/?p=403#comments</comments>
		<pubDate>Tue, 18 May 2010 14:41:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=403</guid>
		<description><![CDATA[I was looking for a quick and dirty way to SSH into a handful of hosts.  I SSH into these hosts all day long, and I was looking for a way to skip the password prompt (I&#8217;m way too much into efficiency &#8212; every second counts!).  I wasn&#8217;t interested in learning how to [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a quick and dirty way to SSH into a handful of hosts.  I SSH into these hosts all day long, and I was looking for a way to skip the password prompt (I&#8217;m way too much into efficiency &#8212; every second counts!).  I wasn&#8217;t interested in learning how to set up the public/private key authentication.  I just wanted to automate the login so all I would need to type is <span style="font-family: courier">goto host</span>.  Obviously this is less than secure, but I&#8217;m not overly concerned with security at my workstation.</p>
<p>Here&#8217;s what I came up with:</p>
<p>1) a file named goto.passwd<br />
  &#8211; which contains hostnames, usernames, and passwords (e.g. myhost myuser mypassword)<br />
2) a script named goto<br />
  &#8211; which accepts one parameter (e.g. goto myhost)<br />
  &#8211; parses the goto.passwd file looking for that host<br />
  &#8211; and then passes that info to<br />
3) a script borrowed from <a href="http://bash.cyberciti.biz/security/expect-ssh-login-script/">here</a><br />
  &#8211; and slightly modified.</p>
<p>Here is an example (the command is simply <span style="font-family:courier">goto myhost</span> and I&#8217;m instantly in.):</p>
<div style="font-family:courier">
john@jslinux:~&gt; goto myhost<br />
spawn ssh user@myhost<br />
user@myhost&#8217;s password:<br />
Last login: Tue May 18 11:31:05 2010 from 1.2.3.4<br />
-bash-3.2$
</div>
<p>Here are the scripts (you can also download them as a zip or tar):</p>
<p><b>goto.passwd</b></p>
<pre class="brush:bash; toolbar: false; gutter:false">
myhost root password
myotherhost root passwordforroot
anotherhost root password12345
</pre>
<p><b>goto</b></p>
<pre class="brush:bash; toolbar: false; gutter:false">
#!/bin/bash
host=$1
user=`cat goto.passwd | grep -e ^$host | awk '{print $2}'`
pass=`cat goto.passwd | grep -e ^$host | awk '{print $3}'`
goto.expect $user $pass $host
</pre>
<p><b>goto.expect</b></p>
<p style="font-family:courier">
omitted.  see zip or tar file below.
</p>
<p><img src="/wp-content/uploads/2010/05/zip.gif" /><br />
<a href="/wp-content/uploads/2010/05/goto.tar">goto.tar</a><br />
<a href="/wp-content/uploads/2010/05/goto.zip">goto.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=403</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewing very large log files</title>
		<link>http://johnstanfield.com/?p=394</link>
		<comments>http://johnstanfield.com/?p=394#comments</comments>
		<pubDate>Thu, 15 Apr 2010 19:49:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=394</guid>
		<description><![CDATA[Someone came to me today and asked if I could track down a 403 error that was handed to a user the morning of 4/13/2010.  The web server log file is 465 megs.  Gulp.  sed and grep to the rescue!
Just pick a random number (representing a wild guess at where, in the [...]]]></description>
			<content:encoded><![CDATA[<p>Someone came to me today and asked if I could track down a 403 error that was handed to a user the morning of 4/13/2010.  The web server log file is 465 megs.  Gulp.  <code>sed</code> and <code>grep</code> to the rescue!</p>
<p>Just pick a random number (representing a wild guess at where, in the log file, your starting point may be) and use <code>sed -n 2000p</code> where 2000 is your random number.  My original guess was way off.  The time period in question ended up spanning lines 500,000 to 680,000 in the server log.  Great, just read 180,000 lines, right?  WRONG!  Use <code>grep</code>.  Here&#8217;s the final string of commands I used.</p>
<pre class="brush: bash; toolbar: false; gutter: false">
# just to locate the correct line...
sed -n 2000p site-access_log
sed -n 12000p site-access_log
sed -n 100000p site-access_log
sed -n 300000p site-access_log
sed -n 500000p site-access_log
sed -n 680000p site-access_log

# now to search that time period for a 403 error
sed -n 500000,685000p site-access_log | grep ' 403'
</pre>
<p>Not perfect, but good enough to get the job done.  <code>sed</code> whittled the 465 meg file down to 180,000 lines, and <code>grep</code> whittled that down to 50 or so lines, some of which were relevant, others not.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=394</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>chmod +x on the script folder</title>
		<link>http://johnstanfield.com/?p=386</link>
		<comments>http://johnstanfield.com/?p=386#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:48:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=386</guid>
		<description><![CDATA[A handful of my Rails apps were created in a Windows development environment&#8230;  Which means that the files in the script directory do not have the +x permission, which means I have to type ruby script/console instead of just script/console&#8230;  SVN doesn&#8217;t see adding the execute permission to a file as being a [...]]]></description>
			<content:encoded><![CDATA[<p>A handful of my Rails apps were created in a Windows development environment&#8230;  Which means that the files in the <i>script</i> directory do not have the <b>+x</b> permission, which means I have to type <i>ruby script/console</i> instead of just <i>script/console</i>&#8230;  SVN doesn&#8217;t see adding the execute permission to a file as being a change, so you can&#8217;t commit it by simply changing the permissions&#8230;  So I wrote a script to copy the script folder, delete it, check it in, restore it, add execute permission, and check it back in.  Ahh, I don&#8217;t have to type <i>ruby</i> anymore!</p>
<pre class="brush: bash; gutter: false; toolbar: false">
svn export script script2
svn delete script
svn commit -m "temporarily deleted script/*"
mv script2 script
svn add script
sudo chmod +x script/*
svn commit -m "restored script/* with +x"
</pre>
<div style="font-family: courier">
svn export script script2<br />
svn delete script<br />
svn commit -m &#8220;deleted script/* so that i could chmod +x and check back in&#8221;<br />
mv script2 script<br />
svn add script<br />
sudo chmod +x script/*<br />
svn commit -m &#8220;deleted script/* so that i could chmod +x and check back in&#8221;
</div>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=386</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Buy Books</title>
		<link>http://johnstanfield.com/?p=383</link>
		<comments>http://johnstanfield.com/?p=383#comments</comments>
		<pubDate>Fri, 15 Jan 2010 18:03:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=383</guid>
		<description><![CDATA[I only give free advertising to truly exceptional companies.  BookFinder.com is one of them.  I have spent wasted countless hours looking for the best price on books from the usual suspects:  Amazon, eBay, and half.com.  No longer!  BookFinder.com quickly and easily locates books from a multitude of sellers and includes [...]]]></description>
			<content:encoded><![CDATA[<p>I only give free advertising to truly exceptional companies.  <a href="http://www.bookfinder.com">BookFinder.com</a> is one of them.  I have <s>spent</s> wasted countless hours looking for the best price on books from the usual suspects:  Amazon, eBay, and half.com.  No longer!  <a href="http://www.bookfinder.com">BookFinder.com</a> quickly and easily locates books from a multitude of sellers and includes the shipping cost in the price.  And if you have trouble with the site, their customer service is fast and friendly.  Two thumbs up for <a href="http://www.bookfinder.com">BookFinder.com</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=383</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Inches to Feet and Inches</title>
		<link>http://johnstanfield.com/?p=354</link>
		<comments>http://johnstanfield.com/?p=354#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:27:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://johnstanfield.com/?p=354</guid>
		<description><![CDATA[I love simple problems, such as fill a drop-down with a range of feet and inches.
One way to do it is to hand-code a &#60;select&#62; element and fill it with hand-coded &#60;option&#62; elements, but what&#8217;s the fun in that?
It&#8217;s more fun to iterate over an array (range) of integers representing inches, and do the math [...]]]></description>
			<content:encoded><![CDATA[<p>I love simple problems, such as <i>fill a drop-down with a range of feet and inches</i>.</p>
<p>One way to do it is to hand-code a &lt;select&gt; element and fill it with hand-coded &lt;option&gt; elements, but what&#8217;s the fun in that?</p>
<p>It&#8217;s more fun to iterate over an array (range) of integers representing inches, and do the math to convert those inches to feet and inches.  To get feet, use the floor function, which truncates all decimal places without rounding.  To get inches, use the modulus operator (the % operator) which returns the remainder.  36 is 3&#8242;0&#8243; and 74 is 6&#8242;2&#8243;.</p>
<p>The math is the same but (as John Madden would say, if he were a programmer) the syntax varies by language&#8230;  Here&#8217;s how you do it in Ruby:</p>
<pre class="brush:ruby; toolbar:false; gutter:false">
<%= select :person,
       :height,
       (36..95).collect{|i|["#{(i/12).floor}' #{i%12}\"",i]},
       {:selected=>@person.height} %>
</pre>
<p>
And here&#8217;s what you end up with:</p>
<select id="person_height" name="person[height]"><option value="36">3&#8242;0&quot;</option><br />
<option value="37">3&#8242;1&quot;</option><br />
<option value="38">3&#8242;2&quot;</option><br />
<option value="39">3&#8242;3&quot;</option><br />
<option value="40">3&#8242;4&quot;</option><br />
<option value="41">3&#8242;5&quot;</option><br />
<option value="42">3&#8242;6&quot;</option><br />
<option value="43">3&#8242;7&quot;</option><br />
<option value="44">3&#8242;8&quot;</option><br />
<option value="45">3&#8242;9&quot;</option><br />
<option value="46">3&#8242;10&quot;</option><br />
<option value="47">3&#8242;11&quot;</option><br />
<option value="48">4&#8242;0&quot;</option><br />
<option value="49">4&#8242;1&quot;</option><br />
<option value="50">4&#8242;2&quot;</option><br />
<option value="51">4&#8242;3&quot;</option><br />
<option value="52">4&#8242;4&quot;</option><br />
<option value="53">4&#8242;5&quot;</option><br />
<option value="54">4&#8242;6&quot;</option><br />
<option value="55">4&#8242;7&quot;</option><br />
<option value="56">4&#8242;8&quot;</option><br />
<option value="57">4&#8242;9&quot;</option><br />
<option value="58">4&#8242;10&quot;</option><br />
<option value="59">4&#8242;11&quot;</option><br />
<option value="60">5&#8242;0&quot;</option><br />
<option value="61">5&#8242;1&quot;</option><br />
<option value="62">5&#8242;2&quot;</option><br />
<option value="63">5&#8242;3&quot;</option><br />
<option value="64">5&#8242;4&quot;</option><br />
<option value="65">5&#8242;5&quot;</option><br />
<option value="66">5&#8242;6&quot;</option><br />
<option value="67">5&#8242;7&quot;</option><br />
<option value="68">5&#8242;8&quot;</option><br />
<option value="69">5&#8242;9&quot;</option><br />
<option value="70">5&#8242;10&quot;</option><br />
<option value="71">5&#8242;11&quot;</option><br />
<option value="72">6&#8242;0&quot;</option><br />
<option value="73">6&#8242;1&quot;</option><br />
<option value="74">6&#8242;2&quot;</option><br />
<option value="75">6&#8242;3&quot;</option><br />
<option value="76">6&#8242;4&quot;</option><br />
<option value="77">6&#8242;5&quot;</option><br />
<option value="78">6&#8242;6&quot;</option><br />
<option value="79">6&#8242;7&quot;</option><br />
<option value="80">6&#8242;8&quot;</option><br />
<option value="81">6&#8242;9&quot;</option><br />
<option value="82">6&#8242;10&quot;</option><br />
<option value="83">6&#8242;11&quot;</option><br />
<option value="84">7&#8242;0&quot;</option><br />
<option value="85">7&#8242;1&quot;</option><br />
<option value="86">7&#8242;2&quot;</option><br />
<option value="87">7&#8242;3&quot;</option><br />
<option value="88">7&#8242;4&quot;</option><br />
<option value="89">7&#8242;5&quot;</option><br />
<option value="90">7&#8242;6&quot;</option><br />
<option value="91">7&#8242;7&quot;</option><br />
<option value="92">7&#8242;8&quot;</option><br />
<option value="93">7&#8242;9&quot;</option><br />
<option value="94">7&#8242;10&quot;</option><br />
<option value="95">7&#8242;11&quot;</option></select>
</p>
<p> And unformatted:</p>
<div style="font-family:courier; overflow: scroll; white-space:nowrap;">
select :person, :height, (36..95).collect{|i|["#{(i/12).floor}' #{i%12}\"",i]}, {:selected=>@person.height}
</div>
]]></content:encoded>
			<wfw:commentRss>http://johnstanfield.com/?feed=rss2&amp;p=354</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
