<?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>Omri Shiv&#039;s Blog</title>
	<atom:link href="http://www.OmriShiv.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.OmriShiv.com/blog</link>
	<description>Don&#039;t look towards the future or life will pass you by unnoticed, don&#039;t look to the past or you will miss what&#039;s important, live in the present and enjoy every moment
</description>
	<lastBuildDate>Sat, 21 Aug 2010 10:40:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Seriously @steam_games, I&#8217;m ab&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1123</link>
		<comments>http://www.OmriShiv.com/blog/?p=1123#comments</comments>
		<pubDate>Sat, 21 Aug 2010 10:40:10 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1123</guid>
		<description><![CDATA[Seriously @steam_games, I&#8217;m abroad, why don&#8217;t you let me buy games from you with my verified credit card?]]></description>
			<content:encoded><![CDATA[<p>Seriously @<a href="http://twitter.com/steam_games" class="aktt_username">steam_games</a>, I&#8217;m abroad, why don&#8217;t you let me buy games from you with my verified credit card?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1123</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Droid certainly does. Just had&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1122</link>
		<comments>http://www.OmriShiv.com/blog/?p=1122#comments</comments>
		<pubDate>Fri, 13 Aug 2010 02:34:34 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1122</guid>
		<description><![CDATA[Droid certainly does. Just had a skype conversation where the other user used her phone as the webcam. Pretty slick]]></description>
			<content:encoded><![CDATA[<p>Droid certainly does. Just had a skype conversation where the other user used her phone as the webcam. Pretty slick</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1122</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto_Complete Goodness</title>
		<link>http://www.OmriShiv.com/blog/?p=1120</link>
		<comments>http://www.OmriShiv.com/blog/?p=1120#comments</comments>
		<pubDate>Thu, 12 Aug 2010 13:38:03 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1120</guid>
		<description><![CDATA[Zolio has been consuming a large part of my life this summer and I&#8217;m happy to say that it&#8217;s ready for testing. A few accounts are being generated and sent out to testers today who will hopefully find ways of &#8230; <a href="http://www.OmriShiv.com/blog/?p=1120">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Zolio has been consuming a large part of my life this summer and I&#8217;m happy to say that it&#8217;s ready for testing. A few accounts are being generated and sent out to testers today who will hopefully find ways of breaking the site so I can fix it.</p>
<p>The last feature that needed to be added is a way to create classes, assign teachers and students to those classes, create assignments, and have students post files to those assignments.</p>
<p>While this seems to be like quite an undertaking, Rails makes it really easy to do. What was interesting; however, was how the student goes about attaching files:</p>
<p>A student is enrolled in a class. A school has many classes. Classes have many users. This sort of logic grows out of control very quickly. Specifically for the file upload, a user has to specify which class he is attaching his file to; however, he is only allowed to attach files to classes within his school that he is enrolled in.</p>
<p>Because I love autocomplete so much, and because Rails makes it so easy to implement, I chose to use it for helping the user select what class to attach his file to. I could have used a drop down, but they seem so inelegant these days.</p>
<p>Autocomplete works by querying a specific table for a column. As text is typed in the box, javascript is used to keep making calls to the database to narrow down the list. I quickly realized I may run into a problem as we actually need to query two tables.</p>
<p>In one table, we have a list of classes. This list contains the name of the class as well as the school it is associated with. In another table, we have a list of user IDs and the class IDs they are associated with. These class IDs relate to the IDs of the classes in the class table (the one with the name and school). What we needed to do is somehow retrieve a list of the classes only the student is associated with, but retrieve it as a name, not the ID of the class. <a href="http://patshaughnessy.net/">Pat Shaughnessy&#8217;s Auto_complete</a> to the rescue:</p>
<p>In my controller, I have the familiar action for auto_complete:</p>
<pre class="brush:ruby">
	auto_complete_for :subject, :name do |list, params|
		list.by_user(params[:uid])
		end
</pre>
<p>Notice, it&#8217;s list.by_user which is a new named scope. Now, in my model I have</p>
<pre class="brush:ruby">
	named_scope :by_user, lambda{|user_id|{:include=>:users,:conditions=>["subjects_users.user_id=?", user_id]}}
</pre>
<p>This runs a join on the tables and finds us the classes (by name) associated with the user through the class ID pivot.</p>
<p>Really fun stuff</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1120</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Of course, the only time I&#8217;ve &#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1119</link>
		<comments>http://www.OmriShiv.com/blog/?p=1119#comments</comments>
		<pubDate>Tue, 10 Aug 2010 16:23:19 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1119</guid>
		<description><![CDATA[Of course, the only time I&#8217;ve ever called a chip company to complain about freshness, they&#8217;re in a meeting about how to better satisfy me&#8230;]]></description>
			<content:encoded><![CDATA[<p>Of course, the only time I&#8217;ve ever called a chip company to complain about freshness, they&#8217;re in a meeting about how to better satisfy me&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1119</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Someone please make a poster o&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1117</link>
		<comments>http://www.OmriShiv.com/blog/?p=1117#comments</comments>
		<pubDate>Tue, 10 Aug 2010 04:16:37 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1117</guid>
		<description><![CDATA[Someone please make a poster of this and then promptly sell it to me: http://bit.ly/bFsXEZ]]></description>
			<content:encoded><![CDATA[<p>Someone please make a poster of this and then promptly sell it to me: <a href="http://bit.ly/bFsXEZ" rel="nofollow">http://bit.ly/bFsXEZ</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1117</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entering some of my homebrew b&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1118</link>
		<comments>http://www.OmriShiv.com/blog/?p=1118#comments</comments>
		<pubDate>Tue, 10 Aug 2010 00:36:25 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1118</guid>
		<description><![CDATA[Entering some of my homebrew beers into Beersnobs&#8217; Son Of Brewzilla Homebrew Competition]]></description>
			<content:encoded><![CDATA[<p>Entering some of my homebrew beers into Beersnobs&#8217; Son Of Brewzilla Homebrew Competition</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1118</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Woes</title>
		<link>http://www.OmriShiv.com/blog/?p=1105</link>
		<comments>http://www.OmriShiv.com/blog/?p=1105#comments</comments>
		<pubDate>Tue, 03 Aug 2010 15:01:25 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1105</guid>
		<description><![CDATA[I have been working on a Rails application for a demonstration at Case. The application is a pretty standard CRM system whose use is to allow faculty on campus to find one another when they need specific things done that &#8230; <a href="http://www.OmriShiv.com/blog/?p=1105">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been working on a Rails application for a demonstration at Case. The application is a pretty standard CRM system whose use is to allow faculty on campus to find one another when they need specific things done that are out of their expertise. For instance, a medical student may have a business idea where he may need a rapid prototyping machine with a specific process. He can log onto the system and be connected with any faculty member who has listed this ability.</p>
<p>Apart from being secured behind Case&#8217;s Single Sign On as well as the possibility of integrating the Case LDAP Phone Book, the app has few &#8220;Wow&#8221; technologies. It includes auto-complete on almost all text entry fields so that as a faculty member starts looking for a &#8220;Rapid Prototyper&#8221;, the minute they type the first R, any machine that includes an R will show up. As they continue typing, the list will be weened out. </p>
<p>What is not so notable but took an incredibly amount of work is one of the requirements:<br />
For example, if a user comes to the system in need of a faculty member with specific expertise, they should be presented with every single expertise present in the system. There are checkboxes next to each one and the user can be as broad or as narrow with their criteria as possible. If the user doesn&#8217;t check any boxes, every faculty member (or equipment) is returned. If they check enough boxes so that no member matches the criteria, none are returned.</p>
<p>Here is where it gets interesting.</p>
<p>We have a users table which has all the personal information. We have an equipment table which contains all the equipment. Lastly, we have a process table which contains a list of process names.</p>
<p>There is also a table in the database that links all of these up. This table has a row for each process that is associated with a user and/or a machine. So for instance, if, in my process table, I have a process named &#8220;cooking&#8221; and it&#8217;s table id is 3, and in my user table, I am user 4, there would be a row in this pivot table that would say user_id 4, process_id 3. </p>
<p>The important thing to understand is that one user may be associated with multiple processes, so for instance, we can have multiple rows like this:</p>
<p>user_id		process_id<br />
4			3<br />
4			5<br />
3			2<br />
4			2</p>
<p>When the page is loaded, the process database is queried and a list of processes as well as checkboxes is created on the page. The user will then select the processes they are interested in. When they click submit, the magic happens.</p>
<p>Each checkbox value is actually the number of the process_id. Therefore, when the user clicks submit, the application has a list of these IDs that the user is searching for.</p>
<p>A SQL query for getting a user with an ID would look something like this:</p>
<pre class="brush:sql">
SELECT * FROM user_processes WHERE process_id = 3
</pre>
<p>The question is, how do we get more specific in our query. Let&#8217;s say we wanted any user that could cook as well as &#8220;chop&#8221; (id 5). Instinctively, we would come up with this query:</p>
<pre class="brush:sql">
SELECT * FROM user_processes WHERE (process_id = 3 AND process_id = 5)
</pre>
<p>However, it turns out that this simple idea turned into a week long headache for me.  After trying every possible google search, I finally stumbled upon this question posted on <a href="http://stackoverflow.com/questions/1330221/sql-filtering-by-multiple-items-in-the-same-column">Stack Overflow</a> and came up with what may be the most complex SQL query I have ever seen (though, probably not complex for SQL gurus):</p>
<pre class="brush:sql">
					SELECT  *
					FROM    (
					        SELECT  DISTINCT user_id
					        FROM    user_processes
					        ) mo
					WHERE   NOT EXISTS
					        (
					        SELECT  NULL
					        FROM    ("+@string+

					                ") list
					        WHERE   NOT EXISTS
					                (
					                SELECT  NULL
					                FROM    user_processes mii
					                WHERE   mii.user_id = mo.user_id
					                        AND mii.process_list_id = list.process_list_id
					                )
					        )")
</pre>
<p>Where @string is dynamicaly generated by Ruby based on the checkbox parameters:</p>
<pre class="brush:ruby">
			if (params[:query].length == 1)
				@string =  "SELECT "+params[:query][0]+" AS process_list_id"
			elsif (params[:query].length > 1)
				@string =  "SELECT "+params[:query][0]+" AS process_list_id"
				1.upto(params[:query].length-1) do |n|
					@string+=(" UNION ALL SELECT "+ params[:query][n].to_s)
				end
			end
</pre>
<p>This was quite a bit of work, but I&#8217;m glad it&#8217;s finally done. It was a great learning experience and I have to thank my friend Alex Budkie for putting up with me while I complained to him about how much easier this should have been (and for helping me interpret the Stack Overflow response).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1105</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So full of delicious grilled c&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1114</link>
		<comments>http://www.OmriShiv.com/blog/?p=1114#comments</comments>
		<pubDate>Mon, 02 Aug 2010 01:59:17 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1114</guid>
		<description><![CDATA[So full of delicious grilled cheese right now. Also, really happy to be moving into my new cubicle at Weatherhead tomorrow]]></description>
			<content:encoded><![CDATA[<p>So full of delicious grilled cheese right now. Also, really happy to be moving into my new cubicle at Weatherhead tomorrow</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1114</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Beauty Of Simplicity</title>
		<link>http://www.OmriShiv.com/blog/?p=1096</link>
		<comments>http://www.OmriShiv.com/blog/?p=1096#comments</comments>
		<pubDate>Wed, 28 Jul 2010 04:18:35 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1096</guid>
		<description><![CDATA[They say beauty is only skin deep; while that may true, it&#8217;s certainly hard to see the real beauty under the face of applications developed on Ruby on Rails (RoR or just, Rails). RoR is a, relatively, modern language built &#8230; <a href="http://www.OmriShiv.com/blog/?p=1096">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>They say beauty is only skin deep; while that may true, it&#8217;s certainly hard to see the real beauty under the face of applications developed on <a href="http://rubyonrails.org">Ruby on Rails</a> (RoR or just, Rails).</p>
<p>RoR is a, relatively, modern language built on Ruby. Developed by <a href="http://37signals.com/">37Signals</a>, Rails has been adopted to developer some of the most notable applications on the internet (<a href="http://twitter.com">Twitter</a>, <a href="http://github.org">Github</a>, and <a href="http://redmine.org">Redmine</a>). Even the <a href="http://yellowpages.com">Yellow Pages</a> uses Rails. The rise in popularity is of no surprise, Rails is both incredibly powerful, as well as incredibly easy to use; a combination that makes it beautiful. </p>
<p>For instance, take the simple example of a for loop in PHP:</p>
<pre class="brush:php">
for ($i = 0; $i<10; $i++){
echo $i;
}</pre>
<p>This would write "0,1,2,3,4,5,6,7,8,9"</p>
<p>In Ruby, this would be written as</p>
<pre class="brush:ruby">
(0..9).each { |i| puts i }
</pre>
<p>(there are much simpler ways of writing this: <a href="http://refactormycode.com/codes/2-ruby-simple-loop">http://refactormycode.com/codes/2-ruby-simple-loop</a>)</p>
<p>This is just a simple example of Ruby's ability to minimize frustration. While it may take a little getting used to (especially coming from stricter languages like C++), once you understand the language, it is simple and elegant. It reads like a language, not like code.</p>
<p>The great thing about Rails is that it takes Ruby's philosophy and extends it to the realm of web applications. No longer do developers have to write complicated SQL code (with a notable exception). Speaking of the database, relational tables are handled by models, while database changes are source controlled through migrations. Web routes are standardized so that CRUD applications follow the convention of /controller/action (for example creating a new user is usually /user/new). I could go on and on, but the bottom line is application development time is reduced, while code maintenance is eased. </p>
<p>While I still have a few gripes with Rails I have become a giant advocate of the MVC philosophy as well as the direction Rails is taking. It's incredibly easy to develop as well as deploy applications using mod_rack. </p>
<p>If you're interested, the big application I'm developing and launching is called <a href="http://zolio.com">Zolio</a>. There will be a future post about it and its place in education. I'd suggest heading over to the site and subscribing to be notified when Zolio officially launches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1096</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I found the most convoluted so&#8230;</title>
		<link>http://www.OmriShiv.com/blog/?p=1095</link>
		<comments>http://www.OmriShiv.com/blog/?p=1095#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:02:28 +0000</pubDate>
		<dc:creator>Omri</dc:creator>
				<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.OmriShiv.com/blog/?p=1095</guid>
		<description><![CDATA[I found the most convoluted solution to a simple SQL problem today: http://bit.ly/b5r1f0]]></description>
			<content:encoded><![CDATA[<p>I found the most convoluted solution to a simple SQL problem today: <a href="http://bit.ly/b5r1f0" rel="nofollow">http://bit.ly/b5r1f0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.OmriShiv.com/blog/?feed=rss2&amp;p=1095</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
