<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>The main purpose of #devguru is to provide the best tutorials, tips and hacks that are connected with our work and passion, which is web developing. 
Everyday we learn something new. We read articles, we solve problems that we deal with at work. We want to share our experience, knowledge, and the stuff we find on web and we find interesting.

If you want to contribute, find us on Flaker.pl or Facebook, send us a link and if we like it - you’ll certainly find it here.</description><title>Devguru</title><generator>Tumblr (3.0; @devguru)</generator><link>http://devguru.pl/</link><item><title>Rails Bad Practices #2 - using Time.now in scope</title><description>&lt;p&gt;Ever wondered how to get your time-dependent scopes to act like bunch of lunatics? &lt;/p&gt;
&lt;p&gt;do this: &lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
class User &lt; ActiveRecord::Base

 scope :active, where(:activated_at.gt =&gt; Time.now)

end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and your list of active users will stub every time you restart your app. Cool!&lt;/p&gt;
&lt;p&gt;Of course, this &lt;a href="http://is.gd/WET0Z7" target="_blank"&gt;great trick&lt;/a&gt; can’t be achieved with this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
class User &lt; ActiveRecord::Base

 scope :active, lambda{ where(:activated_at.gt =&gt; Time.now) }

end&lt;/code&gt;&lt;/pre&gt;</description><link>http://devguru.pl/post/6790941054</link><guid>http://devguru.pl/post/6790941054</guid><pubDate>Wed, 22 Jun 2011 16:54:15 +0200</pubDate></item><item><title>Rails Bad Practices #1 - sql injection.</title><description>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank"&gt;Sql injection&lt;/a&gt; is a very nice trick, however it’s really hard to achieve with Rails. This few simple lines of code allow all of your users to execute sql whatever way they want:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
#app/models/user.rb
class User &lt; ActiveRecord::Base

  scope :very_clever_scope, lambda{|name_or_id| where("name = #{name_or_id} OR id=#{name_or_id}") 

end
&lt;/code&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
#app/controllers/users_controller.rb
class UsersController &lt; ApplicationController 

  def show
    #uber clever params[:id] backwards compability
    User.very_clever_scope(params[:id]).find(:first)
  end

end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;And now you can &lt;a href="http://en.wikipedia.org/wiki/Irony" target="_blank"&gt;relax and enjoy&lt;/a&gt; DROP ALL TABLES queries.&lt;/p&gt;</description><link>http://devguru.pl/post/6380015878</link><guid>http://devguru.pl/post/6380015878</guid><pubDate>Fri, 10 Jun 2011 11:15:00 +0200</pubDate></item><item><title>Recursively Setting Deep Hash Value - revisited</title><description>&lt;p&gt;&lt;a title="Recursively Setting Deep Hash Value" href="http://www.rubyflow.com/items/5868-recursively-setting-deep-hash-value" target="_blank"&gt;This&lt;/a&gt; great tip allows you to recursively set hash value - really useful thing when you have to generate complicated hash. &lt;/p&gt;
&lt;p&gt;One gotcha that i found about this is, that after generating SuperHash instance you must remember about reseting the default value of this hash.&lt;/p&gt;
&lt;p&gt;Consider this: &lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt; 
class SuperHash &lt; Hash   
  def initialize     
    super { |h, k| h[k] = SuperHash.new }   
  end 
end  
&gt; suuper = SuperHash.new #=&gt; {} 
&gt; suuper['mad']['sheep'] = false    
&gt; suuper['mad']['sheep'] #=&gt; false 
&gt; suuper['mad']['cow'] #=&gt; {} 
&gt; supper['calm']['sheep'] #=&gt; {} &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that every undefined key, no matter how deeply nested will return empty hash instead of nil. This was a bit misleading for me since i used SuperHash instance to check complex conditions&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
 &gt; !!{} #=&gt; true 
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Whatever i did, all conditions were always true :)&lt;/p&gt;
&lt;p&gt;The solution of course w’d be to reset SuperHash default after generating full structure:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt; 
&gt; suuper = SuperHash.new #=&gt; {} 
&gt; suuper['mad']['sheep'] = false
&gt; suuper.default = nil #=&gt; nil
&gt; supper['calm']#=&gt; nil
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;However, as my colleague pointed out, reseting default only on suuper wont fix the issue, since nested hashes inside still have their own defaults. What we need to do is complete rewrite of our superhash back to hash again. This can be easily achievied with this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt; 
&gt; suuper = SuperHash.new #=&gt; {} 
&gt; suuper['mad']['sheep'] = false #=&gt; false
&gt; suuper = {}.update(suuper)
&gt; supper['calm'] #=&gt; nil
&gt; suuper['mad']['cow'] #=&gt; nil
&gt; supper['calm']['sheep'] #=&gt; Error
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;And now we are golden :)&lt;/p&gt;</description><link>http://devguru.pl/post/6032714814</link><guid>http://devguru.pl/post/6032714814</guid><pubDate>Tue, 31 May 2011 11:19:00 +0200</pubDate></item><item><title>RVM readline library problems?</title><description>&lt;p&gt;4 steps to resolve:&lt;/p&gt;

