ClickAider
You are currently browsing the Bogle’s Blog weblog archives.

Podlinez: News and Podcasts on any phone

Podlinez has an ingeniously simple system for listening to podcasts on any phone– every podcast gets its own phone number, and users can add their additional podcasts simply by entering the feed URL.  

Unfortunately, the Podlinez directory of podcasts is currently hard to navigate even from a PC and especially from a phone. 

For this reason, I’ve put together my own small directory of links to news related podcasts on Podlinez, available here: http://thebogles.com/berry/podcasts.  This directory is optimized for viewing on a mobile device; you should be able to listen to the podcast on the phone simply by clicking on the phone number links.  The mini-directory is also linked to to from the news and weather pages on Berry411.

Announcing BerrySearch Beta: Info on the Go for the Blackberry

 I am pleased to announce the release of BerrySearch 0.8beta, a free web search tool for the RIM Blackberry.

BerrySearch does for web search on the Blackberry what Berry411 did for local information, making key web reference sources fast to access and easy to use. 

Key features:  

  • Google Suggest saves typing
  • Single click access to Google, Wikipedia, Dictionary, Thesaurus, and more.

To install over the air, point your Blackberry at http://thebogles.com/berrysearch.jad.  And please do send me your feedback, it will help improve the final release.

Adding entries to the Blackberry address book from any web page

The Berry411 app enables mobile web pages on the Blackberry to do several things previos otherwise possible only from native apps, including directly adding entries to the Blackberry address book.

Below is a brief sketch of how this works for single address entries; I will document in another post how to add multiple entries if there is demand.

(1) Look in the HTTP-ACCEPTS header and see if you see the string “text/xml-berry411”.   If you find it, this means the user has Berry411 installed.

(2) Construct a link like the following, replacing the bold values with the appropriate URL encoded values.

http://thebogles.com/berry/yp/add_contact?f=business_name&p=phone &a=street&c=city&s=state

The Rails Way: new blog from Jamis Buck and Michael Koziarski

The Rails Way is a new blog from Rails gurus Jamis Buck and Michael Koziarski. They accept submissions of real world web applications and suggest ways to improve the code through the right MVC factorings. 

Interesting reading. (Also check out some of Jamis’s past posts, such as Skinny Controller, Fat Model.)

With all the attention Rails has received in the last year, there has been an enormous influx of people wanting to learn how to write web applications with it. Rails itself attempts to shepherd programmers along well-trod paths, to help them build well-designed applications “by default”. Alas, Rails’ conventions are not always enough.

This blog is our attempt to back up Rails’ opinions on what things should be done, with our own opinions on how things should be done.

Here’s how we’ll do it: if you have an application or a piece of code which you think could be done better, but you aren’t quite sure how, send it in. We’ll review all submissions, then publish an article or two showing the changes we’d make, and explain why we’d make them.

Readers get the chance to learn tips and tricks for enhancing your design, submitters get their application refactored for free, and we get some free-inspiration for our blog posts. Nobody loses!

Announcing Berry411 3.6: Find what’s best in your city

Berry411 version 3.6 is now available for download.   This version features a Local Info page with links to Weather, Sports, and Yelp guides for your city. 

Yelp and Urbanspoon reviews are also linked to directly from hits in yellow page search results, allow you to find the most highly rated businesses when you’re on the go.  (Most large cities are covered by Yelp.)

Version 3.6 also fixes two bugs affecting certain phones: an exception on powerup on some 7100 phones and multiple listings for the Berry411 menu item in the address book.

 

Ruby Module for Searching using the Alexa Web Services API

This post includes an improved version of the query example in Ruby for hitting the Alexa Web Search web service. Sample usage is as follows.

require 'alexa'
Alexa.search('bogle').each {|hit| puts hit.title}

For convenience, you might want to edit the code below to replace INSERT_YOUR_ACCESS_KEY_HERE with your actual access key and INSERT_YOUR_SECRET_ACCESS_KEY with your secret access key; otherwise these will need to be passed in as the AWSAccessKeyId and SecretAccessKey options.

Read Full Post

Ruby Threading

Ruby threads are useful, but it’s important to understand the limitations and pitfalls of the current implementation. This post is an attempt to pull together some of the key information from various places on web that helped me get up to speed.

Limitations of Ruby Threads

