Tuesday, June 29, 2010

Google Data on Rails

Google Data on Rails

"Where's Ruby on the list of client libraries?"
Motivated by the ferocious appetite of our developers and the enduring popularity of Ruby on Rails (RoR), Jeff Fisher has forged a Ruby utility library from the fiery depths of Mount Doom. Mind you, it's not a full-blown client library, but it does handle the fundamentals like authentication and basic XML manipulation. It also requires you to work directly with the Atom feed using the REXML module and XPath.

http://code.google.com/apis/gdata/articles/gdata_on_rails.html

Issue #6: All Stuff, No Fluff



The digital edition (PDF) is available globally at no cost.
The print edition is available in US, UK and Canada (8.80 USD + shipping).
Read the digital edition
36 pages, full-color. Inside:
  • Beautifying Your Markup With Haml and Sass by Ethan Gunderson
  • Scaling Rails by Gonçalo Silva
  • Interview with Sarah Allen by Rupak Ganguly
  • Data Extraction with Hpricot by Jonas Alves
  • Deployment with Capistrano by Omar Meeky
  • Fake Data – The Secret of Great Testing by Robert Hall
  • RubyConf India 2010 coverage by Judy Das
  • Previous and Next Buttons by James Schorr
  • RVM – The Ruby Version Manager by Markus Dreier
  • Interview with Michael Day of Prince XML by Olimpiu Metiu
http://railsmagazine.com/issues/6

Sunday, June 27, 2010

Sammy

Sammy is a tiny javascript framework built on top of jQuery. It’s RESTful Evented JavaScript.

jQuery is probably the fastest, most robust way to abstract basic low-level Javascript functionality that every Javascript devleoper needs. However, it really remains low-level and does not imply any structure or organization for larger scale Javascript applications.

http://code.quirkey.com/sammy/

Avoid memory leaks in your ruby/rails code and protect you against denial of service

We heard a lot about that Ruby is cool cause we do not have to care about memory, the garbage collector does it for us. Well, that’s kind of true, but this does not mean we can write code without keeping in mind on what’s is going on under our ruby code.

Ruby symbol memory leak

We all know that using symbols instead of strings is a good practice to have, it’s faster and it saves your memory. Yes but at what price ? Symbols are faster in part cause they are created just one time in memory, that’s great ! But then ? they will stay forever in memory
That means, do not convert everything in symbol ! Be sure to well know what you are converting in symbol.

http://www.tricksonrails.com/2010/06/avoid-memory-leaks-in-ruby-rails-code-and-protect-against-denial-of-service/

Monday, June 21, 2010

Less.js Will Obsolete CSS

If you design websites you may have heard of interesting tools called CSS pre-processors. A couple of great ones are LESS and SASS.
Here’s an example of LESS code to give you an idea of what it does:

@brand-color: #3879BD;

.rounded(@radius: 3px) {
    -webkit-border-radius: @radius;
    -moz-border-radius: @radius;
    border-radius: @radius;
}

#header {
    .rounded(5px);
    a {
        color: @brand-color;
        &:hover {
            color: #000;
        }
    }
}


and then you would precompile it to some CSS. Not anymore, now you can natively link to the less:

HTML:
<link rel="stylesheet/less" href="/stylesheets/main.less" type="text/css" />
<script src="http://lesscss.googlecode.com/files/less-1.0.18.min.js"></script>
 
Now less.js will unpack the file and do its thing... making sure that the final CSS will be fully cacheable. Less.js has been written as a CommonJS module so you can run it on the server via node, or in the browser on the fly.


http://ajaxian.com/archives/do-less-with-less-js?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ajaxian+%28Ajaxian+Blog%29
http://fadeyev.net/2010/06/19/lessjs-will-obsolete-css/

Sunday, June 20, 2010

Custom Subdomains in Rails 3

Rails 3 supports subdomains out of the box, which is great. But did you know that the constraints in the Router can actually match patterns too? This means instead of hardcoding each subdomain into your routes you can allow your customers to decide their own subdomains.
However, we have to be careful with pattern matching on the subdomain. There are obvious subdomains we don’t want to match. Like ‘www’, ”, nil, and others that we may reserve. In this case using a pattern match might not be best.

http://bcardarella.com/post/716951242/custom-subdomains-in-rails-3

Executing private methods

To execute a private method simply delegate the call to method 'send' e.g.
class TicketSystem
  attr_reader :current_ticket
  
  def initialize()
    @current_ticket = 0
  end

  def make_purchase
    @current_ticket += 1
  end

  private

  def print_private_expenses
    puts 'private expenses now printing ...'
  end
end

ts = TicketSystem.new

ts.make_purchase
#=> 1

ts.current_ticket
#=> 1 

ts.print_private_expenses
#=> NoMethodError: private method `print_private_expenses' called for #

ts.send :print_private_expenses
#=> private expenses now printing ...

http://snippets.dzone.com/posts/show/11665