&lt;p&gt;1. sudo apt-get install ncurses-dev&lt;br/&gt;
2. cd $HOME/.rvm/src/ruby-1.9.2-p180/ext/readline&lt;br/&gt;
3. ruby extconf.rb — —with-readline-dir=”$HOME/.rvm/usr”&lt;br/&gt;
4. make install&lt;/p&gt;

&lt;p&gt;More information:&lt;br/&gt;
&lt;a href="http://beginrescueend.com/packages/readline/" target="_blank"&gt;http://beginrescueend.com/packages/readline/&lt;/a&gt;&lt;/p&gt;</description><link>http://devguru.pl/post/6032319269</link><guid>http://devguru.pl/post/6032319269</guid><pubDate>Tue, 31 May 2011 10:50:15 +0200</pubDate></item><item><title>Pow</title><description>&lt;p&gt;Since most of us use macs and most of us work on few projects at the same time we really &lt;span&gt;appreciate&lt;/span&gt; what 37signals did. Go and check out &lt;a target="_blank" href="http://pow.cx/"&gt;Pow&lt;/a&gt; project.&lt;/p&gt;</description><link>http://devguru.pl/post/4876595256</link><guid>http://devguru.pl/post/4876595256</guid><pubDate>Sat, 23 Apr 2011 23:47:57 +0200</pubDate></item><item><title>humans.txt</title><description>&lt;p&gt;There is an interesting initiative coming from Spain. The idea is to put humans.txt file containing information about people who have contributed to building the site. More at &lt;a title="humanstxt.org" href="http://humanstxt.org" target="_blank"&gt;humanstxt.org&lt;/a&gt;&lt;/p&gt;</description><link>http://devguru.pl/post/4754236433</link><guid>http://devguru.pl/post/4754236433</guid><pubDate>Tue, 19 Apr 2011 22:00:33 +0200</pubDate></item><item><title>Never run rails 3 application on ruby 1.8.7</title><description>&lt;p&gt;You must update to 1.9.2. RoR3 applications on old ruby are slow. &lt;span&gt;REALLY&lt;/span&gt; SLOW.&lt;/p&gt;</description><link>http://devguru.pl/post/4744491187</link><guid>http://devguru.pl/post/4744491187</guid><pubDate>Tue, 19 Apr 2011 13:11:46 +0200</pubDate></item><item><title>Incompatible character encodings with serialized fileds in ruby 1.9.2</title><description>&lt;p&gt;Watchout for serialized fields in ActiveRecord. On ruby 1.9.2 strings in such fields get saved with ASCII-8BIT encoding, not with UTF-8 as you w’d expect.&lt;/p&gt;</description><link>http://devguru.pl/post/4744465344</link><guid>http://devguru.pl/post/4744465344</guid><pubDate>Tue, 19 Apr 2011 13:09:32 +0200</pubDate></item><item><title>Coffeescript flame.</title><description>&lt;p&gt;Since we use coffeescript at netguru for some time now, we c’d sit back and relax while entire RoR community was burning in the hot fire of &lt;a href="https://github.com/rails/rails/commit/9f09aeb8273177fc2d09ebdafcc76ee8eb56fe33#comments" target="_blank"&gt;this flame&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Our favourite pics from the comments:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/HJK6sJ" target="_blank"&gt;http://is.gd/HJK6sJ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/NZuBtX" target="_blank"&gt;http://is.gd/NZuBtX&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/qTNFdT" target="_blank"&gt;http://is.gd/qTNFdT&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/SeN28X%C2%A0" target="_blank"&gt;http://is.gd/SeN28X &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/CBbcJH" target="_blank"&gt;http://is.gd/CBbcJH&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/UTSAtX" target="_blank"&gt;http://is.gd/UTSAtX&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And this one pretty much sums it up:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://is.gd/QUlhVZ" target="_blank"&gt;http://is.gd/QUlhVZ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;:)&lt;/p&gt;</description><link>http://devguru.pl/post/4615839764</link><guid>http://devguru.pl/post/4615839764</guid><pubDate>Thu, 14 Apr 2011 23:56:00 +0200</pubDate></item><item><title>Mongoid 2.0 and its new documentation</title><description>&lt;a href="http://mongoid.org/"&gt;Mongoid 2.0 and its new documentation&lt;/a&gt;</description><link>http://devguru.pl/post/4551036295</link><guid>http://devguru.pl/post/4551036295</guid><pubDate>Tue, 12 Apr 2011 13:42:32 +0200</pubDate></item><item><title>Beginner railscasts.</title><description>&lt;p&gt;#26 - 6 min&lt;/p&gt;
&lt;p class="p1"&gt;#47 - 9 min&lt;/p&gt;
&lt;p class="p1"&gt;#48 - 10 min&lt;/p&gt;
&lt;p class="p1"&gt;#62 - 11 min&lt;/p&gt;
&lt;p class="p1"&gt;#134 - 7 min&lt;/p&gt;
&lt;p class="p1"&gt;#140 - 4 min&lt;/p&gt;
&lt;p class="p1"&gt;#152 - 9 min&lt;/p&gt;
&lt;p class="p1"&gt;#154 - 8 min&lt;/p&gt;
&lt;p class="p1"&gt;This are the numbers of &lt;a href="http://railscasts.com/" target="_blank"&gt;Railscasts&lt;/a&gt; episodes that every Rails newbie should watch (obligatory for every newcommer in our company).  &lt;/p&gt;</description><link>http://devguru.pl/post/3598072328</link><guid>http://devguru.pl/post/3598072328</guid><pubDate>Wed, 02 Mar 2011 10:06:00 +0100</pubDate></item><item><title>Webrats http_accept method missing in Capybara.</title><description>&lt;p&gt;If you are missing Webrats http_accept method after migrating from Webrat to Capybara this c’d be solution for rack based driver:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;page.driver.header "Accept", "application/javascript"&lt;/code&gt;&lt;/pre&gt;</description><link>http://devguru.pl/post/3198682691</link><guid>http://devguru.pl/post/3198682691</guid><pubDate>Wed, 09 Feb 2011 15:21:20 +0100</pubDate></item><item><title>Alternative hash syntax in Ruby 1.9</title><description>&lt;a href="http://blog.peepcode.com/tutorials/2011/rip-ruby-hash-rocket-syntax"&gt;Alternative hash syntax in Ruby 1.9&lt;/a&gt;</description><link>http://devguru.pl/post/2621729718</link><guid>http://devguru.pl/post/2621729718</guid><pubDate>Thu, 06 Jan 2011 11:21:38 +0100</pubDate></item><item><title>Shortcut for finding objects in rails console</title><description>&lt;p&gt;Tired of typing User.find_by_verylongattribute_name(‘something’) into rails console? This little alias made my day: &lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
class User &lt; ActiveRecord::Base

  def self.[](arg)
    self.find_by_userlogin(arg)
  end

