Full Trace with RSpec

RSpec No Comments »

Just a reminder: To get a the full backtrace when running RSpec, either use the -b option,

script/spec -b /path/to/spec.rb 

or add

--backtrace

to your spec.opts. Here are the other options for either the opts file or the command line.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Netbeans Legacy Versions, Old Versions, Build and Release Archive

Netbeans No Comments »

Just for the record, as this can be hard go google. If you need old and legacy versions of Netbeans, you can find them through this page:

http://www.netbeans.info/downloads/dev.php

Besides all releases, it also gets you to all build types including nightly, daily, milestone etc., acting as a way-back machine for Netbeans developers and users.

 

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Quickstart with YQL and HTTParty with Rails

Ruby on Rails, YQL 1 Comment »

YQL makes it super-easy to consume data in your web app through a unified SQL-like API. And HTTParty by John Nunemakers makes HTTP really easy. A perfect match.

In environment.rb:

config.gem ‘httparty’

Now, just create a model. Be sure to use the public endpoint for now, as the others need oauth authentication.

class News

  include HTTParty
  base_uri  ‘http://query.yahooapis.com/v1/public/yql’
  
  def self.new_york_news
    self.get(”", :query => {:q => ’select title, abstract, url from search.news where query = “%New York%”‘,
        :format => ‘json’

      })
  end

  def self.new_york_news_hash
    self.new_york_news.parsed_response["query"]["results"]["result"]
  end
 
end

In you controller:

class NewsController < ApplicationController

  def index
    @news = News.new_york_news_hash
  end

end

And your view (for example):

<h1>New York News</h1>
<% @news.each do |news_item| %>
  <% content_tag :h2 do %>
    <%= link_to news_item["title"], news_item["url"]  %>
    <% end %>
    <% content_tag :div do  %>
      <% content_tag :p do %>
        <%= news_item["abstract"]  %>
      <% end %>
    <% end %>
  <%  end %>

Be sure to check the API docs of YQL for many other options and watch the excellent screencasts by Christian Heilmann in the YUI theater and elsewhere. The possibilities are endless.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Convert between XML, Hash, YAML, JSON in Ruby - Conversion Cheat Sheet

Ruby, Uncategorized 6 Comments »

Here’s a little XML/JSON/YAML/Hash conversion cheat sheet for Ruby:

First, let’s create an XML document:

require ‘rubygems’

require ‘nokogiri’

builder = Nokogiri::XML::Builder.new do |xml|

    xml.root {
      xml.products {
        xml.widget {
          xml.id_ “10″
          xml.name “Awesome widget”
        }
      }
    }
  end

my_xml = builder.to_xml

XML To Hash:

require ‘active_support’ #if you have Rails installed

my_hash = Hash.from_xml(my_xml)

Without Rails/ActiveSupport, have a look at Crack which very fast and will usually give you enough fields. If you have attributes and a text value in the same node however (<person age=”10″>joe</person), you will only get the value back, not the attribute. Update (again): For text nodes (any node that contains a string), crack will return an attributes hash in addition to the text content.

my_hash = Crack::XML.parse(my_xml)

Hash To Object?

Have a look here: http://blog.jayfields.com/2008/01/ruby-hashtomod.html

Hash To JSON:

require ‘json’

my_json = my_hash.to_json

JSON back to Hash:

my_hash = JSON.parse(my_json)

Also have a look at Crack:

my_hash = Crack::JSON.parse(my_json)

Hash To YAML:

my_yaml = my_hash.to_yaml

YAML back to Hash:

my_hash =  YAML::load(my_yaml)

Bonus Points –  Hash to XML:

require ‘xmlsimple’

my_xml = XmlSimple.xml_out(my_hash, {’KeepRoot’ => true})

There is currently no way to preserve the attributes (like <person age=”10″>Joe</person>) with such conversion from Hash to XML.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Back to BlogJet as My Blog Editor on Linux

Blogging Software, Linux No Comments »

Having tried Bilbo/Blogilo for a while now, I found it to be a fine editor but a bit too intrusive in altering the HTML code I created in code view when I switched back to Bilbo’s WYSIWYG view.

So I tried good old BlogJet again and found there’s a (free) upgrade to the new version 2.5 (currently 2.5.0.15), among other goodies making it Unicode compatible and letting you create categories from within the editor (only for Wordpress blogs), still a rare feature outside of Live Writer.

To install it, proceed just like with the prior versions, as outlined here. You have to open the downloaded installer (BlogJetSetup.2.x.x.x.exe) from the file menu in IEs4Linux and proceed. Simply clicking the downloaded installer will give you an installation without necessary HTML components and it won’t display any content.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in