Thursday, June 17, 2010

Wednesday, June 16, 2010

Rethinking PDF Creation in Ruby

What's the big deal?

  1. HTML+CSS - Assuming you're a web developer, there's a good chance that you already know HTML and can work with it efficiently.
  2. CSS3 - We get WebKit's CSS3 support for free. This means effects like drop shadows, rounded borders, transformations and others are super-easy. (Note: effects requiring blur radius do not work.)
  3. Testing - We have tools built into our normal workflow for testing HTML. You can even use Cucumber to drive the development of a PDF with PDFKit.
To give you an idea of how well this fits into our normal workflow here at Relevance, this is how we built out our PDF reports:
  1. Our designer mocked up a sample PDF and converted it to HTML+CSS.
  2. Using Cucumber to drive development, we created a controller action to generate this HTML view of the PDF. (It was just another URL in our app.)
  3. We added a screen-only stylesheet to the HTML that mimics the look of a PDF reader. This allowed us to get a feel of how it would look as a PDF.
  4. Using a bit of Rack Middleware that ships with PDFKit, we can get the PDF version of that web page by simply appending '.pdf' to the url.
  5. We're done. No crazy extra class to handle PDF rendering. No need to spend all day reading through docs to learn the obscure code and magic incantations required to generate your PDF.

Samples

  • PDF of google.com - PDF rendered from http://google.com
  • CSS3 Examples - Sample rendering of common CSS3 effects including border-radius, text-shadow, box-shadow, and border-image. Notice the lack of a blur radius on text-shadow and box-shadow.
  • Sample HTML page with PDF viewer CSS - Example of using a single HTML source to render both a screen version and a PDF version. Uses a media="screen" and media="all" to mark relevant CSS.
  • PDF generated from PDF viewer HTML - PDF generated from sample HTML above. You must tell PDFKit to only use print stylesheets in order to achieve this effect (PDFKit.new(html, :print_media_type => true)).
http://thinkrelevance.com/blog/2010/06/15/rethinking-pdf-creation-in-ruby.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+relevance-llc+%28Relevance,+Inc.%29&utm_content=Google+Reader

Monday, June 14, 2010

Deep_merge: Ruby Recursive Merging for Hashes

Ruby provides some nice merge capabilities in hash and array. But it rightly doesn’t give us recursive merging, because it’s too poorly defined to standardize. However, recursive merging sometimes solves problems that can’t be solved other ways.
Take this code:
h1 = {:x => {:y => [4,5,6], :z => [7,8,9]}}
h2 = {:x => {:y => [1,2,3], :z => 'xyz'}}
If you want to merge these two hashes, what should happen? Well there are several possibilities. Let’s see how deep_merge handles it:
h2.deep_merge!(h1)
# results: h2 = {:x=>{:z=>[7, 8, 9], :y=>[1, 2, 3, 4, 5, 6]}}
# notice we overwrote 'xyz'! (That's what the bang means)
# Let's try it without the bang:
h1 = {:x => {:y => [4,5,6], :z => [7,8,9]}}
h2 = {:x => {:y => [1,2,3], :z => 'xyz'}}
h2.deep_merge(h1)
# results: h2 = {:x=>{:z=>"xyz", :y=>[1, 2, 3, 4, 5, 6]}}
# notice 'xyz' didn't get overwritten this time. No bang.
Let’s get a little more complicated with a “knockout” merge. We introduce a special string “–” which can “knockout” an element in an existing hash or array element:
h1 = {:x => {:y => ["d","e","--c"]}}
h2 = {:x => {:y => ["a","b","c"]}}
h2.ko_deep_merge!(h1)
# h2 = {:x=>{:y=>["a", "b", "d", "e"]}}
# notice no "c" any more!
Many of these features are configurable to your needs – feel free to read up in the source code. Home page and installation instructions are here: http://trac.misuse.org/science/wiki/DeepMerge

http://www.misuse.org/science/2008/05/19/deep_merge-ruby-recursive-merging-for-hashes/

jQuery Globalization Plugin from Microsoft

Today, MS released a prototype of a new jQuery Globalization Plugin that enables you to add globalization support to your JavaScript applications. This plugin includes globalization information for over 350 cultures ranging from Scottish Gaelic, Frisian, Hungarian, Japanese, to Canadian English.  We will be releasing this plugin to the community as open-source.
You can download our prototype for the jQuery Globalization plugin from our Github repository: http://github.com/nje/jquery-glob
You can also download a set of samples that demonstrate some simple use-cases with it here.

http://weblogs.asp.net/scottgu/archive/2010/06/10/jquery-globalization-plugin-from-microsoft.aspx
Come learn about Rails! Come meet other Rails developers!  Come show the strength of the Israeli Ruby community!

http://www.facebook.com/event.php?eid=124149557625744&ref=mf

Javascript: Copy To Clipboard Cross Browser