end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Usage:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
&gt;&gt; User['madsheep']
=&gt; #&lt;User id: 1, userlogin: "madsheep"&gt;
&lt;/code&gt;
&lt;/pre&gt;</description><link>http://devguru.pl/post/2608273624</link><guid>http://devguru.pl/post/2608273624</guid><pubDate>Wed, 05 Jan 2011 12:55:00 +0100</pubDate></item><item><title>Saving embedded attachments with Mongoid and Carrierwave</title><description>&lt;p&gt;While developing our latest application, we discovered that Mongoid doesn’t save embedded objects when their parent is saved. On the &lt;a href="https://github.com/jnicklas/carrierwave/issues#issue/81" target="_blank"&gt;GitHub page of this issue &lt;/a&gt; there were suggested some solutions and it appears that &lt;a href="https://gist.github.com/574705" target="_blank"&gt;one posted by mcasimir&lt;/a&gt; works very well.
What happened to be the next problem is that with this solution comes the issue with saving attachments’ filenames. We’ve found a solution somewhere on GitHub and changed it a little so it works with overriding filenames :
&lt;pre&gt; &lt;code class="ruby"&gt;
  after_validation :extract_filename

  def extract_filename
    img_original_filename = img.instance_variable_get("@original_filename")
    if self.img.class.filename and img_original_filename.present?
      self.img_filename = self.img.class.filename
    elsif img_original_filename.present?
      self.img_filename = img_original_filename
    end
  end
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;</description><link>http://devguru.pl/post/2511023380</link><guid>http://devguru.pl/post/2511023380</guid><pubDate>Wed, 29 Dec 2010 11:57:51 +0100</pubDate></item><item><title>Thought of the day:</title><description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Each time someone thinks it’s a good idea to create model without timestamps or use habtm instead of hmt - Mighty God kills &lt;a title="Have mercy!" href="http://img232.imageshack.us/img232/3927/cutekitty.jpg" target="_blank"&gt;little kitten&lt;/a&gt;.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</description><link>http://devguru.pl/post/2403597906</link><guid>http://devguru.pl/post/2403597906</guid><pubDate>Tue, 21 Dec 2010 17:36:10 +0100</pubDate></item><item><title>Transfering databases from one development machine to another.</title><description>&lt;p&gt;&lt;a href="http://proxylocal.com/" target="_blank"&gt;&lt;a href="http://proxylocal.com/" target="_blank"&gt;http://proxylocal.com/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://adam.heroku.com/past/2009/2/11/taps_for_easy_database_transfers/" target="_blank"&gt;&lt;a href="http://adam.heroku.com/past/2009/2/11/taps_for_easy_database_transfers/" target="_blank"&gt;http://adam.heroku.com/past/2009/2/11/taps_for_easy_database_transfers/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Those two solutions can be easily combined to transfer mysql database from one development machine to another (no more nasty dump emailing/sending/sharing etc.)&lt;/p&gt;
&lt;p&gt;On first machine:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;taps server mysql://db_user:db_pass@localhost/database_name online_user online_pass -p 5000&lt;/code&gt;
&lt;code class="bash"&gt;proxylocal 5000&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Last command will pop out an address (like &lt;a href="http://tz87.t.proxylocal.com/" target="_blank"&gt;http://tz87.t.proxylocal.com/&lt;/a&gt; or similar)&lt;/p&gt;
&lt;p&gt;And second machine (to obtain sqlite database):&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;taps pull sqlite://development.sqlite3 http://online_user:online_pass@tz87.t.proxylocal.com&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;How cool is that?&lt;/p&gt;</description><link>http://devguru.pl/post/2400911337</link><guid>http://devguru.pl/post/2400911337</guid><pubDate>Tue, 21 Dec 2010 11:45:53 +0100</pubDate></item><item><title>ThinkingSphinx - delta field name</title><description>&lt;pre&gt;&lt;code class="ruby"&gt;set_property :delta_column =&gt; 'another_delta_field'&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adding this property to sphinx indexes on your model allows you to use different field name then ‘delta’ for delta indexing - useful when two stages of your application share the same database.&lt;/p&gt;</description><link>http://devguru.pl/post/2388243221</link><guid>http://devguru.pl/post/2388243221</guid><pubDate>Mon, 20 Dec 2010 15:46:25 +0100</pubDate></item><item><title>FQL in Fgraph</title><description>&lt;p&gt;Very simple way to use FQL in Fgraph (&lt;a href="https://github.com/jugend/fgraph" target="_blank"&gt;&lt;a href="https://github.com/jugend/fgraph" target="_blank"&gt;https://github.com/jugend/fgraph&lt;/a&gt;&lt;/a&gt;) with query caching.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;require 'digest/sha1'
module FGraph
  class Client
    def fql(query)
      @cached_query ||= {}
      @cached_query[Digest::SHA1.hexdigest(query)] ||= HTTParty.get("https://api.facebook.com/method/fql.query", :query =&gt; {:query =&gt; query, :access_token =&gt; self.options[:access_token], :format =&gt; :json} )
    end   
  end
end&lt;/code&gt;&lt;/pre&gt;</description><link>http://devguru.pl/post/2184611571</link><guid>http://devguru.pl/post/2184611571</guid><pubDate>Sun, 12 Dec 2010 10:52:03 +0100</pubDate></item><item><title>Interactive Web apps - brainstorming @ Netguru</title><description>&lt;p&gt;Small brainstorming about solutions to do even more interactive Web apps.&lt;/p&gt;

&lt;p&gt;
&lt;object id="__sse6089218" width="425" height="355"&gt;
&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=modernwebapplicationmodel-101209060437-phpapp02&amp;stripped_title=modern-web-application-model&amp;userName=mtaberski"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed name="__sse6089218" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=modernwebapplicationmodel-101209060437-phpapp02&amp;stripped_title=modern-web-application-model&amp;userName=mtaberski" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;
&lt;script src="http://b.scorecardresearch.com/beacon.js?c1=7&amp;c2=7400849&amp;c3=1&amp;c4=&amp;c5=&amp;c6="&gt;&lt;/script&gt;</description><link>http://devguru.pl/post/2153803691</link><guid>http://devguru.pl/post/2153803691</guid><pubDate>Thu, 09 Dec 2010 13:20:14 +0100</pubDate></item></channel></rss>

