Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created May 29, 2009 03:21
Show Gist options
  • Save mwmitchell/119757 to your computer and use it in GitHub Desktop.
Save mwmitchell/119757 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
require "socket"
require "etc"
MySocket = "/tmp/drb.madcap"
class String
#randomly set case of each letter
def madcap
self.scan(/./).map do |s|
if rand(2) == 0
s.downcase
else
s.upcase
end
end.join
end
end
if pid = fork # run in the background
Process.detach(pid)
exit
end
File.unlink(MySocket) if File.exists?(MySocket)
begin
# create/init server socket
server = UNIXServer.new(MySocket)
File.chmod(0777, MySocket)
rescue Errno::EADDRINUSE
puts "Already listening on #{MySocket}"
exit
rescue Exception => exc
puts exc.message
exit
end
signature = " (brought to you by #{Etc.getpwuid(Process::euid).name})"
loop do
sock = server.accept # listen
reply = sock.gets.strip.sub(signature, "").madcap
reply << signature
sock.print reply
sock.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment