has_many :questions

July 8, 2010

Good thing I didn’t declare podcast bankruptcy on Ruby 5

Filed under: Rails,Ruby — gavinstark @ 1:07 pm

Its a great podcast and if you aren’t subscribe, go do that right now! http://ruby5.envylabs.com

I’m behind about 30 episodes and decided to plow through a bunch of episodes. Here are the neat things they covered I thought I’d mention here:

Homesick Treat your “dot files” as a git repo
Try Redis Interactive redis tutorial
Grack Easily run git over HTTPS instead of relying on SSH keys
MySQL and MongoDB together
gemsday Site to track people tweeting to #gemsday every Wednesday. Whats popular in rubygems this week
Faye Dirt-simple publish/subscribe messaging over HTTP for Node.js and Rack. This seems really cool, client/server pubsub between web browser and server.
acts_as_archive Lets you delete/restore active record entries without having to rely on column selection trickery

I’m not nearly caught up (only behind as far as March) so I’ll be posting other things I found useful/interesting.

June 3, 2010

When ‘rescue’ is not a rescue at all

Filed under: Internet,Programming,Rails,Ruby,Tips and Tricks — gavinstark @ 10:59 am

One of the pages (actually a partial) in my app was running slowly. The partial didn’t have any complicated code in it, just an iteration over some models and creating fields.

But the partial was taking 375+ms to run when I was expecting something in the single digits. Removing as much code through the partial, I realized the issue had to be in the custom form builder I use. The field I’m generating a text_input for specifies a label to use (important for later)

In that form builder I create labels for fields based on column data our app stores. The method for generating the label text begins with:

def label_from_options( method, options )
   label_text = @listview.column_label(method) rescue nil
   label_text = options[:label] if options[:label]

One look at this and I realized that it could be better written as:

   label_text = options[:label] || (@listview.column_label(method) rescue nil)

It so happens that the @listview.column_label was THROWING each time this field was being requested, and while I haven’t investigated yet, I assume it was doing a significant amount of work before that exception was thrown.

Now off to understand why that method is so expensive and see if I can remove its need/tendency to throw.

BTW, thanks to the folks over at New Relic for a great tool. This long running partial first started showing up via their “Transaction Trace” feature and then I used their developer level tool (free, BTW) to evaluate changes until I narrowed down what was slow.

January 25, 2010

Super-simple data plotting in ‘R’

Filed under: Debugging,Programming,Tips and Tricks — gavinstark @ 9:23 am

The ‘R’ app for statistics/graphing/data-analysis is super powerful and I can’t even begin to scratch its surface. However, it is very good at plotting largish data sets. I say “largish” because it can handle more than 5000 data points which is the cutoff for my favorite simple graphing tool: OmniGraphSketcher which I would stick with if it could handle say up to 250,000 points.

Recently when tracking down a memory leak I had to plot two series of numbers representing the memory consumption of an app. These data points were in a file a single line per sample. I wanted to plot the OLD data on a chart in red and the NEW data in green. I also wanted to manually specify a Y axis range so that both data sets would be visible.

Here are the commands I used in “R” to do so:


mem_before <- read.table("/path/to/mem_before.txt",sep=",")
mem_now <- read.table("/path/to/mem_now.txt",sep=",")
plot(mem_before[,1], ylab="Memory Used", xlab = "Time", pch=".", col="red", ylim=c(0,100000))
points(mem_now[,1], col="green", pch='.')

The ‘pch’ option sets the point type to use as the default is a relatively large circle icon. There is still a bit of mystery around some of the syntax but this is enough cargo-culting to produce simple plots.

NOTE: There is a Mac front-end to “R” available here: http://cran.r-project.org/bin/macosx/ Don’t expect the front-end to demystify any of R.

January 17, 2010

Let your SQL Growl in Rails 3

Filed under: Uncategorized — gavinstark @ 3:40 pm

While participating (mostly working on getting some existing apps running under 3.0) in the Rails BugMash this weekend I noted there was recently a subscription system for logging added by José Valim.

I usually enable some hack to watch SQL while I’m in script/console so I thought I’d see if I could use these new subscription models to see the passing sql in growl. I came up with this (sorry for the lack of formatting, I’ll fix this up later) which you can put in development.rb or whatever method you prefer for development-mode-only code.


Gist: http://gist.github.com/280099

(Sorry for the image paste and the gist link, but my wordpress account doesn’t let me embed javascript needed for gist, time to upgrade/move the blog)

You enable the growling of SQL via a call to SQLGrowler::enable in the script/console session. You will also need to require the ‘g’ gem in development mode as well.

I have a couple of problems with this:

  1. There is no way to turn it off once it is on.
  2. It seems there is only one subscriber per namespace so I inherit and ‘super’ — maybe not the best way, but it doesn’t clobber the existing logging facility. Thanks to lenary in the #railsbridge IRC for that suggestion.
  3. Growling all your sql calls may be more annoying than helpful
  4. This is probably a horrible use of Rails::Subscriber for which I will be publicly admonished for using.

I haven’t asked the core team what the plan for Rails::Subscriber is yet. This may be a nice way to observe/log events coming from the core library (or perhaps even your own code)

Happy Growling.

December 1, 2009

Ruby Draft Standard and consistency versus flexibility

Filed under: Programming,Ruby — gavinstark @ 12:54 pm