Writing Cross-Browser Dynamic HTMLIf you use any script for syntax highlighting, you'll see most of them has "copy to clipboard" feature. This is a fascinating thing done with Javascript.
  1.  Copy to clipboard is very easy in Internet Explorer
  2.  Flash solution for other browsers
  3.  Zero Clipboard: A Javascript library for copy to clipboard functionality
http://www.deluxeblogtips.com/2010/06/javascript-copy-to-clipboard.html

Sunday, June 13, 2010

jQuery plugins

jquery calendar thumb
wdCalendar is a jquery based google calendar clone. It cover most google calendar features.
  • Day/week/month view provided.
  • create/update/remove events by drag & drop.
  • Easy way to integrate with database.
  • All day event/more days event provided.
See it in actionCheck documentation | download
jquery calendar thumb

wdScrollTab is a tab panel which has ability to scroll for tabs that do not fit on the page.  It supports iframe, ajax call and dynamically loaded content.
  • croll tab in case of too many tabs.
  • dynamical/remove hide.
  • rich javascript API
See it in actionCheck documentation | download
jquery calendar thumb

wdTree is lightweight jQuery plugin for present tree with nested check boxes. Features highlighted:
  • parents/children checking
  • lazy load from database
  • configurable node attributes
See it in action Check documentation | download
jquery calendar thumb
wdDatepicker is a plugin for the jQuery library which make it easy to enter dates into web forms.
It’s also support month and year dropdown list for choose.
See demo & docs | download
jquery calendar thumb
wdContextMenu is is very lightweight jquery plugin for right click menu.
  • Item specific. Context menu for specific area
  • Dynamical disabled menus/items
See demo & docs | download

Dragdealer JS

Dragdealer is a drag-based JavaScript component that embraces endless front-end solutions. Elegantly crafted for JavaScript-aware coders.

http://code.ovidiu.ch/dragdealer/

Thursday, June 10, 2010

Ruby. Array.size by conditions

class Array
    def size(&closure)
        closure ? inject(0){ |count, elem| (yield elem) ? count + 1 : count } : length
    end
end

array = [1, 2, 3, 4, 5, 6]
puts array.size{ |i| (i & 1).zero? }.inspect

Celerity

Celerity is a JRuby wrapper around HtmlUnit – a headless Java browser with JavaScript support. It provides a simple API for programmatic navigation through web applications. Celerity aims at being API compatible with Watir.

Features

  • Fast - No time-consuming GUI rendering or unessential downloads
  • Easy to use - Simple API
  • JavaScript support
  • Scalable - Java threads lets you run tests in parallel
  • Portable - Cross-platform thanks to the JVM
  • Unintrusive - No browser window interrupting your workflow (runs in background)
http://celerity.rubyforge.org/

Watir. Automated testing that doesn’t hurt

Watir, pronounced water, is an open-source (BSD) library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.
Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.
Watir is a family of Ruby libraries but it supports your app no matter what technology it is developed in. They support Internet Explorer on Windows, Firefox on Windows, Mac and Linux, Safari on Mac, Chrome on Windows and Flash testing with Firefox.
Like other programming languages, Ruby gives you the power to connect to databases, read data files and spreadsheets, export XML, and structure your code as reusable libraries. Unlike other programming languages, Ruby is concise and often a joy to read.

http://watir.com/

Monday, June 7, 2010

BackgrounDRb

BackgrounDRb is a Ruby job server and scheduler. Its main intent is to be used with Ruby on Rails applications for offloading long-running tasks. Since a Rails application blocks while serving a request it is best to move long-running tasks off into a background process that is divorced from http request/response cycle.

http://backgroundrb.rubyforge.org/

Sunday, June 6, 2010

Enhance Tables Using One Of 30 Functional jQuery Plugins

Classic ways of using simple html tables are long gone – of course you can still use them, but you will never get such functionality and flexibility with HTML as you can get using special jQuery plugins to do the job.
Never tables have been so dynamic and users now can specify and filter all the sections they want, you just need to find right plugin for specific project.

http://www.1stwebdesigner.com/resources/enhance-tables-functional-jquery-plugins/

Unicorn

Unicorn is an HTTP server for Ruby, similar to Mongrel or Thin. It uses Mongrel’s Ragel HTTP parser but has a dramatically different architecture and philosophy.
In the classic setup you have nginx sending requests to a pool of mongrels using a smart balancer or a simple round robin.
Eventually you want better visibility and reliability out of your load balancing situation, so you throw haproxy into the mix:

http://github.com/blog/517-unicorn

RabbitMQ

RabbitMQ is based on a proven platform, offering exceptionally high reliability, availability and scalability along with good throughput and latency performance that is predictable and consistent. It has a compact, easily maintainable code base allowing rapid customisation and hot deployment. There are extensive facilities for management, monitoring, control and debugging and it is supported by a full range of commercial support services and an active community developing packages that extend the core system.

http://www.rabbitmq.com/index.html