code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#
# << 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 >> -- 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 |
#!/usr/bin/env ruby
require 'rubygems'
require 'mqtt'
MQTT::Client.connect('localhost',1883) do |client|
client.get('#') do |topic,message|
puts "#{topic}: #{message}"
end
end
| Ruby |
class InitialSchema < 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, :str... | 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 |
#!/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 |
atom_feed(:url => @feed_url, :language => 'ko-KR') do |feed|
feed.title(APP_CONFIG[:site_name] + ' - ' + @board.title)
feed.updated(@posts.first ? @posts.first.created_at : Time.now.utc)
for post in @posts
feed.entry(post, :url => board_post_path(@board, post)) do |entry|
entry.title(post.title)
... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def jquery_onload(&block)
content_for(:jquery_onload) do
javascript_tag "$(document).ready(function() { #{capture(&block)} });"
end
end
def block_to_partial(partial_name, options = {}, &bl... | Ruby |
module BoardsHelper
end
| Ruby |
module Admin::BoardsHelper
end
| Ruby |
module SessionsHelper
end | Ruby |
module HelpHelper
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 PostsHelper
def link_to_author(post)
if post.user
post.user
# link_to post.user #, user_path(post.user)
else
link_to_unless post.homepage.blank?, post.author, post.homepage
end
end
end
| Ruby |
module PagesHelper
end
| Ruby |
module RepliesHelper
end
| Ruby |
module HomeHelper
end
| Ruby |
class MenuBuilder
def self.create_top_nav(data, cascading = true)
returning("<ul id=\"top_nav\" class=\"sf-menu\">\n") do |html|
if cascading
data.each { |top_menu| html << create_menu(top_menu) }
else
data.each do |top_menu|
html << "<li class=\"<%= 'current' if current_pag... | Ruby |
class Post < ActiveRecord::Base
belongs_to :board, :counter_cache => true
belongs_to :user
# self-referential replies
has_many :replies, :class_name => "Post", :foreign_key => "parent_id", :order => 'created_at'
belongs_to :post, :class_name => "Post", :foreign_key => "parent_id", :counter_cache => 'replies_... | Ruby |
class Board < ActiveRecord::Base
has_many :posts, :conditions => ['tmp = ?', false]
validates_presence_of :title
validates_presence_of :name
validates_uniqueness_of :name
def to_s; name end
def to_param; name end
end
| Ruby |
class OpenLevel
CLOSED=0
LIST_ONLY=1
READ_ONLY=2
OPEN=99
def self.options
[['비공개', CLOSED], ['목록보기', LIST_ONLY], ['내용보기', READ_ONLY], ['읽고쓰기', OPEN]]
end
def self.level(level)
options.find { |option| option.last == level }.first
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 Page < ActiveRecord::Base
belongs_to :user
validates_presence_of :title
validates_presence_of :name
validates_uniqueness_of :name
acts_as_wikitext :body
simply_searchable
def to_param; name end
end
| Ruby |
class PagesController < ApplicationController
before_filter :login_required, :except => [:index, :show]
def index
end
def show
@page = Page.find_by_name(params[:id])
new unless @page
end
def new
@page = Page.create(:title => params[:id], :name => params[:id])
render :action => 'edit'
en... | Ruby |
class PostsController < ApplicationController
before_filter :find_board, :except => [:home, :search]
before_filter :check_open_level, :except => [:home, :search]
protect_forms_from_spam :only => [:new, :edit, :show]
PER_PAGE = 10
def index
find_posts
@feed_url = formatted_board_posts_url(@board, :a... | 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
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
he... | Ruby |
class HelpController < ApplicationController
def service_info
end
def privacy
end
end
| Ruby |
class Admin::BoardsController < Admin::AdminController
make_resourceful do
actions :index, :new, :create, :edit, :update, :destroy # :all
response_for :create, :update do |format|
format.html { redirect_to admin_boards_path }
end
end
def current_object
@current_object ||= current_model.f... | Ruby |
class Admin::UsersController < Admin::AdminController
make_resourceful do
actions :index, :edit, :update, :destroy # :all
end
def current_object
@current_object ||= current_model.find_by_login(params[:id])
end
def current_objects
@current_object ||= current_model.paginate( :order => "created_... | Ruby |
class Admin::AdminController < ApplicationController
before_filter :admin_required
layout 'admin'
end | Ruby |
class HomeController < ApplicationController
# here goes all static html pages
caches_page :show
def index
render :action => :index
rescue
redirect_to page_path(APP_CONFIG[:home_title])
end
def show
render :action => params[:page]
end
end
| Ruby |
class UsersController < ApplicationController
# render new.rhtml
def new
@user = User.new
end
def create
logout_keeping_session!
@user = User.new(params[:user])
success = @user && @user.save
if success && @user.errors.empty?
# Protects against session fixation attacks, causes ... | Ruby |
class RepliesController < ApplicationController
before_filter :find_post
def create
@reply = @post.replies.build(params[:reply])
@reply.user = current_user
unless @reply.save
# flash[:notice] = @reply.errors.map(&:to_s).join('\n') #'Something wrong'
error_stickie(@reply.errors.full_messages... | Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# render new.rhtml
def new
end
def create
logout_keeping_session!
user = User.authenticate(params[:login], params[:password])
if user
# Protects against session fixation attack... | 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 |
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:kymd => "%Y년%m월%d일",
:kmd => "%m월%d일",
:khm => "%H:%M",
:klong => "%Y-%m-%d %H:%M",
:kym => "%Y년 %m월",
:ymdhm => "%Y.%m.%d %H:%M"
) | 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 |
ActionView::Base.default_form_builder = LabelingFormBuilder | Ruby |
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/site_config.yml")[RAILS_ENV].symbolize_keys | Ruby |
ActionController::Routing::Routes.draw do |map|
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/register', :controller => 'users', :action => 'create'
map.signup '/signup', :controller => 'users', :action => 'n... | 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.3... | 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
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 ? users(user).id : nil
end
def authorize_as(user)
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials... | Ruby |
namespace :batch do
namespace :tmp do
desc "Count all temporary posts"
task :count => :environment do
puts "There are #{Post.tmp.count} temporary posts."
end
desc "Delete all temporary posts"
task :delete_all => :environment do
puts "#{Post.tmp.delete_all} temporary post(s) delet... | Ruby |
def menu_config_file
File.join("config", "menu.yml")
end
def top_nav_file
File.join("app", "views", "layouts", "_top_nav.html.erb")
end
def side_nav_file
File.join("app", "views", "layouts", "_side_nav.html.erb")
end
namespace :zi5 do
namespace :build do
desc "Generates default menu templates from confi... | 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 |
# 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 |
ExceptionNotifier.exception_recipients = %w(sjoonk@gmail.com) | 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 |
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:kymd => "%Y년%m월%d일",
:kmd => "%m월%d일",
:khm => "%H:%M",
:klong => "%Y-%m-%d %H:%M"
) | Ruby |
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV].symbolize_keys | 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 |
# 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 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.1... | 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 |
ActionController::Routing::Routes.draw do |map|
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/register', :controller => 'users', :action => 'create'
map.signup '/signup', :controller => 'users', :action => 'ne... | Ruby |
module RepliesHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
#include ActiveUploadHelper
def jquery_onload(&block)
content_for(:jquery_onload) do
javascript_tag "$(document).ready(function() { #{capture(&block)} });"
end
end
def block_to_partial(p... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.