code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class CreateViewCounts < ActiveRecord::Migration
def self.up
create_table :view_counts do |t|
t.column :count, :integer
t.column :object_type, :string
t.column :object_id, :integer
end
end
def self.down
drop_table :view_counts
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments, :force => true do |t|
t.column :title, :string, :limit => 50, :default => ""
t.column :comment, :string, :default => ""
t.column :created_at, :datetime, :null => false
t.column :commentable_id, :integer, :de... | Ruby |
class CreateSpaces < ActiveRecord::Migration
def self.up
create_table :spaces do |t|
t.column "name", :string, :null => false
t.column "description", :string
t.column "created_at", :datetime
t.column "type", :string
end
end
def self.down
drop_table :spaces
end
end
| Ruby |
class AddSessions < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.column :session_id, :string
t.column :data, :text
t.column :updated_at, :datetime
end
add_index :sessions, :session_id
end
def self.down
drop_table :sessions
end
end
| Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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.... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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.... | 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 |
# 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 |
# 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 |
# 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 =~ /mswin32/
require 'pathname'
root_path = Pathname.new(root_path).cleanpath(true).to_s
end
RAILS... | Ruby |
ActionController::Routing::Routes.draw do |map|
#UJS::routes
# ActiveRbac's RegistrationController confirmation action needs a special route
map.connect '/active_rbac/registration/confirm/:user/:token',
:controller => 'active_rbac/registration',
:action => 'confirm'
map.connect '', :c... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def include page, page_title
page_included=Page.find :first, :conditions=>["title=? and space_id=?", page_title[1..-1], page.space.id]
markup page_included, page_included.content
end
de... | Ruby |
# CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting
#
# Screw the license.
class Date
def week
return self.next.cweek
end
end
module CalendarHelper
# Returns an HTML calendar. In its simplest form, this method generates a plain
# calendar (which can then be ... | Ruby |
module AttachmentHelper
def size_to_s size
if size > GIGA
return (size/GIGA) .to_s + "GB"
elsif size > MILLION
return (size/MILLION) .to_s + "MB"
elsif size > KILO
return (size/KILO) .to_s + "KB"
else
return size.to_s + "B"
end
end
end
| Ruby |
module UserHelper
end
| Ruby |
module PageHelper
end
| Ruby |
class Page < ActiveRecord::Base
acts_as_ferret({},{:analyzer=>Ferret::Analysis::RegExpAnalyzer.new(/./,false)})
acts_as_versioned
PAGE_LINK = /\[([^\]|]*)[|]?([^\]]*)\]/
belongs_to :space
belongs_to :creator, :class_name=>'User', :foreign_key=>'creator_id'
belongs_to :user
has_many :attachments
has_ma... | Ruby |
class Weblog < Page
end
| Ruby |
class Space < ActiveRecord::Base
has_many :pages
has_many :weblogs
def existing_page_titles
connection.select_all("SELECT title FROM pages WHERE space_id = #{self.id.to_i}").map { |row| row['title'] }
end
end
| Ruby |
class PageSweeper < ActionController::Caching::Sweeper
observe Page, Weblog, Comment
def after_save(record)
# 把cache全删了
FileUtils.rm_rf(RAILS_ROOT + "/public/index.html")
FileUtils.rm_rf(RAILS_ROOT + "/public/space/")
FileUtils.rm_rf(RAILS_ROOT + "/public/page/")
FileUtils.rm_rf(RAILS_ROOT + "/... | Ruby |
class ViewCount < ActiveRecord::Base
end
| Ruby |
class Comment < ActiveRecord::Base
acts_as_ferret({},{:analyzer=>Ferret::Analysis::RegExpAnalyzer.new(/./,false)})
belongs_to :commentable, :polymorphic => true
# NOTE: install the acts_as_votable plugin if you
# want user to vote on the quality of comments.
#acts_as_voteable
# NOTE: Comments belong ... | Ruby |
class Attachment < ActiveRecord::Base
belongs_to :page
belongs_to :user
end
| Ruby |
class UserController < ApplicationController
layout nil
def loginbox
if current_user.is_anonymous?
render :partial => "anonymous"
else
render :partial => "loggined"
end
end
def view_count
if !(['show', 'show_month'].include?(params[:a]))
return render(:text=>"")
end
i... | Ruby |
class PageController < ApplicationController
scaffold :page
cache_sweeper :page_sweeper
#caches_page :show, :displaypage
def comments
@page = Page.find params[:id]
@comments_str=render_to_string :partial => "comments"
end
def download_attach
attach = Attachment.find :first, :conditions=>["name... | Ruby |
# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
require_dependency "#{RAILS_ROOT}/vendor/plugins/active_rbac/app/helpers/rbac_helper"
class ApplicationController < ActionController::Base
helper RbacHelper
... | 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 |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/breakpointer' | 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/runner' | 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/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/profiler'
| 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/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/breakpointer' | 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/console' | 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/spawner'
| 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/spawner'
| 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/generate' | 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/about' | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin' | Ruby |
class CreatePages < ActiveRecord::Migration
def self.up
create_table :pages do |t|
t.column :title, :string, :null => false
t.column :content, :string
t.column :creator_id, :integer
t.column :user_id, :integer, :null => false
t.column :parent_id, :integer
t.column :created_at, ... | Ruby |
class CreateAttachments < ActiveRecord::Migration
def self.up
create_table :attachments do |t|
t.column :name, :string, :null => false
t.column :size, :integer
t.column :page_id, :integer
t.column :user_id, :integer, :null => false
t.column :created_at, :datetime
t.column :desc... | Ruby |
class AddPersonalSpaceForUser < ActiveRecord::Migration
def self.up
add_column :users, :personal_space_id, :integer, :default=>-1
User.update_all "personal_space_id = -1"
end
def self.down
remove_column :users, :personal_space_id
end
end
| Ruby |
class ChangeCommentsToSelfwrite < ActiveRecord::Migration
def self.up
remove_column :comments, :commentable_type
add_column :comments, :page_id, :integer
Comment.update_all "page_id=commentable_id"
remove_column :comments, :commentable_id
end
def self.down
add_column :comments, :commentable_i... | Ruby |
class AddDefaultUserAndRole < ActiveRecord::Migration
def self.up
end
def nothing
role = Role.new
role.title = 'Admin'
role.save
user = User.new
user.login = 'Admin'
user.update_password 'password'
user.email = 'root@localhost'
# the next line is essential
user.state = User.s... | Ruby |
class AddUserNickname < ActiveRecord::Migration
def self.up
add_column "users", "nick_name", :string
end
def self.down
remove_column "users", "nick_name"
end
end
| Ruby |
class TranslateFormatText < ActiveRecord::Migration
# Need to disable the Page's acts_as_versioned and acts_as_ferret method
def self.up
transaction do
pages=Page.find :all
pages.each do |page|
page.content.gsub!( "{{{", "<pre>")
page.content.gsub!( "}}}", "</pre>")
page.co... | Ruby |
class CreatePageVersion < ActiveRecord::Migration
def self.up
add_column "pages", "version", :integer
Page.create_versioned_table
end
def self.down
Page.drop_versioned_table
remove_column "pages", "version"
end
end
| Ruby |
class CreateViewCounts < ActiveRecord::Migration
def self.up
create_table :view_counts do |t|
t.column :count, :integer
t.column :object_type, :string
t.column :object_id, :integer
end
end
def self.down
drop_table :view_counts
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments, :force => true do |t|
t.column :title, :string, :limit => 50, :default => ""
t.column :comment, :string, :default => ""
t.column :created_at, :datetime, :null => false
t.column :commentable_id, :integer, :de... | Ruby |
class CreateSpaces < ActiveRecord::Migration
def self.up
create_table :spaces do |t|
t.column "name", :string, :null => false
t.column "description", :string
t.column "created_at", :datetime
t.column "type", :string
end
end
def self.down
drop_table :spaces
end
end
| Ruby |
class AddSessions < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.column :session_id, :string
t.column :data, :text
t.column :updated_at, :datetime
end
add_index :sessions, :session_id
end
def self.down
drop_table :sessions
end
end
| Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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.... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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 imp... | Ruby |
#!c:/soft/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.... | 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 |
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.string :profile_id
t.string :email
t.string :refresh_token
end
add_index :users, :profile_id
end
def down
drop_table :users
end
end
| Ruby |
# Copyright (C) 2012 Google Inc.
#
# 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 agreed to in writ... | Ruby |
source :gemcutter
gem 'sinatra', :require => 'sinatra/base'
gem 'thin', '~> 1.3'
gem 'pg'
gem 'sinatra-activerecord'
gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client'
group :development do
gem 'rake'
gem 'sqlite3-ruby'
end
| Ruby |
require 'sinatra.rb'
# Sinatra defines #set at the top level as a way to set application configuration
set :run, false
set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development)
require './main'
run Sinatra::Application | Ruby |
require 'sinatra/activerecord/rake'
require './main' | Ruby |
class SmbFuzz
def initialize
end
def on_start(desc)
cmsg("SmbFuzzer: Received start event")
end
def on_stop(desc)
cmsg("SmbFuzzer: Received stop event")
end
def on_error(desc, error)
cmsg("SmbFuzzer: Received error event (code: #{error})")
end
def on_data(desc, direction... | Ruby |
class HttpFuzzer
FUZZ_STRINGS = [
"/.../.../.../.../.../",
"/.../.../.../.../..." * 100,
"/.../.../.../.../..." * 50,
"/.../.../.../.../..." * 1024,
"/.../.../.../.../..." * 10,
"/.../.../.../.../..." * 1,
"../../../../../../../../../../../../etc/hosts%00",
"../../../.... | Ruby |
class FuzzBlock
FUZZ_STRINGS = [
"A" * 100,
"X" * 100
]
def initialize
@@tokens = []
@@token_idx = 0
@@fuzz_idx = 0
@@orig_data = ""
end
def prepare_for(data, tokens)
@@tokens = tokens
@@orig_data = data
end
def get_next_fuzz_string
return ni... | Ruby |
# Blind data stream fuzzer
class StreamFuzzer
def initialize
@started = false
@saveslot = []
@pkt_count = 0
end
def on_start(w_desc)
@started = true
@fuzz_state = 0
@curr_state = 0
if w_desc.run_count > 1
@fuzz_state = 1 + (rand(Process.pid) % (@pkt_count -... | Ruby |
module Attack
class StringAttack
attr_accessor :string
def initialize(string)
@string = string
end
def AppendStringAfterEachByte(repeat_string,no_of_repetation)
ret_array = []
for i in 0...@string.length
ret_str = String.new(@string)
first_part = ret_str[0,i+1]
l... | Ruby |
class MySampleHook
def initialize
puts ">> MySampleHook initialized"
end
def on_start(desc)
puts ">> MySampleHook start (desc: #{desc.inspect})"
end
def on_data(desc, direction, data)
puts ">> MySampleHook data (desc: #{desc.inspect})"
puts ">> MySampleHook data (direction: #{di... | Ruby |
puts "Hello Wireplay!"
| Ruby |
require 'mkmf'
EXT_NAME = 'winter_sense'
dir_config(EXT_NAME)
create_makefile(EXT_NAME)
| Ruby |
desc "Use Uglify JS to compress Underscore.js"
task :build do
sh "uglifyjs underscore.js -c -m -o underscore-min.js"
end
desc "Build the docco documentation"
task :doc do
sh "docco underscore.js"
end
| Ruby |
# $ext_path: This should be the path of where the ExtJS SDK is installed
# Generally this will be in a lib/extjs folder in your applications root
# <root>/lib/extjs
$ext_path = "../../"
# sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder
# Generally this will be in a resource... | Ruby |
# include the utils rb file which has extra functionality for the ext theme
dir = File.dirname(__FILE__)
require File.join(dir, 'lib', 'utils.rb')
# register ext4 as a compass framework
Compass::Frameworks.register 'ext4', dir | Ruby |
# $ext_path: This should be the path of the Ext JS SDK relative to this file
$ext_path = "../../extjs"
# sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder
# Generally this will be in a resources/sass folder
# <root>/resources/sass
sass_path = File.dirname(__FILE__)
# css_pat... | Ruby |
# Compass configurations
sass_path = File.dirname(__FILE__)
css_path = File.join(sass_path, "..", "css")
# Require any additional compass plugins here.
images_dir = File.join(sass_path, "..", "img")
output_style = :expanded
environment = :production | Ruby |
module ExtJS4
module SassExtensions
module Functions
module Utils
def parsebox(list, n)
assert_type n, :Number
if !n.int?
raise ArgumentError.new("List index #{n} must be an integer")
elsif n.to_i < 1
raise ArgumentError.new("List index #{n} must... | Ruby |
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
# You can select your preferred output style here (can be overridden via the command line):
# output_styl... | 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 |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.