code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# = client.rb - Sphinx Client API
#
# Author:: Dmytro Shteflyuk <mailto:kpumuk@kpumuk.info>.
# Copyright:: Copyright (c) 2006 - 2008 Dmytro Shteflyuk
# License:: Distributes under the same terms as Ruby
# Version:: 0.9.9-r1299
# Website:: http://kpumuk.info/projects/ror-plugins/sphinx
#
# This library... | Ruby |
module Sphinx
# Pack ints, floats, strings, and arrays to internal representation
# needed by Sphinx search engine.
class Request
# Initialize new request.
def initialize
@request = ''
end
# Put int(s) to request.
def put_int(*ints)
ints.each { |i| @request << [i].p... | Ruby |
module Sphinx
# Unpack internal Sphinx representation of ints, floats, strings, and arrays.
# needed by Sphinx search engine.
class Response
# Initialize new request.
def initialize(response)
@response = response
@position = 0
@size = response.length
end
# Gets cu... | Ruby |
#
# $Id$
#
require 'init.rb'
q = ARGV.join(' ')
@sphinx = Sphinx::Client.new
# @sphinx.SetSortMode(Sphinx::Client::SPH_SORT_ATTR_ASC, 'created_at')
results = @sphinx.Query(q)
puts "Query '#{q}' retrieved #{results['total']} of #{results['total_found']} matches in #{results['time']} sec.";
puts "Query sta... | Ruby |
class AddWikiIdToPages < ActiveRecord::Migration
def self.up
add_column :pages, :wiki_id, :integer
end
def self.down
remove_column :pages, :wiki_id
end
end
| Ruby |
class CreateRevisions < ActiveRecord::Migration
def self.up
create_table :revisions do |t|
t.integer :page_id
t.integer :user_id
t.text :content
t.timestamps
end
end
def self.down
drop_table :revisions
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100, :default => '', :null => true
t.column :email, :string, ... | Ruby |
class CreateWikis < ActiveRecord::Migration
def self.up
create_table :wikis do |t|
t.string :title
t.string :subdomain
t.timestamps
end
add_index :wikis, :subdomain, :unique => true
end
def self.down
remove_index :wikis, :subdomain
drop_table :wikis
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :revision_id
t.integer :user_id
t.text :comment
t.timestamps
end
end
def self.down
drop_table :comments
end
end
| Ruby |
class CreatePages < ActiveRecord::Migration
def self.up
create_table :pages do |t|
t.string :title
t.timestamps
end
end
def self.down
drop_table :pages
end
end
| 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 |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | 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'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
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/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
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/dbconsole'
| 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/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 relative_time(from_time)
from_time = from_time.to_time if from_time.respond_to?(:to_time)
distance_in_minutes = (((Time.now - from_time).abs)/60).round
case distance_in_minutes
when 0.... | Ruby |
module SessionsHelper
end | Ruby |
module UsersHelper
#
# Use this to wrap view elements that the user can't access.
# !! Note: this is an *interface*, not *security* feature !!
# You need to do all access control at the controller level.
#
# Example:
# <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ... | Ruby |
module PageHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
class Wiki < ActiveRecord::Base
validates_presence_of :subdomain
validates_format_of :subdomain, :with => /^[A-Za-z0-9-]+$/, :message => "The subdomain can only contain alphanumeric characters and dashes."
validates_uniqueness_of :subdomain, :case_sensitive => false
validates_exclusion_of :subdomain, :in => %w(... | Ruby |
class Comment < ActiveRecord::Base
belongs_to :revision
belongs_to :user
def page
revision.page
end
def content
comment
end
end | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
validates_presence_of :login
validates_length_of :login, :within => 3..40
validates_uniqueness_of :login
validates_format_of :login, ... | Ruby |
class Revision < ActiveRecord::Base
has_many :comments
belongs_to :page
# Shows the human-readable revision number, no
# idea how it works, but it does.
def rid
return 1 if self.page.nil?
revs = self.page.revisions
rid = 0
until rid >= revs.length || revs[rid] == self
rid += 1
... | Ruby |
class Page < ActiveRecord::Base
validates_presence_of :title, :message => "can't be blank"
validates_uniqueness_of :title, :message => "is already in use by another page"
has_many :revisions
has_many :comments, :through => :revisions, :order => "comments.created_at DESC", :include => :user
belongs_to :wiki... | 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
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details... | Ruby |
class CommentsController < ApplicationController
before_filter :login_required
def create
@revision = Revision.find(params[:revision_id])
@comment = @revision.comments.build(params[:comment])
@comment.user_id = current_user.id
@comment.save
respond_to do |wants|
wants.html { redirect_to... | Ruby |
class UsersController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
@user = User.new
end
def create
logout_keeping_session!
@user = User.new(params[:user])
success = @user && @u... | Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
end
def create
logout_keeping_session!
user = User.... | Ruby |
class PageController < ApplicationController
before_filter :login_required, :only => [ :comment ]
before_filter :load_page
def show
respond_to do |wants|
wants.html # show.html.erb
wants.xml { render :xml => @page.to_xml }
end
end
def edit
end
def update
@page.update_attributes(... | 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):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person',... | Ruby |
# A Site key gives additional protection against a dictionary attack if your
# DB is ever compromised. With no site key, we store
# DB_password = hash(user_password, DB_user_salt)
# If your database were to be compromised you'd be vulnerable to a dictionary
# attack on all your stupid users' passwords. With a site... | Ruby |
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full clas... | 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 Resources
map.resources :users
map.resources :pages do |pages|
pages.resources :comments
end
map.resource :session
# Helper/Shortened URLs
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controll... | Ruby |
set :application, "yourwiki"
set :repository, "git@git.yourwiki.net:yourwiki.git"
set :scm, :git
set :deploy_via, :remote_cache
set :deploy_to, "/home/yourwiki/#{application}"
set :user, "yourwiki"
set :use_sudo, false
role :app, "serv2.yourwiki.net"
role :web, "serv2.yourwiki.net"
role :db, "serv2.yourwiki.net", :... | 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.2... | 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
# Enable threaded mode
# config.threadsafe!
# Use a different logger for distributed setups
# config.... | 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
end
# Accesses the current user from the session.
# Future calls avoid the database because nil is not ... | Ruby |
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil
end
def authorize_as(user)
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentic... | Ruby |
#
# Copied from Instiki-0.11.0 by David Heinemeier Hansson.
# License available at: http://www.ruby-lang.org/en/LICENSE.txt
#
module HTMLDiff
Match = Struct.new(:start_in_old, :start_in_new, :size)
class Match
def end_in_old
self.start_in_old + self.size
end
def end_in_new
self.start_... | Ruby |
#
# Inspired by
# http://dev.rubyonrails.org/svn/rails/plugins/account_location/lib/account_location.rb
#
module WikiSubdomains
def self.included( controller )
controller.helper_method(:wiki_domain, :wiki_subdomain, :wiki_url, :current_wiki, :default_wiki_subdomain, :default_wiki_url)
end
protected
... | Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to res... | Ruby |
#!/usr/bin/env rake
# 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.expand_path('../config/application', __FILE__)
YoursApi::Application.load_tasks
| Ruby |
source 'https://rubygems.org'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
#Xgem 'coffee-rails', '~... | Ruby |
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
| Ruby |
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
| Ruby |
xml.instruct!(:xml, :version=>"1.0")
xml.kml(:xmlns => "http://earth.google.com/kml/2.0") do
xml.document do
xml.distance @route.distance if @route.distance
xml.traveltime @route.traveltime if @route.traveltime
xml.folder do
xml.placemark do
xml.lineString do
... | Ruby |
module ApplicationHelper
end
| Ruby |
require 'net/http'
#
# https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api
# https://github.com/DennisOSRM/Project-OSRM/wiki/Output-json
#
class Osrm
Host = "router.project-osrm.org"
BasePath = "/viaroute?"
def self.route_get(flat, flon, tlat, tlon)
qstr = "loc=%s,%s&loc=%s,%s" % [flat, flo... | Ruby |
require 'net/http'
require 'shellwords'
#
# http://brensche.de/brouter
#
class Brouter
#Host = "h2096617.stratoserver.net"
#BasePath = "/cgi-bin/brouter.sh?"
def self.route_get(flat, flon, tlat, tlon)
#qstr = "coords=%s_%s_%s_%s_..%%2Fcustomprofiles%%2F%s_0" % [flon, flat, tlon, tlat, profile]
#Rail... | Ruby |
require 'net/http'
class Yours
Host = "www.yournavigation.org"
BasePath = "/api/1.0/gosmore.php?format=kml&"
# vehicle:
# motorcar
# bicycle
def self.route_get(flat, flon, tlat, tlon, vehicle = 'motorcar')
qstr = "flat=%s&flon=%s&tlat=%s&tlon=%s&v=%s&fast=1&layer=mapnik" % [flat, flo... | Ruby |
class RoutesController < ApplicationController
def show
case params[:v]
when 'bicycle'
# render(:text => Yours.route_get(params[:flat], params[:flon], params[:tlat], params[:tlon],
# params[:v]), :content_type => 'application/xml')
@route = Brouter.route_get... | Ruby |
class ApplicationController < ActionController::Base
protect_from_forgery
end
| 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):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', ... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters ... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attac... | 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 |
# Be sure to restart your server when you modify this file.
YoursApi::Application.config.session_store :cookie_store, key: '_yours-api_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rail... | Ruby |
YoursApi::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'prod... | Ruby |
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.requi... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
YoursApi::Application.initialize!
| Ruby |
YoursApi::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.actio... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.