code
stringlengths
1
1.73M
language
stringclasses
1 value
module GameMechanics def load_accounts end def account_valid? end end
Ruby
require 'models/belongs_to_entity' class Action < MudBase include BelongsToEntity attr_accessor :type, :data # [+type+] Symbol identifying the action # [+performer+] Entity performing the action # [+data+] A free-form hash containing information about the action def initialize(typ...
Ruby
class Account < MudEntityBase has_three :characters properties :username, :password, :email def login end class Character < MudEntityBase has_many :items end class Items < MudEntityBase end class AccountCollection < MudCollectionBase end @bob = AccountCollection.fin...
Ruby
require 'rubygems' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => "../db/mud.db" ) # setup account table ActiveRecord::Schema.define do create_table :accounts, :force => true do |t| t.column :username, :string t.column :pa...
Ruby
class CharacterDatabase < Array include Singleton def announce(data) self.each { |x| x.update data} end end
Ruby
require 'models/account' class AccountDatabase include Singleton @accounts = {} def add(account) @accounts[account.name.to_sym] = account end end
Ruby
require 'models/mud_base' class Entity < MudBase include Comparable properties :oid,:name,:description def <=>(e) self.oid<=>e.oid end def to_s self.name end end
Ruby
require 'yaml' class Module def has_many(sym) puts sym end def properties(*args) args.each do |arg| class_eval <<-EOC def #{arg} @props ||= {} @props[:#{arg}] end def #{arg}=(value) @props ||= {} @props[:#{...
Ruby
module HasManyCharacters def add_character(character) @char_container = @char_container || {} @char_container[character.oid.to_sym] = character end def remove_character(character) @char_container.delete character.id.to_sym end def each_character @char_container.each_valu...
Ruby
require 'models/mud_base' require 'models/has_many_characters' class Account < MudBase include HasManyCharacters properties :username, :password, :last_login def initialize(args) raise "Missing Required Properties" unless (args.key?(:username) and args.key?(:password)) raise "Invalid ...
Ruby
module BelongsToEntity attr_accessor :owner end
Ruby
module HasManyCharacters def characters @characters ||= [] @characters end def add_character(val) @characters ||= [] raise "You have reached your limit of characters" if @characters.length == 3 @characters << val end def remove_character(name) @cha...
Ruby
require 'models/entity' class Character < Entity attr_accessor :connection def update(data) @connection.call data end end
Ruby
require 'network/telnet_handler' module NetworkHandler attr_accessor :account def post_init @manager = TelnetHandler.new(self) send_data "Welcome to AwesomeMud\r\nHit 'Enter' to continue...\r\n" end def receive_data(data) @manager.handle data end def send_line(data) ...
Ruby
module StateHandler @states = {} puts @states.class def add_state(state_name, &block) puts "#{state_name} added" @states = {} unless @states @states[state_name] = block end def call_state(data) #begin @states[@current_state].call data.sanitize #rescue => err # ...
Ruby
require 'models/character' require 'network/state_handler' class CharacterHandler include StateHandler def initialize(connection) @connection = connection set_state :init puts @connection puts "that was connection" puts @connection.account puts "that was connectio...
Ruby
require 'models/account' require 'network/state_handler' class LogonHandler include StateHandler def initialize(connection, parent_handler) @parent_handler = parent_handler @connection = connection setup_states set_state :init end def handle(data) call_state data.sanitiz...
Ruby
require 'network/logon_handler' require 'network/character_handler' class String def sanitize #i also need to strip out backspace characters.. or bad things happen.. self.strip.downcase.gsub('\r\n' , '') end end class TelnetHandler def initialize(connection) @connection = connec...
Ruby
require 'rubygems' require 'eventmachine' require 'singleton' require 'logger' require 'facets/core/kernel/with' require 'network/network_handler' require 'database/character_database' require 'database/account_database' require 'engine/game_engine' @account_db = AccountDatabase.instance @@logger ...
Ruby
require 'test/unit' require 'facets/core/kernel/with' require 'models/mud_base' require 'models/account' require 'models/character' class AccountTest < Test::Unit::TestCase def setup @account = Account.validate( :username => "test", :password => "test") end def test_001_new_good_account ...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def show_flash [:notice, :warning, :message].collect do |key| content_tag(:div, flash[key], :class => "flash_banner") unless flash[key].blank? end.join end # from Dan Webb's MinusMOR plugin def...
Ruby
module UsersHelper end
Ruby
module TasksHelper end
Ruby
require 'digest/sha1' class User < ActiveResource::Base #include Doodle::Helper #include Doodle::Factory #has :id, :kind => Integer #has :email, :kind => String, :default => nil #has :full_name, :kind => String, :default => nil #has :password, :kind => String, :default => nil #has :sa...
Ruby
class Task < ActiveResource::Base # Specify the default schema attributes for the class. This ensures that these attributes are available # in view forms etc. include ActiveResourceSchema @@defaults = { :id => nil, :user_id => nil, :name => nil, :worth => 1, :completed_at => nil, :created_at => nil, :...
Ruby
class TasksController < ApplicationController before_filter :login_required # GET /tasks # GET /tasks.xml def index filter_tasks(current_user.tasks) calculate_totals respond_to do |format| format.html # index.html.erb format.xml { render :xml => @incomplete_tasks } end end ...
Ruby
# This controller handles the login/logout function of the site. class SessionController < ApplicationController def new flash[:notice] = "Notice" if self.logged_in? redirect_to tasks_path end end def create password_authentication(params[:email], params[:password]) end def destroy self.curre...
Ruby
class UsersController < ApplicationController before_filter :login_required, :except => [:new, :create] # GET /users # GET /users.xml def index @users = User.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /us...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base include AuthenticatedSystem helper :all # include all helpers, all the time # See ActionController::Req...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # i...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
ActionController::Routing::Routes.draw do |map| # restful_authentication session mappings map.resource :session, :controller => 'session' map.login '/login', :controller => 'session', :action => 'new' map.logout '/logout', :controller => 'session', :action => 'destroy' # resource mappings map.resources...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
# Be sure to restart your server when you modify this file # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.0...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? current_user != :false end # Accesses the current user from the session. Set it to :false if login fails # so that fu...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? users(user).id : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials...
Ruby
# This module can be included in ActiveResource model classes to initialize attributes to default values # like nil etc. so they work with view forms. # # You just need to define a @@defaults hash for the attributes in the including class. # # For example if you have a project class that always has 'first_name' an...
Ruby
require 'RMagick' class NumberImageGenerator @@IMAGE_DIR = 'numbers-hdpi/' def generate(text, fs=18) #filename = "b" + sprintf("%03d", text) + ".png"; filename = "" + sprintf("%03d", text) + ".png"; font_size = fs; height = 35; width = 35; image = Magick::Image.new(width, height) {self.ba...
Ruby
#!/usr/bin/env ruby # encoding: utf-8 project = 'battery-indicator' user = `cat ~/.netrc | awk '{print $4;}'`.strip pass = `cat ~/.netrc | awk '{print $6;}'`.strip version = `grep "android:versionName=" AndroidManifest.xml`.split('"')[1] apk_location = "BatteryIndicatorPro-#{version}.apk" system("cp bin/*-release.ap...
Ruby
#!/usr/bin/env ruby require 'nokogiri' string_to_remove = ['pref_cat_themes', 'theme_settings', 'theme_settings_summary', 'theme_settings_help'] string_files = [] Dir.glob('res/values*').each do |d| file = d << "/strings.xml" string_files << file if Fil...
Ruby
#!/usr/bin/env ruby require 'net/http' require 'uri' LANGS_URI = 'http://ath.darshancomputing.com/bi/langs/' langs = Net::HTTP.get(URI.parse(LANGS_URI)).split() langs.each do |lang| if lang.length == 2 dir = 'res/values-' << lang else dir = 'res/values-' << lang[0,2] << '-r' << lang[2,2] end if ! D...
Ruby
#!/usr/bin/env ruby # encoding: utf-8 require 'nokogiri' # read in convert.xml to see which how to convert the string-arrays # for each strings.xml in res/values res/values-?? res/values-??-* # find the string-arrays that match the ones in convert.xml and for each # remove opening and closing string-array tag #...
Ruby
SET app_name create-dmg VERSION create-dmg.cur create-dmg heads/master NEWDIR build.dir temp %-build - NEWFILE create-dmg.zip featured %.zip % COPYTO [build.dir] INTO create-dmg [create-dmg.cur]/create-dmg INTO sample [create-dmg.cur]/sample INTO support [create-dmg.cur]/support SUBSTVARS [build.dir<alter>]/c...
Ruby
#!/usr/bin/env ruby require File.expand_path("../lib/channel_info.rb", File.dirname(__FILE__)) if __FILE__ == $0 puts ChannelInfo.getNameByID ARGV[0] end
Ruby
#! /usr/bin/env ruby # accounting_metad.rb # Meta server for ngx_http_accounting_module # Lantao Liu ( liulantao@gmail.com ) require 'lib/accounting_metad.rb' require 'lib/yaml_loader.rb' settings = YLoader.get(File.expand_path("includes/settings.yml", File.dirname(__FILE__))) AccountingMetad.new(settings).start...
Ruby
#! /usr/bin/env ruby require "RRD" require 'fileutils' class MRRD def self.update(rrdfile, value) create rrdfile unless File.exists? rrdfile RRD.update(rrdfile, "#{Time.now.to_i}:#{value}") end def self.create(rrdfile) puts "\t==>\tCreating #{rrdfile}" FileUtils.mkdir_p(Fi...
Ruby
#!/usr/bin/env ruby require 'yaml' class YLoader def self.get(filename) puts "YLoader: #{filename}" File.exists?(filename) ? YAML.load_file(filename) : YAML.load_file(filename + '.default') end end if __FILE__ == $0 p YLoader.get("includes/settings.yml") p YAML.load_file("includes/settings.yml") end
Ruby
# Ruby license. Copyright (C)2004-2008 Joel VanderWerf. # Contact mailto:vjoel@users.sourceforge.net. # # A lightweight, non-drifting, self-correcting timer. Average error is bounded # as long as, on average, there is enough time to complete the work done, and # the timer is checked often enough. It is lightweight in t...
Ruby
#! /usr/bin/env ruby #require 'send_nsca' require File.expand_path("yaml_loader.rb", File.dirname(__FILE__)) class ThresholdJudge @@thresholds = YLoader.get(File.expand_path("../includes/thresholds.yml", File.dirname(__FILE__))) def self.thresholds @@thresholds end def self.append(name, value, debug=false) i...
Ruby
#! /usr/bin/env ruby require File.expand_path("yaml_loader.rb", File.dirname(__FILE__)) class ChannelInfo @@channelinfo = YLoader.get(File.expand_path("../includes/channels.list", File.dirname(__FILE__))) def self.getNameByID(accounting_id) if(accounting_id =~ /^\d+$/ or accounting_id.class.name == "F...
Ruby
#! /usr/bin/env ruby require 'socket' require File.expand_path('store_adaptor.rb', File.dirname(__FILE__)) require File.expand_path('counter_server.rb', File.dirname(__FILE__)) require File.expand_path('threshold_judge.rb', File.dirname(__FILE__)) require File.expand_path("server_info.rb", File.dirname(__FILE__)) requi...
Ruby
#! /usr/bin/env ruby class CounterServer @counter = Hash.new 0 def self.increase(ids=[]) if ids.class.name == "Array" ids.each do |id| @counter[id] += 1 end elsif ids.class.name == "Hash" ids.each do |id, value| @counter[id] ...
Ruby
#! /usr/bin/env ruby require File.expand_path("yaml_loader.rb", File.dirname(__FILE__)) class ServerInfo @@serverinfo = YLoader.get(File.expand_path("../includes/server_info.yml", File.dirname(__FILE__))) def self.groupname(ip) @@serverinfo[ip] || "unspecified_grid" end end if __FILE__ == $0 ...
Ruby
#!/usr/bin/env ruby require 'logger' require File.expand_path("yaml_loader.rb", File.dirname(__FILE__)) require File.expand_path("mrrd.rb", File.dirname(__FILE__)) require File.expand_path("channel_info.rb", File.dirname(__FILE__)) class StoreAdaptor def self.append(ip, info) raise "virtual function called...
Ruby
# Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = "/" css_dir = "theme/css" sass_dir = "theme/scss" images_dir = "images" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): output_style = :co...
Ruby
# -*- encoding: utf-8 -*- Gem::Specification.new do |gemspec| gemspec.version = "0.2.0" gemspec.date = "2011-07-12" gemspec.name = "compass-recipes" gemspec.authors = ["Maxime Thirouin", "David Kaneda"] gemspec.summary = %q{Recipes for Compass} gemspec.description = %q{A Compass extension to have some sas...
Ruby
task :default do sh "compass compile" end task :pages do require 'git' require 'fileutils' repo = Git.open('.') # copy tests into a temp dir before switching branch FileUtils.rm_rf "tmp" FileUtils.mkdir("tmp") (FileList.new('tests/**/*.html')+FileList.new('tests/**/*.css')).each do |file| FileUti...
Ruby
## # Compass Recipes # Configuration files mainly used for tests # http_path = '/' css_dir = '.' sass_dir = '.' line_comments = false relative_assets = true additional_import_paths = [ './stylesheets', './tests' ] # just for testing extension require File.join(File.dirname(__FILE__), 'lib', 'compass-recipes'...
Ruby
source :rubygems gem "bundle" gem "rake" gem "compass" gem "git"
Ruby