ruby

Apple Push Notification in Erlang (or improved in Ruby?)

I currently have an Apple Push Notification running on my server in Ruby. I'd like to get one going in Erlang as I'd like to use a supervisor to keep watch over it. Does anyone have any code that they could help me with? Here's my Ruby code. One thing I do not like about this current implementation is that it does not seem to stay ...

In Ruby, what is the best way to execute a local Linux command stored in a string?

In Ruby, what is the simplest way to execute a local Linux command stored in a string while catching any potential exceptions that are thrown and logging the output of the Linux command and any thrown errors to a common log file? ...

Method pointers in ruby

I want to store several different methods in an array in Ruby. Suppose I want to store the type method twice: [type, type] doesn't store two entries of type in an array; it executes type twice, and stores the results in the array. how do I refer explicitly to the method object itself? (this is just a simplified version of what I real...

RubyODBC Cannot allocate SQLHENV

I'm trying to connect to SQL Server on Ubuntu 9.04 using Ruby. I translated and followed all the steps outlined in getting OSX talking to SQL Server from here: http://toolmantim.com/articles/getting_rails_talking_to_sqlserver_on_osx_via_odbc Everything is working on the FreeTDS and unixODBC end. I can see and query the database using t...

What does it mean to yield within a block?

def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In this code from ActiveRecord, what is the purpose of a yield statement that exists within a block? ...

Is there any live demo/sample applications for SproutCore or Cappuccino

Didn't find any from their website. I mostly just trying to see which one is worth going with(RIA of course). thanks ...

Why does Ruby Builder's XmlMarkup use different syntax to groovys' NodeBuilder

Groovys' NodeBuilder uses def someBuilder = new NodeBuilder() someBuilder.people(kind:'folks', groovy:true) { person(x:123, name:'James', cheese:'edam') { project(name:'groovy') project(name:'geronimo') } person(x:234, name:'bob', cheese:'cheddar') { project(name:'groovy') project(name:'drools') } } whereas ...

Using will_paginate without :total_entries to improve a lengthy query

I have a current implementation of will_paginate that uses the paginate_by_sql method to build the collection to be paginated. We have a custom query for total_entries that's very complicated and puts a large load on our DB. Therefore we would like to cut total_entries from the pagination altogether. In other words, instead of the t...

How to I launch a ruby script from the command line by just its name?

On windows, I can run my ruby script like this: > ruby myscript.rb but I want to set things up so that I can just do this instead?.. > myscript.rb How do I do this? I know it's possible because I've recently moved from one PC that had this set up to a new PC that doesn't (yet). ...

yield: why can't i write: p test_method { i.upcase }

def test_method ["a", "b", "c"].map {|i| yield(i) } end If I call test_method like this: p test_method {|i| i.upcase } # => ["A", "B", "C"] Why do I need the {|i|} inside the block, instead of just saying this: p test_method { i.upcase } The reason I think so is because when yield is called in test_method, we already have an {|...

Selectively caching models with cache_money

Instead of doing this in the cache_money.rb initializer class ActiveRecord::Base is_cached :repository => $cache end I want to be able to selectively cache only certain models (the reason being our User model breaks memcached because it's generally too large to be serialized properly). class User < AR::Base is_cached :repository ...

heuristic(s) for detecting trackback links on a page

I'm writing my own blog (every one should do this once) and the project for this week is to automatically send (trackback || pingback) requests to pages to which I am linking. I'm writing in ruby, but would also like general heuristics. I would like some advice on the following: 1) What is the best way to pull RDF out of a document when...

Why might you call instance_eval (as opposed to class_eval) inside 'initialize'?

class Observer def initialize(&block) instance_eval(&block) if block_given? end end I'm wondering what assumption is made here about the type of block that is being used with 'initialize'. Since instance_eval is called, this means the block is evaluated in the context of the class Observer. Why would it do that, a...

Post file using ruby's Http class

I have been learning to fake posting forms using Ruby's Http class, but now I need to post a file (as in faking a form submission where one of the fields is input type="file"). Anyone know how to do this? NB It's not essential I use the Http class, just that I can post files. ...

How to validate that a string is a year

Using Ruby/RoR - The year is a string in the model/view. How do I validate that the user entered string is a valid gregorian calendar year? ...

How to Group by Day with Ruport / Ruby on Rails?

I'm trying to evaluate Ruport for use in my Rails app, but am not sure how to take a series of records with date/time stamps and group them via Ruport's grouping functions. I'm open to other/better methods to do this same grouping if Ruport doesn't make sense. ...

Are there any advantages in using block initialization?

Is there any reason to do use block initialization, like this: x = Observer.new do add_event(foo) some_other_instance_method_on_observer self.some_attribute = something end instead of initializing attributes using the dot operator on an instance variable like this: x = Observer.new x.add_event(foo) x.some_other_instance_method_...

How to recursively search through self-referential subtopics?

If I have a self-referential Topic class and I want to recursively loop through all of my subtopics, what would be a good Ruby way to do that: @category.topics.all(:parent_id => topic.id).each do |subtopic| subtopic.delete_tags @category.topics.all(:parent_id => subtopic.id).each do |subsubtopic| subsubtopic.delete_tags ...

Ruby (on Rails) && PHP - two great things that work great together???

I've done very little work with Ruby, and have an app I've written in PHP. I would like to add some functionality which is available in open sourced Ruby code. I could either try to translate the Ruby to PHP, or try mixing the two. Though I think the mixing part would be somewhat silly. I believe my options are to either mix ruby wi...

Run Shoes clone in IronRuby

I found cool article on Creating cross platform GUI's with IronRuby where someone re-created the Shoes DSL by _why the lucky stiff in IronRuby. Awesome right! So, I downloaded the IronRuby binaries and the code from the article and ran the following command: c:\IronRuby\bin\ir hello_world.rb But I get the following error: :0:in ...