<?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>Why So Scared &#187; Ruby</title>
	<atom:link href="http://www.whysoscared.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whysoscared.com</link>
	<description>A blog about; Programming, Music and Random Stuff</description>
	<lastBuildDate>Thu, 10 Jun 2010 02:43:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>select_tag / select input into my database rails</title>
		<link>http://www.whysoscared.com/select_tag-select-input-into-my-database-rails/</link>
		<comments>http://www.whysoscared.com/select_tag-select-input-into-my-database-rails/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 16:59:50 +0000</pubDate>
		<dc:creator>Juo</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.whysoscared.com/?p=346</guid>
		<description><![CDATA[In my posts form the input to the model can only be Dog or Cat, I&#8217;ve constructed the following code and assumed it would work, however the information input into the select_tag box was never going into my database.




1
2
3
4
5
6
7
8
9
10
11



&#60;% form_for(@post) do &#124;f&#124; %&#62;

    &#60;%= f.label :title %&#62;&#60;br /&#62;
    &#60;%= [...]]]></description>
			<content:encoded><![CDATA[<p style="padding-top: 0.5em; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; text-align: left; border-color: #ebdddd; margin: 0px;">In my posts form the input to the model can only be Dog or Cat, I&#8217;ve constructed the following code and assumed it would work, however the information input into the select_tag box was never going into my database.</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; margin-top: 0em; line-height: 1.3em; color: #999999; padding-right: 2em; text-align: right;">1
2
3
4
5
6
7
8
9
10
11</pre>
</td>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em; word-wrap: break-word; color: #f8f8f8; background-color: #141414; padding: 0px;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #dad085;">form_for</span>(<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #7587a6;">@post</span>) <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">do </span>|<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #7587a6;">f</span>| <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span>

<span style="padding-top: 0.2em; padding-bottom: 0.1em;">    &lt;%= f.label :title %&gt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span>br <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">/</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&gt;</span>
    <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%=</span> f.<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #dad085;">text_field</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:title</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span>

<span style="padding-top: 0.2em; padding-bottom: 0.1em;">    &lt;%= f.label :source %&gt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span>br <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">/</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&gt;</span>
    <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%=</span> select_tag <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:source</span>,  options_for_select([ <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">"Dog"</span>, <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">"Cat"</span>) <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span>

<span style="padding-top: 0.2em; padding-bottom: 0.1em;">    &lt;%= f.submit 'Create' %&gt;</span>

<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">end</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span></pre>
</pre>
</td>
</tr>
</tbody>
</table>
<p style="padding-top: 0.5em; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; text-align: left; border-color: #ebdddd; margin: 0px;">I finally got this to work by using;</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; margin-top: 0em; line-height: 1.3em; color: #999999; padding-right: 2em; text-align: right;">1</pre>
</td>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em; word-wrap: break-word; color: #f8f8f8; background-color: #141414; padding: 0px;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%=</span> f.select(<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:source</span>, options_for_select({<span style="padding-top: 0.2em; padding-bottom: 0.1em;"> </span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">: Dog</span> =&gt;<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">'Dog'</span>,<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:Cat</span> =&gt;<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">'Cat'</span>} <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span></pre>
</pre>
</td>
</tr>
</tbody>
</table>
<p style="padding-top: 0.5em; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; text-align: left; border-color: #ebdddd; margin: 0px;">If you put the options in a hash then they will be output in a random order, to output the options in a chosen order they need to be put into an array, this left me with the following code.</p>
<p style="padding-top: 0.5em; padding-right: 0px; padding-bottom: 0.5em; text-align: left; border-color: #ebdddd; margin: 0px;"><strong>View</strong></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; margin-top: 0em; line-height: 1.3em; color: #999999; padding-right: 2em; text-align: right;">1
2</pre>
</td>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em; word-wrap: break-word; color: #f8f8f8; background-color: #141414; padding: 0px;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%=</span> f.<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #dad085;">label</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:source</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;&lt;br /&gt;</span>
<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">&lt;</span><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">%=</span> f.select(<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cf6a4c;">:source</span>, options_for_select(<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #7587a6;">@source</span>)) <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">%&gt;</span></pre>
</pre>
</td>
</tr>
</tbody>
</table>
<p style="padding-top: 0.5em; padding-right: 0px; padding-bottom: 0.5em; text-align: left; border-color: #ebdddd; margin: 0px;"><strong>Controller</strong></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; margin-top: 0em; line-height: 1.3em; color: #999999; padding-right: 2em; text-align: right;">1</pre>
</td>
<td style="vertical-align: top;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em; word-wrap: break-word; color: #f8f8f8; background-color: #141414; padding: 0px;">
<pre style="font-family: 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #7587a6;">@source</span> <span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #cda869;">=</span> [[<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">'Dog'</span>],[<span style="padding-top: 0.2em; padding-bottom: 0.1em; color: #8f9d6a;">'Cat'</span>],]</pre>
</pre>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.whysoscared.com/select_tag-select-input-into-my-database-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Scrubyt to Screenscrape</title>
		<link>http://www.whysoscared.com/using-scrubyt-to-screenscrape/</link>
		<comments>http://www.whysoscared.com/using-scrubyt-to-screenscrape/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 23:24:04 +0000</pubDate>
		<dc:creator>Juo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.whysoscared.com/?p=156</guid>
		<description><![CDATA[At http://www.warez-dnb.com/ Im working on a bit of Ruby code that when finished is going to make 20 second samples of every single post.
I decided the simplest way to do this would to have a bot that scraped the website for Rapidshare links, went away and downloaded the links, extracted them, made the sample and [...]]]></description>
			<content:encoded><![CDATA[<p>At h<a href="ttp://www.warez-dnb.com/" target="_blank">ttp://www.warez-dnb.com/</a> Im working on a bit of Ruby code that when finished is going to make 20 second samples of every single post.</p>
<p>I decided the simplest way to do this would to have a bot that scraped the website for Rapidshare links, went away and downloaded the links, extracted them, made the sample and then uploaded them to our FTP server. (I did say simplest, not most elegant)</p>
<p>After a file is upload this PHP script tests if the samples are uploaded yet. <a href="http://www.whysoscared.com/php-function-check-if-a-file-or-url-exists">http://www.whysoscared.com/php-function-check-if-a-file-or-url-exists</a></p>
<p>To make the Ruby script I needed something that could not only screen scrape the webpage but also login. I was using hpricot but then we decided to make Rapidshare links on Warez-DnB only show up to registered users.</p>
<blockquote><p>require &#8216;rubygems&#8217;<br />
require &#8217;scrubyt&#8217;</p>
<p>#only the following parts should need editing<br />
baseurl = &#8220;http://www.warez-dnb.com/&#8221;<br />
username = &#8220;User&#8221;<br />
password = &#8220;Password&#8221;</p>
<p>data = Scrubyt::Extractor.define do<br />
fetch &#8220;#{baseurl}?action=login&#8221;<br />
fill_textfield &#8216;user&#8217;, username<br />
fill_textfield &#8216;passwrd&#8217;, password<br />
submit<br />
fetch &#8220;#{baseurl}?topic=672&#8243;<br />
link &#8216;//div/code&#8217;<br />
end</p></blockquote>
<p>This is the script that will actually scan each page. Using Scrubyt is super simple first it fetches the login page at Warez-DnB fills the username and password field and submits. Now its logged in.</p>
<p>After this the plan is to use a loop based off the RSS feed to see if the post is in the listings category and extract the Rapidshare links.</p>
<p>Its in fairly simple stages at the moment but ill post the majority of the script when its completed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whysoscared.com/using-scrubyt-to-screenscrape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
