I find this concept fascinating and plan to investigate further down this road.
Ruby (on or off) Rails
Howto: Enable regular expression highlighting in LimeChat
in LimeChat.app/Contents/Resources/logrenderer.rb around line 419… WFM. IANAL. YMMV. RTFM. OMGWTF. WTL. GTFO. ETC.
words.each do |w| next if w.empty? s = body offset = 0 #rex = Regexp.new(w, true) # while rex =~ s #begin # left = $~.begin(0) right = $~.end(0) pre = $~.pre_match post = $~.post_match ok = true if exact_word_match if !pre.empty? && alphabetic?(w.first_char) && alphabetic?(pre.last_char) ok = false elsif !post.empty? && alphabetic?(w.last_char) && alphabetic?(post.first_char) ok = false end end if ok keywords < < { :pos => offset+left, :len => right-left } end s = post offset += right #rescue next end # end end
It’s good for the server. It’s good for the soul.
ack (http://petdance.com/ack/), love it (thanks nikolay)
Autumn Leaves Leaf #3: Commander
This leaf is capable of running a script on the local server in response to the !deploy channel command. For security you have to authenticate first. To do so you send it a message with a password. it then it http authenticates against a specific url with your nickname and the mesage text as the password. If the file fetched matches predesignated contents then you are added to the internal ACL. Anyone in the ACL can run the !deploy command. If you leave the chan, join the chan, change nicks, or quit irc you will be removed from the ACL and have to re-authenticate. This could be adapted to any system command for any purpose. I ended up not needing this leaf; I still wanted to put it out there since its functional and useful.
require 'net/http' require 'net/https' class Commander < AutumnLeaf before_filter :authenticate, :only => [ :reload, :sync, :quit, :deploy ] $authenticated = [] def authenticate_filter(sender, channel, command, msg, options) return true if $authenticated.include?(sender) return false end def did_receive_private_message(sender, msg) # assumes there is a file at # http://my.svnserver.com/svn/access # whose contents are "granted" Net::HTTP.start('my.svnserver.com') {|http| req = Net::HTTP::Get.new('/svn/access'); req.basic_auth(sender, msg) response = http.request(req) $authenticated < < sender if response.body == "granted" } end def someone_did_quit(sender, msg) $authenticated.delete(sender) end def someone_did_leave_channel(sender, channel) $authenticated.delete(sender) end def someone_did_join_channel(sender, channel) $authenticated.delete(sender) end def deploy_command(sender, channel, text) message "deploying..." system("sudo /usr/local/bin/deploy.sh 1>/dev/null 2>/dev/null") end end
Autumn Leaves Leaf #2: Feeder
This handy little bot keeps track of RSS feeds, and announces in the channel when one is updated. (note: be sure to edit the path to the datafiles) Each poller runs inside its own ruby thread, and can be run on its own independent schedule
require 'thread' require 'rss/1.0' require 'rss/2.0' require 'open-uri' require 'fileutils' require 'digest/md5' class Feeder < AutumnLeaf def watch_feed(url, title, sleepfor=300) message "Watching (#{title}) [#{url}] every #{sleepfor} seconds" feedid = Digest::MD5.hexdigest(title) Thread.new { while true begin content = "" open(url) { |s| content = s.read } rss = RSS::Parser.parse(content, false) rss.items.each { |entry| digest = Digest::MD5.hexdigest(entry.title) if !File.exist?("/tmp/.rss.#{feedid}.#{digest}") FileUtils.touch("/tmp/.rss.#{feedid}.#{digest}") message "#{entry.title} (#{title}) #{entry.link}" end sleep(2) } rescue sleep(2) end sleep(sleepfor) end } sleep(1) end def did_start_up watch_feed("http://planet.wordpress.org/rss20.xml", "planet", 600) watch_feed("http://wordpress.com/feed/", "wpcom", 300) end end
Autumn Leaves Leaf #1: Announcer
This bot is perfect for anything where you need to easily build IRC channel notifications into an existing process. It’s simple, clean, and agnostic. Quite simply you connect to a TCP port, give it one line, the port closes, the line given shows up in the channel. eg: echo ‘hello’ | nc -q 1 bothost 22122
require 'socket' require 'thread' class Announcer < AutumnLeaf def handle_incoming(sock) Thread.new { line = sock.gets message line sock.close } end def did_start_up Thread.new { listener = TCPServer.new('',22122) while (new_socket = listener.accept) handle_incoming(new_socket) end } end end
Autumn Leaves (a ruby framework for IRC bots)
What an awesome awesome thing for people who use IRC in their day to day lives! I’ll post a couple of utility leaves here real quick.
ruby-Mapquest Release v0.003
Primarily a bugfix release. Catch it here:
ruby-Mapquest Release v0.002
Welcome: ruby-Mapquest v0.002. Wherein I’ve added support for routing (directions.) Let me tell you that getting the info together for this was *NOT* a pretty picture…
Hpricot <text>sometext</text> workaround
As noted by the open trouble ticket here, The most awesome Hpricot seems to have come down with a bug, in that it’s not able to access “sometext” inside this: “<text>sometext</text>” It parses it ok (puts.doc.inspect definately shows the proper {elem}) you just cant get to it. So heres my ugly little hack/workaround for this issue until it’s resolved. (I’m posting it here, since I cant seem to signup to make a comment on the bug report on the Hpricot home page… and someone might find this useful) This hack is specifically for web documents, however would also work for strings or files with only minor tweaks.
## Begin hack
doc = “”
open(url) do |f|
doc=doc + f.read
end
doc = doc.gsub(/<text>/, “<mtext>”)
doc = doc.gsub(/<\/text>/, “</mtext>”)
doc = Hpricot(doc)
## Should be one line
## doc = Hpricot(open(url))
## End hack