code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
module Calendar
class Splicer
# Takes a Range of dates and returns an array of Ranges organized by month
def self.by_month(period)
months = Array.new
start = nil
period.each do |day|
start = day if start.nil?
if start.month != day.month
month = start..(day - 1)
... | Ruby |
module AuthorizationSystem
def self.included(base)
base.send :helper_method, :current_user, :logged_in?
end
protected
def logged_in?
!@current_user.nil?
end
# Returns the currently logged in user
def current_user
@current_user ||= User.find(session[:user_id])
end
# Assigns the curre... | Ruby |
# =============================================================================
# A set of rake tasks for invoking the Capistrano automation utility.
# =============================================================================
# Invoke the given actions via Capistrano
def cap(*parameters)
begin
require 'rubyg... | Ruby |
desc 'Create items from all the recurrings today'
task :recur => :environment do
date = Time.now.utc.to_date
puts "[#{Time.now.strftime('%F %T')}] Starting for #{date}"
count = 0
for recurring in Recurring.on(date)
item = Item.new :date=>date, :value=>recurring.explicit_value, :description=>recurring.de... | Ruby |
module TimePeriod
def self.week_to_date
(TzTime.now.to_date - 6)..TzTime.now.to_date
end
def self.this_month
Date.new(TzTime.now.year, TzTime.now.month, 1)..Date.civil(TzTime.now.year, TzTime.now.month, -1)
end
def self.month_to_date
Date.new(TzTime.now.year, TzTime.now.month, 1)..TzTime.now... | Ruby |
class DataPoint
attr :name
attr :value
attr :number
def initialize(name, value, number)
@name = name
@value = value
@number = number
end
def <=>(other)
value <=> other.value
end
end | Ruby |
#!/usr/local/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 impai... | Ruby |
#!/usr/local/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 impai... | Ruby |
#!/usr/local/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.lo... | Ruby |
#!/usr/local/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 impai... | Ruby |
#!/usr/local/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 impai... | Ruby |
#!/usr/local/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.lo... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'redgreen'
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... | Ruby |
ActionController::Base.extend ActiveDirectorySearch
| Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the active_directory_search plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the active... | Ruby |
# desc "Explaining what the task does"
# task :active_directory_search do
# # Task goes here
# end | Ruby |
# Uninstall hook code here
| Ruby |
puts IO.read(File.join(File.dirname(__FILE__), 'README')) | Ruby |
module ActiveDirectorySearch
# generate controller method to handle autocompleter
def active_directory_auto_complete_for(object, method, options = {})
define_method("auto_complete_for_#{object}_#{method}") do
searcher = ActiveDirectorySearcher.new
searcher.initialization
@items = searcher.search ... | Ruby |
ActiveRecord::Schema.define do
create_table :tracks, :force => true do |tr|
tr.column :trackable_type, :string
tr.column :trackable_id, :integer
tr.column :version, :integer
tr.column :record_data, :text
tr.column :action, :string
tr.column :create... | Ruby |
class Topic < ActiveRecord::Base
acts_as_tracked
has_many :questions , :dependent => :destroy
end
class Question < ActiveRecord::Base
belongs_to :topic
end
class Track < ActiveRecord::Base; end
class DeletedTrackable < ActiveRecord::Base; end
| Ruby |
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '/../config/environment.rb'))
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
if !ActiveR... | Ruby |
# desc "Explaining what the task does"
# task :acts_as_tracked do
# # Task goes here
# end | Ruby |
# Install hook code here
| Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_tracked plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the acts_as_tracke... | Ruby |
# Uninstall hook code here
| Ruby |
# Include hook code here
require 'rubygems'
require 'active_record'
require 'rexml/document'
require "#{File.dirname(__FILE__)}/lib/track"
require "#{File.dirname(__FILE__)}/lib/deleted_trackable"
require "#{File.dirname(__FILE__)}/lib/acts_as_tracked" | 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 |
# 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 |
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
unless defined?(RAILS_ROOT)
root_path = File.join(File.dirname(__FILE__), '..')
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
require 'pathname'
root_path = Pathname.new(root_path).cleanpath(true).to_s
end
... | Ruby |
# Be sure to restart your web 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 =... | Ruby |
# ActsAsTracked
# Copyright (c) 2007 Marjun Pagalan
module June
module Acts
# This plugin will track your AR model [changes , deletion] to be save in track table.
# This also assumes that there is already track table.
#
# class Topic < ActiveRecord::Base
# acts_as_tracked
# ... | Ruby |
class DeletedTrackable < ActiveRecord::Base
def restore
rec = ActiveRecord::Base.const_get(trackable_type).restore_from_xml(record_data, :id => trackable_id)
rec.id= trackable_id
return rec if rec && rec.save && self.destroy
raise "There was an error restoring the #{model} from DeletedRecord(#{id... | Ruby |
class Track < ActiveRecord::Base
# revert the object to a given revision number
def restore
rec = ActiveRecord::Base.const_get(trackable_type).restore_from_xml(record_data, :id => trackable_id)
rec.id= trackable_id
ActiveRecord::Base.const_get(trackable_type).without_tracking do
rec.ve... | Ruby |
ActiveScaffold rescue
raise "ActiveScaffoldSchema depends on ActiveScaffold. Enable the plugin first"
ActiveScaffold::Helpers::ListColumns rescue
raise "ActiveScaffoldSchema works only ActiveScaffold-1.1.0rc1 or higher"
ActiveScaffold::Config::Search.class_eval do
def colors
unless @colors
@colors
... | Ruby |
# Uninstall hook code here
| Ruby |
# Install hook code here
| Ruby |
# desc "Explaining what the task does"
# task :acts_as_keywordable do
# # Task goes here
# end | Ruby |
# Install hook code here
| Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_keywordable plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the acts_as_ke... | Ruby |
# Uninstall hook code here
| Ruby |
require 'acts_as_keywordable'
ActiveRecord::Base.send(:include, ActiveRecord::Acts::Keywordable)
require File.dirname(__FILE__) + '/lib/keywording'
require File.dirname(__FILE__) + '/lib/keyword' | Ruby |
class Keywording < ActiveRecord::Base
belongs_to :keyword
belongs_to :keywordable, :polymorphic => true
def self.tagged_class(keywordable)
ActiveRecord::Base.send(:class_name_of_active_record_descendant, keywordable.class).to_s
end
def self.find_taggable(tagged_class, tagged_id)
tagged_class.const... | Ruby |
module ActiveRecord
module Acts #:nodoc:
module Keywordable #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_keywordable(options = {})
write_inheritable_attribute(:acts_as_keywordable_options, {
:keywordable_t... | Ruby |
class Keyword < ActiveRecord::Base
has_many :keywordings
def self.parse(list)
keyword_names = []
keyword_names = list.split(/[\r\n]/).uniq.reject {|c| c == ""}
# strip whitespace from the names
keyword_names = keyword_names.map { |t| t.strip }
# delete any blank tag names
keyword... | Ruby |
# example how I wish to configurate my active_background
ActiveBackground.Configuration.configure do |config|
# configuration for master server and middleman
config.host='127.0.0.1'
config.port=9595
config.server_name='active_background'
config.background=true
config.logging.enable=true
conf... | Ruby |
require 'thread'
require 'drb'
require 'drb/observer'
require 'logger'
require 'singleton'
require 'digest/md5'
require 'yaml'
require 'monitor'
Thread.abort_on_exception=true
$ACTIVE_BACKGROUND_DEBUG = true
# logger
require 'logger'
ACTIVE_BACKGROUND_LOGGER = Logger.new(File.dirname(__FILE__) + '/log... | Ruby |
require File.dirname(__FILE__) + "/tasks/active_background_tasks.rake" | Ruby |
#!/usr/bin/env ruby
require "stop_server.rb" | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + 'start_server.rb' | Ruby |
require File.dirname(__FILE__) + "/../init.rb"
ActiveBackground::Server.start() | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + 'start_server.rb' | Ruby |
#!/usr/bin/env ruby
require "stop_server.rb" | Ruby |
require "win32/service"
include Win32
# If we got this far, we are running as a service.
class Daemon
def service_init
# Give the service time to get everything initialized and running,
# before we enter the service_main function.
sleep 10
end
def service_main
require File.dirname(... | Ruby |
require 'rake'
require 'getoptlong'
namespace :active_background do
task :setup do
require File.dirname(__FILE__) + "/../init.rb"
ActiveBackground::Configuration.setup()
end
task :server do
require File.dirname(__FILE__) + "/../init.rb"
ActiveBackground::Server.start()
end
... | Ruby |
# Install hook code here
| Ruby |
class MyWorker < ActiveBackground::Worker
def work
# work_on :all
# get a connection
database do
@persons = Person.find(:all)
end
database do
@persons2 = Person.find(:all)
end
ACTIVE_BACKGROUND_LOGGER.warn(@persons.size)
ACTIVE_BACKGROUND_LOGGER... | Ruby |
class MyJob < ActiveBackground::Worker
def process
end
end | Ruby |
module ActiveBackground
class Base
def linux?
if !defined(__human68k__) && !defined(_WIN32) && !defined(__MACOS__) && !defined(__EMX__) && !defined(__VMS)
true
else
false
end
end
end
end | Ruby |
module ActiveBackground
module DatabaseHandler
def database(attempt=0, &block)
database = ActiveBackground::Database.instance
database.lock
begin
db = Thread.new do
database.prepare
self.instance_eval(&block)
database.terminate
end
... | Ruby |
# == Server
#
# The server module is responsible for installing (as service), running,
# stopping, detaching, and terminating the DRb server. Use one of the
# supplied rake tasks to start the server like:
#
# rake ActiveBackground::server
#
# But you can also use one of the following:
#
# rake Active... | Ruby |
module ActiveBackground
class Worker < ActiveBackground::Job
def initialize(name, options={}, args={})
super(name, options, args)
@worker_threads = Hash.new
end
def process_job()
# start working, this method is always run unless termination is called
# in one of the met... | Ruby |
module ActiveBackground
class Queue < ActiveBackground::Job
def process_job
# advanced job handeling (including queue handeling....)
end
end
end | Ruby |
module ActiveBackground
class Chef < ActiveBackground::Handler
# initialize implementation by including the default worker directories
def initialize
super
Dir.foreach(File.dirname(__FILE__) + "/../../workers/") do |file|
if file != "." && file != ".."
require File.dirna... | Ruby |
module ActiveBackground
class Cache < ActiveBackground::Handler
def initialize
super
end
end
end | Ruby |
module ActiveBackground
class Handler
def initialize
@middle_man = ActiveBackground::MiddleMan.instance
end
end
end | Ruby |
module ActiveBackground
class Client
@@server = false
def prepare
connect unless @@server
if @@server.terminated?
raise "Server is being terminated"
end
end
def connect(client_options = {})
@client_options ||= client_options
config = Con... | Ruby |
module ActiveBackground
# some methods to convert the keys from symbols to strings
# and back again....
class Configuration
def load(file)
config = YAML.load_file(file)
config.each do |key, value|
unless key.is_a?(Symbol)
config[key.to_sym] = value
config.d... | Ruby |
module ActiveBackground
class Archive
end
end | Ruby |
module ActiveBackground
class Manager
include Singleton
@@config = {
:sleep => 10
}
def initialize
@jobs = Hash.new
@queue = Hash.new
@running = true
@lock = Monitor.new
@threads = Hash.new
@terminated = nil
r... | Ruby |
module ActiveBackground
class Job
DRbUndumped
include ActiveBackground::DatabaseHandler
@@job_options = {
:terminate => true,
:archive => false,
:postpone_termination => false,
:before_job => false,
... | Ruby |
module ActiveBackground
class Assistent
end
end | Ruby |
module ActiveBackground
class Negotiator
end
end | Ruby |
module ActiveBackground
class Slave < ActiveBackground::Server
end
end | Ruby |
# The client program to communicate with the server
#
# MiddleMan allows you to connect to the ActiveBackground::Server
# to push jobs and retrieve jobs. The jobs are managed by
# ActiveBackground::Manager.
module ActiveBackground
class MiddleMan < Client
include Enumerable
include Singleton
... | Ruby |
module ActiveBackground
class AccessControl
end
end | Ruby |
ActiveBackground::Initializer.configure do |config|
end | Ruby |
ActiveBackground::Initializer.configure do |config|
end | Ruby |
ActiveBackground::Initializer.configure do |config|
config.logging(STDOUT) do |logger|
logger.level = Logger::WARN
end
end | Ruby |
# example how I wish to configurate my active_background
ActiveBackground::Initializer.configure do |config|
# configuration for master server and middleman
config.server(:master).host='localhost'
config.server(:master).port=9595
config.server(:master).name='active_background'
config.server(:maste... | Ruby |
begin
require 'thread'
require 'drb/drb'
require 'drb/observer'
require 'drb/timeridconv'
require 'logger'
require 'singleton'
require 'digest/md5'
require 'yaml'
require 'monitor'
require 'find'
require 'logger'
# base class
require File.dirname(__FILE__) + '/lib/active_backg... | Ruby |
require 'win32ole'
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = false
ie.navigate("http://www.pragmaticprogrammer.com")
ie.visible = true
ie.navigate("http://www.tweakers.net/")
ie.navigate("http://www.fok.nl/") | Ruby |
require 'drb'
require 'rubygems'
require 'betabrite'
DRb.start_service()
obj = DRbObject.new(nil, 'druby://eviladmins.org:9000')
File.open("out4.jpg", 'wb') { |a|
a.write obj.write_simple("Advany")
}
| Ruby |
require 'diff/lcs'
seq1 = "a b c e h j l m n p"
seq2 = "b c d e f j k l m r s t"
lcs = Diff::LCS.LCS(seq1, seq2)
diffs = Diff::LCS.diff(seq1, seq2)
sdiff = Diff::LCS.sdiff(seq1, seq2)
#puts lcs.inspect
#puts diffs.inspect
puts sdiff.inspect | Ruby |
require "drb/drb"
class ServerOne
def initialize
@object=Job.new
end
def get
@object
end
end
class ServerTwo
def retrieve
drb = DRb::DRbObject.new(nil, "druby://localhost:11123")
@object = drb.get
drb = nil
end
def process
puts @object.name
puts @ob... | Ruby |
=begin
dRuby sample
Copyright (c) 2000 Masatoshi SEKI
= How to play
* Terminal 1
% ruby -I. extserv_test.rb server
druby://yourhost:12345
* Terminal 2
% ruby -I. extserv_test.rb druby://yourhost:12345
...
=end
require 'drb/drb'
def ARGV.shift
it = super()
raise "usage:\ns... | Ruby |
require 'rake'
load File.dirname(__FILE__) + '/tasks/active_background_tasks.rake' | Ruby |
#!/usr/bin/env ruby
require "stop_server.rb" | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + 'start_server.rb' | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + 'start_server.rb' | Ruby |
#!/usr/bin/env ruby
require "stop_server.rb" | Ruby |
require "win32/service"
include Win32
# If we got this far, we are running as a service.
class Daemon
def service_init
# Give the service time to get everything initialized and running,
# before we enter the service_main function.
sleep 10
end
def service_main
require File.dirname(... | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
task :default => [:test]
namespace :active_background do
task :setup do
require File.dirname(__FILE__) + "/../init.rb"
ActiveBackground::Configuration.instance.setup()
end
task :server do
begin
require File.dirname... | Ruby |
class MyWorker < ActiveBackground::Worker
def work
# work_on :all
# get a connection
1.times do
database do
@persons = Person.find(:all)
end
end
@logger.info('MyWorker: worked')
end
def task_find_feed
@logger.info('MyWorker: find feed')
... | Ruby |
class MyJob < ActiveBackground::Worker
def process_job
# work_on :all
# get a connection
1.times do
database do
@persons = Person.find(:all)
end
end
@logger.info('MyWorker: worked')
end
end | Ruby |
class Person < ActiveRecord::Base
end | Ruby |
module ActiveBackground
module Handler
class Feed
def discover(url=nil, options={})
# TODO: strip website searching for feeds
# @middle_man.job.register(directory)
# @middle_man.job.atom(url, {:postpone_termination => 5}, {:pass_result_to => :my_job_name})
end
end
... | Ruby |
# Install hook code here
| Ruby |
# = Active Background
#
# Something about active background
#
# == MiddleMan
#
# The client program to communicate with the server
#
# MiddleMan allows you to connect to the ActiveBackground::Server
# to push jobs and retrieve jobs. The jobs are managed by
# ActiveBackground::Manager.
#
# == Client
# ... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.