Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (28 sloc) 0.772 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# Serves up code. That is all.

require 'drb'

IP = ARGV.first

class CodeServ
  BOOT = %(ruby -rdrb -e'puts DRbObject.new(nil, "druby://#{IP}:2323").get("03_hacktastic.rb")' > hacktastic.rb)
  
  def put(name, code)
    file = name[/\w+(\.\w+)?/]
    File.open("incoming/#{file}", 'w'){|f| f.write code}
    "Thanks!"
  end

  def get(name)
    hack = "hacks/#{name[/\w+(\.\w+)?/]}"
    if File.exist?(hack)
      File.read(hack)
    else
      File.read('hacks/default.rb')
    end.gsub(/_\_IP__/, IP)
  end
  
  def list
    Dir['hacks/*'].sort.collect do |e|
      "#{File.basename(e).ljust(18)} #{File.readlines(e).first.chomp[0..50]}"
    end.sort.join("\n")
  end
end

DRb.start_service("druby://#{IP}:2323", CodeServ.new)
puts
puts CodeServ::BOOT
DRb.thread.join
Something went wrong with that request. Please try again.