It’s good for the server. It’s good for the soul.

ack (http://petdance.com/ack/), love it (thanks nikolay)


Posted on : Dec 12 2007
Posted under Business, Software Development, cli, linux, php, ruby on or off rails, ruby on rails, web stuff |

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

Posted on : Oct 03 2007
Posted under Business, Software Development, cli, linux, ruby on or off rails, web stuff |

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

Posted on : Oct 02 2007
Posted under Business, Random Thoughts, Software Development, blogging, cli, linux, ruby on or off rails |

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.

Link: http://www.shutupgeorge.com/al-docs/


Posted on : Oct 02 2007
Posted under Business, Software Development, cli, linux, ruby on or off rails, web stuff |

ruby-Mapquest Release v0.003

Primarily a bugfix release.  Catch it here:


Posted on : Feb 17 2007
Posted under API, Business, Software Development, geospacial, ruby on or off rails, web stuff |

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…


Posted on : Feb 13 2007
Posted under API, Business, cli, geospacial, ruby on or off rails, web stuff |

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


Posted on : Feb 13 2007
Posted under Software Development, ruby on or off rails, web stuff |

ruby-Mapquest v0.001

After releasing my preliminary code for del.icio.us I’m releasing my preliminary code for mapquest’s OpenAPI service: ruby-Mapquest.


Posted on : Feb 11 2007
Posted under API, Business, Software Development, geospacial, ruby on or off rails, web stuff |

ruby-Delicious v0.001

Since I’ve worked out the kinks mentioned in my last blog entry (was a problem with re-escaping already escaped data, by the way (never debug while sick and sleep deprived!)) I’ve scraped things together into a class which is a client for the api itself.  It’s relatively sparse right now, but good enough for using in an application.  Which is what the client is geared towards, by the way.  Specifically (and privately) tagging arbitrary data.  It *can* publicly tag URLs, but thats more or less a side effect if what delicious… is… and not a direct intention while writing the API.  You can visit the quickly thrown together ruby-Delicious page here (link also added up top)


Posted on : Feb 10 2007
Posted under API, Business, Personal, Software Development, ruby on or off rails, web stuff |