I’d like to start this post by thanking everyone who’s involved in the various ruby implementations and the RubySpec project. Its fantastic seeing whats happening with MRI Ruby 1.9, JRuby, Rubinius, MagLev, MacRuby, etc. (sorry if I left you out)

This morning a tweet by Jim Weirich caught my eye leading to a document the “Ruby Draft Standard.” It is an interesting document which I have not spent enough time reviewing. I was curious to see how this document covered the language and the core libraries and how it might compare to the RubySpec During a quick read I noticed many statements of the form “the behavior is implementation dependent.” Simple search in Safari told me there were more than 100 of these references. My first reaction was “whoa, thats too many”

Jim tweeted, appropriately, that Ruby language implementers should have flexibility. I agree as there are many unique things that each implementation brings to the table and a flexible language like Ruby should embrace this. However, there are many cases in the Draft Spec where this flexibility might be sacrificing consistency in the face of flexibility.

One example is the method String#*(num) about which the draft standard states If the num is not an instance of the class Integer, the behavior is implementation dependent. On the surface this seems reasonable. However, the fine folks over at RubySpec have this to say: “tries to convert the given argument to an integer using to_int” This seems far more reasonable a behavior and supports the whole Principal of Least Surprise we love so much.

So, who’s right here? Will we have a two levels of specification, one for the core language with lots of “implementation dependent” behaviors that the implementers, through RubySpec, will then choose to specify or leave dependent?

I’ve been looking for a good way to contribute to the Ruby language so perhaps I’ll make a pass at trying to reconcile this Ruby Draft Standard against the RubySpec specs and see what shakes out. I suspect there are many “implementation dependent” entries that RubySpec has spec-ed into concrete behavior. Even better might be, if there is value here, to augment the RubySpec DSL to add traceability to this document. However, past lives have shown that documents with a numbering scheme like “15.2.10.3.1 String#*” tend to descend quickly into renumbering-hell.

May 29, 2009

HD Zune. Really, that made it into the interface?

Filed under: Hardware,User Interface — gavinstark @ 8:49 pm

I’m not a UI expert. I do a competent job, but I’m no Apple UI engineer.

However, I think even I’d have noticed this UI “bug” on Microsoft’s Zune HD player (if this is even a real screen not a mock-up)

Visit this article: http://www.appleinsider.com/articles/09/05/28/early_glimpse_at_zune_hd_better_than_ipod_touch.html

And look at the first image (the one with text) here is a direct link

Notice the word “marketplace” has part of the “e” cut-off on the right hand side of the screen. Huh? Unless the user selected some different font or point size, why would the default UI be configured so the words wouldn’t fit horizontally. Its not like the feature is called “antidisestablishmentarianism.” A slightly different point size, kerning, spacing could have prevented that. Looking at other aspects of the UI in the video it seems as if they’ve deliberately chosen to display half words (like when browsing Music you see the top half of the word Music at the top of the page) thinking that users won’t care or their brains will “fill in” the missing pieces. I get that for those parts of the UI, but something about having ONE letter being cut off just makes it seem like an oversight rather than a clever UI choice.

I also think the spacing between icons and text is too small and the placement of subordinate text (e.g. the text under “Social”) is too small and too crammed under the text. Since I’m not a UI expert, I’ll leave that up for others to debate.

May 16, 2009

Day Of Ruby Resources

Filed under: Rails,Ruby — gavinstark @ 11:10 am

Guides:

Prag Prog

“Way” books

Screen Casts:

Presentations

May 10, 2009

~/.gem getting you down? chmod to the rescue

Filed under: Rails,Ruby — gavinstark @ 6:20 pm

I noticed while reading the twitter stream at RailsConf I saw a post about troubles with gems and the answer was rm -rf ~/.gem I’ve forgotten to sudo gem install a few times. I wondered if I just did a “chmod a-rwx ~/.gem” if that would prevent gem from using the directory. The answer is yes.

To prevent gem from using the ~/.gem directory:

chmod a-rwx ~/.gem

If you “rm -rf“ed that directory just mkdir ~/.gem and then do the chmod above.

Now when you gem install something without sudo you’ll get:


$ gem install something
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/username/.gem/specs

Ok, so its not clean, but at least it prevents you from getting gems stuck someplace you don’t want them to.

Perhaps there should be a “.gemrc” option to not use the personal gem folder…. If there isn’t one, maybe its patch time…

April 8, 2009

TextMate 2.0 rumors?

Filed under: Programming — gavinstark @ 9:50 am

Just came across this when doing my monthly “WTF is happening with TextMate 2.0″ google search:

http://blog.peterhaza.no/textmate-20-avian-soon-in-private-alpha/

Lets hope this is true. The only thing I really wish TM was better at was editing larger files and those with long lines. If that came out as a 1.5 update, I’d be a happy camper.

March 17, 2009

How many programming languages can you cram into a single file?

Filed under: Internet,Programming — gavinstark @ 4:29 pm

I came across this link a while ago. Don’t just look at it in your browser, view the source. The contents are executable/compilable in many languages. Save the source to disk and run it through the Python interpreter, then try the Ruby interpreter, than compile it as C, or C++, run it as a Bash script. even try it in Perl…

Original Link: http://mauke.ath.cx/stuff/poly.html

For safe keeping in case the original goes away (I dare not comment the contents as I may destroy its beauty)

gisthub: http://gist.github.com/80775
Direct gisthub download: http://gist.github.com/raw/80775/e18cbf9b44851e1c6929a65aee4547f8183e2630/gistfile1.txt

Next Page »

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.