Archive

Posts Tagged ‘Ruby’

working with processes and ruby

December 5th, 2008

Some code for working with processes using ruby.

 
# get status from child process before daemonizing
rd, wr = IO.pipe
fork do
  rd.close
  fork do
    wr.write "hello"
    wr.close
    sleep 10
  end
  wr.close
end
wr.close
puts rd.read
 
# run a command and get exit status and command output
rd, wr = IO.pipe
pid = fork do
  $stdout.reopen wr
  $stderr.reopen wr
  $stdin.reopen rd
  exec '/opt/local/bin/ls -l'
end
wr.close
 
pid, status = Process.wait2(pid)
puts rd.read
puts status.inspect

Pretty easy in ruby.

Software

conference website

October 7th, 2008

We just finished up our first virtual conference website.  It’s a kind of mix of event signup and confernce registration as well as related content.  The content is provided by the company hosting the conference, SAE.  I think I most enjoyed puting together the Dynamic Lead with the rotating images on the landing page.  I used Prototype UI’s carousel widget.

Dynamic Lead for SAE

Read more…

Software , , , , , ,

Curb gits Forked

August 25th, 2008

Git has really made it much easier to share code.  ~23 days after posting curb to github, it now has a fork that’s added direct methods for making a PUT and DELETE request.

Software , ,

Running different Rack adapters with merb

August 19th, 2008

A question came up recently and I had to think twice. It was how do I run a different app server for my merb application? Knowing merb relies on rack, I initially thought to look in the config/rack.rb.  Then I started to grep through merb-core/ and finally came to:

Merb::Config.use do|config|
  config[:adapter] = :mongrel
end

Read more…

Software , , , , , ,

Adding ruby thread scheduling to curb

August 4th, 2008

Ruby threads require care when writing an extension - especially when the extension does anything over a network. In the case of curb, it’s often used as a replacement to the built in ruby net/http library.
Read more…

Software , ,

New curb patch, on_success, and on_failure

July 10th, 2008

I added a new callback hook to curb on_success and on_failure. They work as advertised and are esspecially useful when using the Curl::Multi interface from my last patch.

gc = Curl::Easy.new("http://www.google.com/")
gc.on_success{|curl| puts curl.body_str }
yc = Curl::Easy.new("http://www.yahoo.com/")
yc.on_success{|curl| puts curl.body_str }
 
mc = Curl::Multi.new
mc.add(gc)
mc.add(yc)
 
mc.perform

Read more…

Software , ,

Freezing compiled gems in merb

July 3rd, 2008

Vendoring gems definitely makes deployment easier for both rails and merb. For merb, the solution is to create a local gem repository within your project.

gem install -i gems/ --no-ri --no-rdoc #{gem_to_install}

This works great, once you update your merb/config/init.rb to include the new gem repository.

Gem.clear_paths
Gem.path.unshift(Merb.root / "gems")

Read more…

Software , ,