Skip to content

Instantly share code, notes, and snippets.

View h0rs3r4dish's full-sized avatar

Chris Szentkiralyi h0rs3r4dish

View GitHub Profile
@h0rs3r4dish
h0rs3r4dish / enum.rb
Created December 24, 2009 00:54
Enums, the Ruby Way
class Enum; class << self; def new(*list)
i = (list[0].class == Fixnum) ? list.shift : 0
Class.new.class_eval do
list.each { |item| const_set item, i; i += 1 }
class << self;
def each(&blk); self.constants.each { |i| blk.call(i) }; nil; end
def map(&blk); self.constants.map { |i| blk.call(i) }; end
end
self
end
@h0rs3r4dish
h0rs3r4dish / humane-examples.rb
Created December 17, 2009 04:42
HumaneBrick: WEBrick for sane people
require 'humane'
server = HB::Server.new # use "include HB" for even more fun
server.path "/" do # Hello world, HB style
write true, "h1. Hello, world!" # write() = puts() for the web; hx. = <hx></hx>
write true, "The URL you entered was '%s'" % url # Just pop that word in there and enjoy
end
server.path "/submit" do |name| # auto-magically gives you POST/GET-ed variables
@h0rs3r4dish
h0rs3r4dish / rt
Created December 16, 2009 02:35
RubyTask, a todo sort of app
#!/usr/bin/ruby
# Viewing as a Gist? See rubytask.md at the bottom
ARGV.push 'help' if ARGV.empty?
command = ARGV.shift.downcase
Taskfile = '/home/'+ENV['USER']+'/.rtasks'
system "touch #{Taskfile}" if !File.exist? Taskfile
@h0rs3r4dish
h0rs3r4dish / errfree.md
Created December 11, 2009 03:24
errfree IRC bot manual

errfree Factoid/Markov Bot

errfree is a factoid & Markov chain text processing bot that features semi- intelligent conversation and the ability to discern question/answer phrases.

Table of Contents

  1. Basic Functions
@h0rs3r4dish
h0rs3r4dish / canine.rb
Created October 16, 2009 00:47
Canine, an easy Ruby "binary" library
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s