Created
May 29, 2009 03:21
-
-
Save mwmitchell/119757 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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