code
stringlengths
1
1.73M
language
stringclasses
1 value
class Time class << Time def parse(date, now=Time.now) d = Date._parse(date, false) year = d[:year] year = yield(year) if year && block_given? make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now) end def xmlschema(date) if ...
Ruby
require 'test/unit' $: << File.join(File.dirname(__FILE__), '..', 'app', 'lib')
Ruby
default_environment['PATH'] = "/usr/local/bin:$PATH" set :application, "trackbacks.seagul.co.uk" set :repository, "http://chrisroos.googlecode.com/svn/trunk/www/#{application}" set :deploy_to, "/home/chrisroos/www/#{application}" set :deploy_via, :copy role :app, "jail0093.vps.exonetric.net" role :web, "jail0093.vp...
Ruby
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
require 'rake/testtask' Rake::TestTask.new(:default) do |t| t.test_files = FileList['test/*_test.rb'] t.verbose = true end
Ruby
#!/usr/bin/env ruby DATA_DIRECTORY = File.join(File.dirname(__FILE__), 'data') TEMPLATE_DIRECTORY = File.join(File.dirname(__FILE__), 'views') require 'rubygems' require 'mongrel' require File.join(File.dirname(__FILE__), 'lib', 'trackback_http_request') require File.join(File.dirname(__FILE__), 'lib', 'trackback_ren...
Ruby
#!/usr/bin/env ruby DATA_DIRECTORY = File.join(File.dirname(__FILE__), 'data') TEMPLATE_DIRECTORY = File.join(File.dirname(__FILE__), 'views') require 'rubygems' require 'mongrel' require File.join(File.dirname(__FILE__), 'lib', 'trackback_http_request') require File.join(File.dirname(__FILE__), 'lib', 'trackback_ren...
Ruby
require File.join(File.dirname(__FILE__), 'http_body') class TrackbackHttpRequest class Trackback def self.from_http_request(http_request) body = http_request.body.read http_body = HttpBody.new(body) new(http_body.to_hash) end attr_reader :error def initialize(attribu...
Ruby
require File.join(File.dirname(__FILE__), 'trackback_http_request_http_method') require File.join(File.dirname(__FILE__), 'trackback_http_request_http_content_type') require File.join(File.dirname(__FILE__), 'trackback_http_request_trackback') class TrackbackHttpRequest attr_reader :trackback def initialize(...
Ruby
class TrackbackHttpRequest class HttpMethod attr_reader :error def initialize(request_params) @request_params = request_params @error = nil end def valid? unless valid = @request_params['REQUEST_METHOD'] == 'POST' @error = 'Http Method MUST be POST' end v...
Ruby
require File.join(File.dirname(__FILE__), 'weekday_suffix') class TrackbackRenderer def initialize(trackback) @trackback = trackback end def received_on weekday, month = @trackback['received_at'].strftime("%A %B").split(' ') "#{weekday} #{received_at_day_with_suffix} #{month}" end def re...
Ruby
class TrackbackHttpRequest class HttpContentType attr_reader :error def initialize(request_params) @request_params = request_params @error = nil end def valid? unless valid = @request_params['HTTP_CONTENT_TYPE'] =~ /^application\/x-www-form-urlencoded/ @error = "Cont...
Ruby
require 'uri' class HttpBody def initialize(body) @data = body.split('&').inject({}) do |hash, key_and_value| key, value = key_and_value.split('=') value = '' if value.nil? # URI.unescape will fail if value is nil (if we've left out the excert, for example) hash[key] = URI.unescape(value) ...
Ruby
class WeekdaySuffix def initialize(day) @day = day end def suffix case @day when 1, 21, 31 then 'st' when 2, 22 then 'nd' when 3, 23 then 'rd' else 'th' end end end
Ruby
require 'yaml' class Trackbacks DataLocation = File.join(DATA_DIRECTORY, 'trackbacks.yml') class << self def create(trackback) trackbacks = from_yaml_file(DataLocation) trackbacks.add(trackback) trackbacks.save end def find_all from_yaml_file(DataLocation) end ...
Ruby
require 'erb' include ERB::Util class ErbRenderer def initialize(template_file, binding) @template_file, @binding = template_file, binding end def render(output_buffer) template = File.open(@template_file) { |f| f.read } erb = ERB.new(template) output_buffer << erb.result(@binding) end end
Ruby
require 'test/unit' require 'rubygems' require 'mocha' $: << File.join(File.dirname(__FILE__), '..', 'lib')
Ruby
# breadcrumbs.rb module BreadcrumbsHelper # call-seq: # breadcrumbs( page ) => html # # Create breadcrumb links for the current page. This will return an HTML # <ul></ul> object. # def breadcrumbs( page ) list = ["<li>#{h(page.title)}</li>"] loop do page = @pages.parent_of(page) ...
Ruby
desc 'Deploy to the server using rsync' task :deploy do sh "rsync -av public/* chrisroos@seagul.co.uk:/home/chrisroos/www/thanetcommercials.co.uk" end
Ruby
# breadcrumbs.rb module BreadcrumbsHelper # call-seq: # breadcrumbs( page ) => html # # Create breadcrumb links for the current page. This will return an HTML # <ul></ul> object. # def breadcrumbs( page ) list = ["<li>#{h(page.title)}</li>"] loop do page = @pages.parent_of(page) ...
Ruby
set :application, "permailink.co.uk" set :repository, "http://chrisroos.googlecode.com/svn/trunk/www/#{application}" if ENV['HOSTS'] == 'localhost' set :domain, application.gsub(/\.co\.uk$/, '.local') else set :domain, application end set :deploy_to, "/u/chrisroos/www/#{domain}" set :deploy_via, :copy role :app...
Ruby
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
# = net/pop.rb # # Copyright (c) 1999-2007 Yukihiro Matsumoto. # # Copyright (c) 1999-2007 Minero Aoki. # # Written & maintained by Minero Aoki <aamine@loveruby.net>. # # Documented by William Webber and Minero Aoki. # # This program is free software. You can re-distribute and/or # modify this program under the same ...
Ruby
require 'tmail' require 'test/unit' require 'pp' module Permailink class Email attr_reader :forwarded_by def initialize(filename) @tmail = TMail::Mail.load(filename) @forwarded_by = @tmail.from.first @tmail = TMail::Mail.parse(@tmail.attachments.first.string) end def received_at ...
Ruby
require 'flickr' name = ARGV.shift dimensions = ARGV.shift weight = ARGV.shift tag = ARGV.shift unless name && dimensions && weight puts "Usage: ruby generate_data.rb name-of-item dimensions (wxhxd) weight [tag]" exit end description = '' while line = gets description << line end w, h, d = dimensions.split('x...
Ruby
require 'hpricot' require 'net/http' class Photos def self.get(tag) new(tag).photos end def initialize(tag) @tag = tag end def photos return [] unless @tag (doc/'td#GoodStuff'/'p.UserTagList'/'a').collect do |anchor| url = flickr_url + anchor.attributes['href'] thumbnail_url = (an...
Ruby
require 'erb' require 'yaml' require 'redcloth' template = File.open('template.erb.html') { |f| f.read } erb = ERB.new(template) Dir['listings/*'].each do |listing_filename| listing = YAML.load_file(listing_filename) html = erb.result(binding) File.open(File.join('html', "#{File.basename(listing_filename)}.html...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- line_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear...
Ruby
# # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice ...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- text_demo2.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- ttfont_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appe...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- font_example.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright noti...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- encryption.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- demo.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appea...
Ruby
# # << Haru Free PDF Library 2.0.6 >> -- slideshow_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice a...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- arc_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear ...
Ruby
require 'mkmf' $CPPFLAGS = $CPPFLAGS + " -I../../include" $LDFLAGS = $LDFLAGS + " -L../../" $LIBS = $LIBS + " -lhpdf -lpng -lz" create_makefile 'hpdf'
Ruby
# Copyright 2008-2009 Nokia Siemens Networks Oyj # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or...
Ruby
#!/usr/bin/env ruby class ExampleRemoteLibrary def count_items_in_directory(path) Dir.entries(path).find_all{|i| not i.match('^\.')}.length end def strings_should_be_equal(str1, str2) puts "Comparing '#{str1}' to '#{str2}'" if str1 != str2 raise RuntimeError, "Given strings are not equal" ...
Ruby
class RubyLibraryExample def get_server_language 'ruby' end # Basic communication def passing end def failing(message) raise message end def logging(message, level='INFO') puts "*#{level}* #{message}" end def returning 'returned string' end # Logging def one_message_w...
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
class CreateRoles < ActiveRecord::Migration def self.up create_table :roles do |t| t.string :title end Role.create(:title => "users"); Role.create(:title => "announcements"); Role.create(:title => "pages"); Role.create(:title => "photos"); Role.create(:title => "podcast"); R...
Ruby
class CreateAnnouncements < ActiveRecord::Migration def self.up create_table :announcements do |t| t.string :title t.text :body t.integer :position t.string :url_slug t.timestamps end end def self.down drop_table :announcements end end
Ruby
class AddActsAsTaggableTables < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name end add_index :tags, :name create_table :taggings do |t| t.integer :tag_id, :taggable_id t.string :taggable_type end add_index :taggings, [:tag_id, :taggable_type] ...
Ruby
class CreateAlbums < ActiveRecord::Migration def self.up create_table :albums do |t| t.string :title t.string :body t.string :url_slug t.integer :position t.timestamps end end def self.down drop_table :albums end end
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.string :title t.text :body t.string :url_slug t.integer :parent_id t.timestamps end end def self.down drop_table :pages end end
Ruby
class CreateVideos < ActiveRecord::Migration def self.up create_table :videos do |t| t.integer :clip_id t.string :title t.text :body t.string :url_slug t.string :photo_url t.timestamps end add_index :videos, :clip_id end def self.down drop_table :videos ...
Ruby
class CreateAppQuestions < ActiveRecord::Migration def self.up create_table :app_questions do |t| t.string :question t.string :answer_type t.integer :position t.boolean :required, :default => true end end def self.down drop_table :app_questions end end
Ruby
class CreateSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end def self.down drop_table :sessions end end
Ruby
class AddActsAsAuthoredTables < ActiveRecord::Migration def self.up create_table :authorings do |t| t.integer :authored_id, :user_id t.string :authored_type end end def self.down drop_table :authorings end end 9
Ruby
class CreateDefaultApplication < ActiveRecord::Migration def self.up AppQuestion.create(:question => "First Name", :answer_type => "small") AppQuestion.create(:question => "Middle Name", :answer_type => "small") AppQuestion.create(:question => "Last Name", :answer_type => "small") AppQuestion.create(:...
Ruby
class CreatePhotos < ActiveRecord::Migration def self.up create_table :photos do |t| t.integer :album_id t.integer :position t.integer :size t.string :filename t.string :content_type t.integer :height t.integer :width t.integer :parent_id t.string :thumbnai...
Ruby
class CreatePodcasts < ActiveRecord::Migration def self.up create_table :podcasts do |t| t.string :title t.string :url_slug t.text :body t.integer :size t.string :content_type t.string :filename t.timestamps end end def self.down drop_table :podcasts end e...
Ruby
class AddSettingsTable < ActiveRecord::Migration def self.up create_table :settings, :force => true do |t| t.column :var, :string, :null => false t.column :value, :text, :null => true t.column :created_at, :datetime t.column :updated_at, :datetime end end def self.down ...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.string :name t.string :email t.string :crypted_password, :limit => 40 t.string :salt, :limit => 40 t.string :remember_token t.datetime :remember_t...
Ruby
class CreateUserPermissions < ActiveRecord::Migration def self.up create_table :user_permissions do |t| t.integer :role_id t.integer :user_id end end def self.down drop_table :user_permissions end end
Ruby
class CreateAdmin < ActiveRecord::Migration def self.up User.create(:name => "admin", :email => "admin", :password => "admin", :password_confirmation => "admin"); User.find(:first).roles << Role.find_by_title('admin') end def self.down User.find(:first).destroy; end end
Ruby
class CreateUserPhotos < ActiveRecord::Migration def self.up create_table :user_photos do |t| t.integer :size t.string :content_type t.string :filename t.integer :height t.integer :width t.integer :user_id t.integer :parent_id t.string :thumbnail t.timestamps...
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
#!/opt/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
#!/opt/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
#!/opt/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
#!/opt/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
#!/opt/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
#!/opt/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/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 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 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 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 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/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/generate'
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Announcements Tagged with #{params[:tag]}" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @announcements.first.updated_at if...
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "#{Settings.short_title} Announcements" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @announcements.first.updated_at if @an...
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "#{Settings.short_title} Podcasts Tagged with #{params[:tag]}" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @videos.first.u...
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "#{Settings.short_title} Videos" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @videos.first.updated_at if @videos.any? ...
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "#{Settings.short_title} Podcasts Tagged with #{params[:tag]}" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @podcasts.first...
Ruby
xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "#{Settings.short_title} Podcasts" xml.link url_for :only_path => false, :controller => 'posts' xml.pubDate CGI.rfc1123_date @podcasts.first.updated_at if @podcasts.any...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module ButtonHelper def button_for(name, type, options = {}, html_options = {}) html_options[:class] = "button" link_to "<span><span><span class='#{type}'>#{name}</span></span></span>", options, html_options end end
Ruby
module Admin::PodcastsHelper end
Ruby
module Admin::ProfileHelper end
Ruby
module Admin::SettingsHelper end
Ruby