As explained in the Rubyspec wiki, all Ruby threads are serviced by a single native OS thread. The VM schedules threads by timeslicing at well-defined points in the VM.  This means that a single misbehaved Ruby thread could starve out all other Ruby threads (although the timeslicing points are many and hard to avoid), and that Ruby threads don’t take advantage of multiple processors or scale to high-end hardware. 

For this reason, applications that care about scale typically create multiple Ruby processes.  For instance, a web server might spawn multiple FastCGI worker processes are created rather than relying upon a single mulithreaded server as might happen in Java.

Using Threads with ActiveRecord

If you want to use ActiveRecord from multiple threads, you must include the following call in your code, as described here:

ActiveRecord::Base.allow_concurrency = true

Exceptions in threads

 As with other languages, be careful with unhandled exceptions thrown within threads. the default behavior is to silently kill the thread that caused the exception. The Threads and Exceptions section has helpful background.  When I started coding a multithreaded crawler, I failed to handle an exception causing all of my threads to eventually die, leaving me scratching my head about what happened to them. 

If you set Thread.abort_on_exception = true, then an unhandled exception will cause all threads to terminate. This can be helpful in debugging and making unhandled exceptions really obvious.

Limiting Amazon searches to items sold directly by Amazon

Ken Woodruff shares this helpful Amazon trick:

I’m an Amazon Prime member, which is sweet [because of the free shipping]if what you’re looking at is sold by Amazon,  but since they let everybody and their brother into the place to sell now, that is often not the case if you just search at random. 

Turns out there’s an easy filter–just add the ”soldbyamazon” keyword to any search to limit it to Amazon-sold (and thus Prime-eligible items).

Ruby Wrapper for MSN Live Search API

After a couple painful hours of trial and error, I’d like to share some code that simplifies the process of accessing the MSN Live Search API from Ruby

The code assumes that you have auto-generated the SOAP driver for the MSN Search web services in a directory called msn_search_driver, using the following command.

wsdl2ruby –wsdl http://soap.search.msn.com/webservices.asmx?wsdl –type client

msn_search.rb takes care of the nasty details for you, so that you can write simple code like this:

require 'msn_search'
MsnSearch.new.search("bogle").results.each {|r| puts r.url}

<RANT>
Although it’s possible in to call the SOAP driver directly, the API is hard to use because of complex, nested request and response types, poorly documented mandatory arguments, and unhelpful error messages on invalid requests. (These shortcomings are not unique to the MSN SOAP interface– I’ve experience similar shortcomings in many other SOAP apis. REST-based APIs tend to win hands down in terms of simplicity and debuggability.  

Note that neither Google, Yahoo, nor MSN will allow to fetch beyond the first 1000 results in a search, independent of their daily hit limits. If you need to use a web index for an application that’s more than a toy, you’re probably much better off using something like Alexa Web Search Platform than any of the major search APIs. The downside to the Alexa platform is that C and Java are the only supported languages.   The Alexa platform supports C, Java, and Ruby.  Alexa provides Ruby-based tutorial on how to build an image search application using their index.
</RANT>

Now that I’ve got that rant off my chest, here’s the code.


msn_search.rb
($:).push('msn_search_driver')

require ‘defaultDriver.rb’

class MsnSearch
	attr_accessor :driver

	def initialize(appID = ‘INSERT_YOUR_APP_ID_HERE’)
		@driver = MSNSearchPortType.new
		@appID = appID
	end

	def search(query, offset=0, count=50, source=”Web”,
safeSearch=”Off”, culture=”en-US”)
		s = Search.new
		s.request = with_new(SearchRequest) do |r|
			r.cultureInfo = culture
			r.safeSearch = safeSearch
			r.query = query
			r.appID = @appID
			r.requests = source_requests =
ArrayOfSourceRequestRequests.new
			source_requests << with_new(SourceRequest) do |sr|
				sr.offset = offset
				sr.count = count
				sr.source = source
				sr.resultFields = “All”
			end
		end
		@driver.search(s).response.responses.sourceResponse
	end

	def set_debug_mode(dev = STDOUT)
		@driver.wiredump_dev = dev
	end

protected
	def with_new(klass)
		instance = klass.new
		yield instance
		return instance
	end

end


Gmail Mobile Application

I’ve been using the new Gmail Mobile Application on the Blackbery now for a few days and it’s fantastic.  This is a native Java application that allows you to access your Gmail inbox and messages nearly instantaneously;  it’s a huge improvement over the old Gmail mobile web client.  It also fully supports search and labels via right click menus. 

I recommend it highly; it’s available on most phones that support Java.