<?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>sarbastic &#187; code</title>
	<atom:link href="http://sarbastic.kennethbowen.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://sarbastic.kennethbowen.com</link>
	<description>sarbastic. adj. sardonic and bombastic. --sarbastically adv. --sarbastich n.</description>
	<lastBuildDate>Wed, 07 Jul 2010 01:00:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Installing RMagic on Debian/Ubuntu Linux</title>
		<link>http://sarbastic.kennethbowen.com/code/rmagic-debian</link>
		<comments>http://sarbastic.kennethbowen.com/code/rmagic-debian#comments</comments>
		<pubDate>Mon, 02 Oct 2006 21:52:11 +0000</pubDate>
		<dc:creator>Kenneth Bowen</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://sarbastic.kennethbowen.com/code/rmagic-debian</guid>
		<description><![CDATA[I&#8217;m working on an image manipulation program that requires the Ruby ImageMagick bindings, RMagick. I was unable to install RMagick from either the gem, or the Debian package. Building RMagick from source didn&#8217;t work either. The following worked for both a Debian Sarge box, and an Xubuntu laptop. I hope it saves someone some grief. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on an image manipulation program that requires the <a href="http://www.ruby-lang.org/en/">Ruby</a>
<a href="http://www.imagemagick.org/">ImageMagick</a> bindings, <a href="http://rmagick.rubyforge.org/">RMagick</a>. I was unable to install <a href="http://rmagick.rubyforge.org/">RMagick</a> from
either the gem, or the <a href="http://www.us.debian.org/">Debian</a> package. Building <a href="http://rmagick.rubyforge.org/">RMagick</a> from source
didn&#8217;t work either.</p>

<p>The following worked for both a <a href="http://www.us.debian.org/releases/stable/">Debian Sarge</a> box, and an <a href="http://www.xubuntu.org/">Xubuntu</a>
laptop. I hope it saves someone some grief.</p>

<pre><code>$ dpkg -l | grep magick
  ii  imagemagick    6.0.6.2-2.7    Image manipulation programs
  ii  libmagick6     6.0.6.2-2.7    Image manipulation library
  ii  perlmagick     6.0.6.2-2.4    A perl interface to the libMagick
  ii  rubymagick     0.1.3-13       Ruby interface for ImageMagick
</code></pre>

<p>Get rid of the rubymagick package</p>

<pre><code>$ apt-get remove --purge rubymagick
</code></pre>

<p>Install the dev versions of libmagick6 and Ruby 1.8 <em><strong>edit</strong>: for Xubuntu, install libmagick9</em></p>

<pre><code>$ apt-get install libmagick6-dev ruby1.8-dev
</code></pre>

<p>Install rmagick from the gem</p>

<pre><code>$ gem install rmagick
</code></pre>

<p>You can test the install by running a simple app like this, which will print the EXIF
data from an image:</p>

<pre><code>require 'rubygems'
require 'RMagick'

require 'pp'

img = Magick::Image.read('test.jpg').first
exif_data = img.get_exif_by_entry()

pp exif_data
</code></pre>

<h3>Update:</h3>

<p>As of Xubuntu 7.04 (Feisty Fawn), you need libmagick9-dev.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarbastic.kennethbowen.com/code/rmagic-debian/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript: Numbers to Strings</title>
		<link>http://sarbastic.kennethbowen.com/code/javascript-numbers-to-strings</link>
		<comments>http://sarbastic.kennethbowen.com/code/javascript-numbers-to-strings#comments</comments>
		<pubDate>Fri, 05 May 2006 04:01:56 +0000</pubDate>
		<dc:creator>Kenneth Bowen</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://sarbastic.kennethbowen.com/numbers-to-strings</guid>
		<description><![CDATA[Javascript is pretty casual about strings and numbers. Because javascript is an untyped language, it&#8217;s easy to get used doing things like: var aString = "kb" + 63; // results in string "kb63" Instead of choking, javascript will treat the number 63 as a string and concatenate them together for you. Sometimes, you really need [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is pretty casual about strings and numbers. Because javascript is
an <i>untyped</i> language, it&#8217;s easy to get used doing things like:
<pre>
var aString = "kb" + 63; // results in string "kb63"
</pre>
Instead of choking, javascript will treat the number 63 as a string and
concatenate them together for you.</p>

<p>Sometimes, you really need a string or a number. For example, you might have a
database key that you want to use as an array index:
<pre>
var dbKey = 546735289; // some surrogate key out of the database.
var dbObject = {
   name: "Kenneth",
   age: "old",
   likes: "beer"
};
var theArray = new Array();
theArray[dbKey] = dbObject;
</pre></p>

<p>But now, <code>theArray.length</code> is 546735290 &#8211; one more than the
index. Javascript arrays are sparse, so this might not cause any memory
problems since memory should only be allocated for the single array element at
546735289. However, if you loop through the array using a for loop <code>
theArray.length</code> times, performing some expensive operation inside the
loop &#8211; such as a complex DOM manipulation &#8211; you might get into trouble.</p>

<p>In this case, you&#8217;d be better off using a named property instead of a numeric
array index. To convert a number to a string:</p>

<pre><code>    // use the toString method
    dbKey.toString

    // use the String() constructor
    String(dbKey)

    // concatenate a number with empty string. Crude and ugly
    dbKey + ""
</code></pre>

<p>What if you want to go the other way, from a string to a number? The cheap and
easy way is to do some math on the string:</p>

<pre><code>    var myString = "1000";
    var myNumber = myString * 1
</code></pre>

<p>Don&#8217;t try and use the <code>+</code> operator:</p>

<pre><code>    // won't work. javascript thinks concatenate
    var myString = "1000";
    var myNumber = myString + 0; // results in the string 10000
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://sarbastic.kennethbowen.com/code/javascript-numbers-to-strings/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
