code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
... | 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.resources :admin_logs
map.root :controller => "main"
map.myprofile 'profile',
:controller => 'profiles',
:action => 'show'
map.userji 'users/:username',
:controller => 'users',
:action => 'show'
map.signup 'signup',
:controll... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
module CodeRepliesHelper
end
| Ruby |
module Authentication
# vrne TRUE, ce je se ujema id in id sranjen v session
# vhod: id... id reference objave, session... teh session :)
def isCurrentUserAuthor(id, session)
unless session == nil
puts "session not null"
puts id==session.to_s
return id == session # TODO: if admin naj bo tudi true
end
... | Ruby |
module UsersHelper
#def loggedIn(id)
# return id == session[:user_id]
#end
end
| Ruby |
module ProgramLanguagesHelper
end
| Ruby |
module MainHelper
end
| Ruby |
module SessionsHelper
end
| Ruby |
module CategoriesHelper
end
| Ruby |
module CodeListHelper
end
| Ruby |
module SubcategoriesHelper
end
| Ruby |
module HelpHelper
end
| Ruby |
module CodesHelper
### NOTE!
# Next five methods are deprecated, moved to code model.
# Aljosa 5.4.10
###
# Returns author's name as string
# Input: code class
# Output: name
# def authorName(thisCode)
# return User.find(thisCode.user_id).username
# end
# Returns programLanguage as string
# In... | Ruby |
# These helper methods can be called in your template to set variables to be used in the layout
# This module should be included in all views globally,
# to do so you may need to add this line to your ApplicationController
# helper :layout
module LayoutHelper
def title(page_title, show_title = true)
@content_fo... | Ruby |
module AdminLogsHelper
end
| Ruby |
module TypesHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module ProfilesHelper
end
| Ruby |
module GradesHelper
end
| Ruby |
class Category < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
################################################
# return all root categories
# (at the moment, all categories are root cat.)
# order them by name
################################################
def self.find_root_... | Ruby |
# Last edit by Aljosa Apr 26 10
class Grade < ActiveRecord::Base
# relationships
belongs_to :user
belongs_to :code
# presence validation
validates_presence_of :user_id
validates_presence_of :code_id
validates_presence_of :value
#validates_presence_of :id
# uniquness validation
validates_uniquene... | Ruby |
class Code < ActiveRecord::Base
validates_presence_of :code_body
validates_presence_of :title
validates_length_of :title, :maximum=>40
validates_presence_of :description
validates_presence_of :shortdescription
validates_length_of :shortdescription, :maximum=>200, :message=>": Maximum 200 character allowed"
... | Ruby |
class AdminLog < ActiveRecord::Base
def log(id, controller, action)
@admin_log = self.new(id, :controller => controller, :action => action)
@admin_log.save
end
end
| Ruby |
class Subcategory < ActiveRecord::Base
belongs_to :category
validates_presence_of :child_id
validates_presence_of :category_id
end
| Ruby |
class User < ActiveRecord::Base
# new columns need to be added here to be writable through mass assignment
attr_accessible :username, :email, :password, :password_confirmation
attr_accessor :password
before_save :prepare_password
validates_presence_of :username
validates_uniqueness_of :username, :emai... | Ruby |
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :code
validates_presence_of :user_id
validates_presence_of :code_id
validates_presence_of :content
validates_length_of :content, :within => 2..100
##########################################
# Obj's name getter methods
# Aljosa 11.4.1... | Ruby |
# Last edit by Aljosa Apr 26 10
class Profile < ActiveRecord::Base
# attachment_fu stuff, for saving the image
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 100.kilobytes,
:resize_to => '100x100>',
:thumbnails => { :th... | Ruby |
# Last edit by Aljosa Apr 26 10
class Type < ActiveRecord::Base
# relationships
belongs_to :code
# presence validation
validates_presence_of :name
# uniquness validation
validates_uniqueness_of :id
end
| Ruby |
# Last edit by Aljosa Apr 26 10
class ProgramLanguage < ActiveRecord::Base
# relationships
belongs_to :code
# presence validation
validates_presence_of :language_name
# uniquness validation
validates_uniqueness_of :id
# other stuff
validates_length_of :language_name, :maximum=>50, :message=>": Wtf? Langua... | Ruby |
class Upload < ActiveRecord::Base
###
before_create :set_filename
after_create :store_file
after_destroy :delete_file
# restrictions
validates_presence_of :uploaded_file
attr_accessor :uploaded_file
def link
"/uploads/#{CGI.escape(filename)}"
end
###
private
def store_file
File.open(file_storage_lo... | Ruby |
class CodeReply < ActiveRecord::Base
belongs_to :code
validates_presence_of :child_id
validates_presence_of :code_id
end
| Ruby |
class HelpController < ApplicationController
layout :default.to_s
end
| Ruby |
class TypesController < ApplicationController
# GET /types
# GET /types.xml
before_filter :authorize
layout :default.to_s
def index
@types = Type.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @types }
end
end
# GET /types/1
# GET /types/1.... | Ruby |
class GradesController < ApplicationController
# GET /grades
# GET /grades.xml
before_filter :authorize # Only admin group can manually edit grades!
layout :default.to_s
def index
@grades = Grade.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @grade... | Ruby |
class SubcategoriesController < ApplicationController
# GET /subcategories
# GET /subcategories.xml
before_filter :authorize # Only admin can manually edit categories!
layout :default.to_s
def index
@subcategories = Subcategory.all
respond_to do |format|
format.html # index.html.erb
for... | Ruby |
class CommentsController < ApplicationController
# GET /comments
# GET /comments.xml
layout :default.to_s
# Action filter
before_filter :authorize, :except => [:new, :create] #:only => [:edit, :update, :destroy, :show] # For editing you must be authorised
before_filter :loggedin, :only => [:new, :create] #... | Ruby |
class SessionsController < ApplicationController
def create
user = User.authenticate(params[:login], params[:password])
if user
session[:user_id] = user.id
flash[:notice] = "Logged in successfully."
#redirect_to_target_or_default(:back)
session[:username] = user.username
redir... | Ruby |
class ProfilesController < ApplicationController
# GET /profiles
# GET /profiles.xml
layout :default.to_s
#before_filter :authorize
def index
@profiles = Profile.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @profiles }
end
end
# GET /... | Ruby |
class MainController < ApplicationController
layout :default.to_s
def index
@top_5 = Code.find(:all, :order => "popularity DESC", :limit => 5)
@top_5_comments = Comment.find(:all, :order => "updated_at DESC", :limit => 5)
end
end
| Ruby |
class CategoriesController < ApplicationController
# GET /categories
# GET /categories.xml
layout :default.to_s
before_filter :authorize # Only admin can manually edit categories!
def index
@categories = Category.all
respond_to do |format|
format.html # index.html.erb
format.xml { rend... | Ruby |
class ProgramLanguagesController < ApplicationController
# GET /program_languages
# GET /program_languages.xml
before_filter :authorize
layout :default.to_s
def index
@program_languages = ProgramLanguage.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => ... | 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
include Authentication
helper :all # include all helpers, all the time
#protect_from_forgery # See ActionCo... | Ruby |
class CodeRepliesController < ApplicationController
# Action filter
before_filter :authorize, :except => [:new, :create] #:only => [:edit, :update, :destroy, :show] # For editing you must be authorised
before_filter :loggedin, :only => [:new, :create] # In order to add codereply you must be logged in
# GET /c... | Ruby |
class CodesController < ApplicationController
before_filter :loggedin, :only => [:create_comment, :createGrade, :gradeChange] # In order to add codereply you must be logged in
before_filter :onlyAuthor, :only => [:show, :edit, :destroy]
# GET /codes
# GET /codes.xml
layout :default.to_s
def index
if... | Ruby |
class CodeListController < ApplicationController
def index
#@codes = Code.find_group_codes
@categories = Category.find_root_categories
end
def show
@code = Code.find(params[:id])
@comments = @code.getComments
@comment = Comment.new
@comment.user_id = session[:user_id]
@comment.code_id = Code.find... | Ruby |
class UsersController < ApplicationController
layout :default.to_s
def new
if !params[:user].nil?
@user = User.new(params[:user])
@user.group = 0 # set group to default
if @user.save then
#session[:user_id] = @user.id
Profile.create(:user_id => @user.id, :emai... | Ruby |
class AdminLogsController < ApplicationController
# GET /admin_logs
# GET /admin_logs.xml
before_filter :authorize
layout :default.to_s
def index
@admin_logs = AdminLog.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @admin_logs }
end
end
# GE... | 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'
require 'thi... | Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
| Ruby |
class CreateTypes < ActiveRecord::Migration
def self.up
create_table :types do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :types
end
end
| Ruby |
class AddImgAttribToProfile < ActiveRecord::Migration
def self.up
add_column :profiles, :filename, :string # Original filename
add_column :profiles, :thumbnail, :string # Mime type
add_column :profiles, :size, :integer # File size in bytes
end
def self.down
remove_column :profiles, :filename
... | Ruby |
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :categories
end
end
| Ruby |
class AddPrivateToCode < ActiveRecord::Migration
def self.up
add_column :codes, :private, :boolean
end
def self.down
remove_column :codes, :private
end
end
| Ruby |
class AddAidToAdminLog < ActiveRecord::Migration
def self.up
add_column :admin_logs, :aid, :integer
end
def self.down
remove_column :admin_logs, :aid
end
end
| Ruby |
class CreateProfiles < ActiveRecord::Migration
def self.up
create_table :profiles do |t|
t.string :email
t.string :IM
t.string :company
t.text :portfolio
t.string :webpage
t.string :avatar
t.references :user
t.timestamps
end
end
def self.down
drop_tabl... | Ruby |
class AddPopularityToCodes < ActiveRecord::Migration
def self.up
add_column :codes, :popularity, :float
end
def self.down
remove_column :codes, :popularity
end
end
| Ruby |
class CreateProgramLanguages < ActiveRecord::Migration
def self.up
create_table :program_languages do |t|
t.string :language_name
t.text :reservered_words
t.timestamps
end
end
def self.down
drop_table :program_languages
end
end
| Ruby |
class AddGroupToUser < ActiveRecord::Migration
def self.up
add_column :users, :group, :integer
end
def self.down
remove_column :users, :group
end
end
| Ruby |
class CreateCodeReplies < ActiveRecord::Migration
def self.up
create_table :code_replies do |t|
t.integer :child_id
t.references :code
t.timestamps
end
end
def self.down
drop_table :code_replies
end
end
| Ruby |
class AddListingToProfile < ActiveRecord::Migration
def self.up
add_column :profiles, :listing, :integer
end
def self.down
remove_column :profiles, :listing
end
end
| Ruby |
class AddViewsToCode < ActiveRecord::Migration
def self.up
add_column :codes, :views, :integer
end
def self.down
remove_column :codes, :views
end
end
| Ruby |
class CreateGrades < ActiveRecord::Migration
def self.up
create_table :grades do |t|
t.decimal :value
t.references :user
t.references :code
t.timestamps
end
end
def self.down
drop_table :grades
end
end
| Ruby |
class CreateSubcategories < ActiveRecord::Migration
def self.up
create_table :subcategories do |t|
t.integer :child_id
t.references :category
t.timestamps
end
end
def self.down
drop_table :subcategories
end
end
| Ruby |
class CreateCodes < ActiveRecord::Migration
def self.up
create_table :codes do |t|
t.string :title
t.text :code_body
t.string :tag
t.text :description
t.text :shortdescription
t.references :user
t.references :program_language
t.references :category
t.reference... | Ruby |
class CreateAdminLogs < ActiveRecord::Migration
def self.up
create_table :admin_logs do |t|
t.int :user_id
t.string :controller
t.string :action
t.timestamps
end
end
def self.down
drop_table :admin_logs
end
end
| Ruby |
class AddSyntaxTagToProgramLanguage < ActiveRecord::Migration
def self.up
add_column :program_languages, :syntax_tag, :string
end
def self.down
remove_column :program_languages, :syntax_tag
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.text :content
t.references :user
t.references :code
t.timestamps
end
end
def self.down
drop_table :comments
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :email
t.string :password_hash
t.string :password_salt
t.timestamps
end
end
def self.down
drop_table :users
end
end
| 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' }])
# Major.create(:name... | Ruby |
# This module is included in your application controller which makes
# several methods available to all controllers and views. Here's a
# common example you might add to your application layout file.
#
# <% if logged_in? %>
# Welcome <%=h current_user.username %>! Not you?
# <%= link_to "Log out", logout_pat... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::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 da... | Ruby |
require "rexml/document"
require "rexml/xpath"
require "test/unit"
class CSProj
attr_reader :basedir, :xml
@@target_ext = { "exe" => ".exe", "library" => ".dll" }
def initialize(basedir, xml)
@basedir = basedir
@xml = xml
end
def CSProj.parse(basedir, input)
CSProj.new basedir, REXML::Do... | Ruby |
environment = :production
project_type = :stand_alone
http_path = "/"
css_dir = "../styles"
sass_dir = "."
images_dir = "images"
sass_options = {
:line_numbers => false,
:debug_info => false
}
# output_style = :compressed
# output_style = :compact
output_style = :expanded
| Ruby |
#
# jQuery File Tree Ruby Connector
#
# Version 1.01
#
# Erik Lax
# http://datahack.se
# 13 July 2008
#
# History
#
# 1.01 Initial Release
#
# Output a list of files for jQuery File Tree
#
#<settings>
#root = "/absolute/path/"
# or
root = File.expand_path(".")
#</settings>
#<code>
require "cgi"... | Ruby |
i = 0
if i == 0 then
p 'test'
end
unless i != 0 then
p 'test'
end
case i
when 0
p "test"
end
while i != 0 do
p 'test'
end
until i == 0 do
p 'test'
end
for y in [] do
p 'test'
end
loop do
p 'test'
end
loop {
p 'test'
}
[].each do |b|
p 'test'
end
[].each {... | Ruby |
i = 0
if i == 0 then end
unless i != 0 then end
case i
when 0
p "test"
end
while i != 0 do end
until i == 0 do end
for y in [] do end
loop do end
loop { }
[].each do |b| end
[].each { |b| }
lambda do |x| end
lambda { |x| }
i = 0
if i == 0 then
end
unless i != 0 then
end
case i
when... | Ruby |
class A
def a
end
end
module B
def b
end
end
class C
module CC
def cc
end
end
end
class << C
def c
end
end
class << C.new
def c2
end
end
c3 = C.new
class << c3
end
def z
end
| Ruby |
def prime_table(max)
result = Array.new(max + 1, true)
result[0] = result[1] = false
(2..Math::sqrt(max).ceil).each { |i|
next unless result[i]
(i*2).step(max, i) { |j|
result[j] = false
}
}
result
end
def prime_list(table)
result = []
table.each_with_index { |b, i|
result << i if b
... | Ruby |
i = 0
if i == 0 then end
unless i != 0 then end
case i
when 0
p "test"
end
while i != 0 do p "test" end
until i == 0 do p "test" end
for y in [] do p "test" end
loop do p "test" end
loop { p "test" }
[].each do |b| p "test" end
[].each { |b| p "test" }
lambda do |x| p "test" end
lambda { |x| p "t... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.