<?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>devedup.com &#187; ruby</title>
	<atom:link href="http://blog.devedup.com/index.php/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.devedup.com</link>
	<description></description>
	<lastBuildDate>Sun, 09 Oct 2011 16:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MD5 in Java (&#8230; and Ruby &amp; PHP)</title>
		<link>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/</link>
		<comments>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 22:43:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://blog.devedup.com/?p=57</guid>
		<description><![CDATA[Why doesn&#8217;t the standard Java SDK provide a method that returns a 32 character (128bit) String representation of  an MD5 encrypted string&#8230; just like most other languages do (PHP, Ruby)&#8230; i don&#8217;t know! Below are Ruby and PHP examples and then a Java implementation. Ruby implementation: require 'digest/md5' digest = Digest::MD5.hexdigest(&#34;encrypt this text&#34;) PHP implementation: [...]]]></description>
			<content:encoded><![CDATA[<p>Why doesn&#8217;t the standard Java SDK provide a method that returns a 32 character (128bit) String representation of  an MD5 encrypted string&#8230; just like most other languages do (PHP, Ruby)&#8230; i don&#8217;t know! Below are Ruby and PHP examples and then a Java implementation.</p>
<p>Ruby implementation:</p>
<pre class="brush: ruby;">require 'digest/md5'
digest = Digest::MD5.hexdigest(&quot;encrypt this text&quot;)</pre>
<p>PHP implementation:</p>
<pre class="brush: php;">&lt;?php
   $str = &quot;Hello&quot;;
   echo md5($str);
?&gt;</pre>
<p>Java implementation (2 methods for clarity):</p>
<pre class="brush: java;">import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.UnsupportedEncodingException

public class MD5 {

public static String digest(String text) {
      throws NoSuchAlgorithmException, UnsupportedEncodingException {
   MessageDigest md = MessageDigest.getInstance(&quot;MD5&quot;);
   byte[] md5hash = new byte[32];
   md.update(text.getBytes(&quot;iso-8859-1&quot;), 0, text.length());
   md5hash = md.digest();
   return convertToHex(md5hash);
}

private static String convertToHex(byte[] b) {
   StringBuilder result = new StringBuilder(32);
   for (int i = 0; i &amp;lt; b.length; i++) {
      result.append(
         Integer.toString( ( b[i] &amp;amp; 0xff ) + 0x100, 16).substring( 1 ));
   }
   return result.toString();
}
}</pre>
<p>This isn&#8217;t the fastest MD5 implementation, but that isn&#8217;t my goal here. I found quite a few implementations when searching, some of which gave results which were not even correct!</p>
<p>Hope this implementation helps someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.devedup.com/index.php/2009/06/07/md5-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord outside of Rails</title>
		<link>http://blog.devedup.com/index.php/2009/06/04/activerecord-outside-of-rails/</link>
		<comments>http://blog.devedup.com/index.php/2009/06/04/activerecord-outside-of-rails/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 16:27:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.devedup.com/?p=17</guid>
		<description><![CDATA[So you want to use ActiveRecord outside of the Rails framework? It&#8217;s not hard to do. Firstly make sure you have active record installed, which you can do by executing: gem install activerecord Then, the code below is all you need to get started (with an example DAO &#8211; DvdTitle at the end) require &#34;rubygems&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to use ActiveRecord outside of the Rails framework? It&#8217;s not hard to do. Firstly make sure you have active record installed, which you can do by executing:</p>
<pre class="brush: ruby;">gem install activerecord</pre>
<p>Then, the code below is all you need to get started (with an example DAO &#8211; DvdTitle at the end)</p>
<pre class="brush: ruby;">
require &quot;rubygems&quot;
require 'active_record'

ActiveRecord::Base.establish_connection(
  :adapter =&amp;gt; &quot;mysql&quot;,
  :host =&amp;gt; &quot;127.0.0.1&quot;,
  :username =&amp;gt; &quot;username&quot;,
  :database =&amp;gt; &quot;dvdsale_development&quot;,
  :password =&amp;gt; &quot;secret&quot;)

class DvdTitle &amp;lt; ActiveRecord::Base
end

puts DvdTitle.find(1).name
</pre>
<h4>My environment:</h4>
<p>Ruby version 1.8.6 (i386-mswin32)<br />
RubyGems version 1.3.3<br />
Rails version 2.2.2<br />
Active Record version 2.2.2</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.devedup.com/index.php/2009/06/04/activerecord-outside-of-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

