code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class CreatePageElements < ActiveRecord::Migration
def self.up
create_table :page_elements do |t|
t.column :page_id, :integer, :null => false
t.column :content_id, :integer, :null => false
t.column :area_name, :string
t.column :position, :integer
end
add_index :page_elements, :area... | 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 |
#!/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/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/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/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/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/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 |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def import_stylesheet (name)
"<style type='text/css'>\n@import url('"<< stylesheet_path(name)<< "');\n</style>"
end
end
| Ruby |
module ContentsHelper
def live_search
page<<( remote_function :url => { :action => :live_search },:with => "searchtext")
end
end
| Ruby |
module RenderHelper
end
| Ruby |
module PagesHelper
def if_ie_tag (content)
"\n<!--[if IE]>\n"+content+"\n<![endif]-->\n"
end
end
| Ruby |
class Content < ActiveRecord::Base
has_many :meta_datas
has_many :page_elements, :dependent => :destroy
has_many :pages, :through => :page_elements
def body_to_html
case content_type
when "text/textile"
if body.blank?
""
else
textilized = RedCloth.new(body)#, ... | Ruby |
class PageElement < ActiveRecord::Base
belongs_to :page
belongs_to :content
# acts_as_list :scope => "area_name = '#{area_name}'"
end
| Ruby |
class GlobalSettings < ActiveRecord::Base
def GlobalSettings.[](key_name)
find_or_create_by_key key_name.to_s
end
def self.site_name
find_or_create_by_key('site_name').value
end
def self.site_name=(new_value)
find_or_create_by_key('site_name').update_attribute :value, new_value
end
e... | Ruby |
class MetaData < ActiveRecord::Base
belongs_to :content
end
| Ruby |
class Page < ActiveRecord::Base
attr_reader :page_html
has_many :page_elements, :include=>:content, :order=>"area_name, position ASC" do
def of_area (area_name)
find_all "area_name = '#{area_name}'"
end
end
# returns an array of strings with all the area_names associated to the elements of this pa... | Ruby |
class PagesController < ApplicationController
layout "pages", :except => :edit
# scaffold :page, :suffix => true
# scaffold :content, :suffix => true
def set_global_settings_site_name
begin
@setting = GlobalSettings[:site_name]
@setting.value = params[:global_settings][:site_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.
class ApplicationController < ActionController::Base
end | Ruby |
require 'render_engine'
class RenderController < ApplicationController
layout false
# ecco pronta la regex per beccare i segnalatori dei template: %%[a-z_]+:[a-z_]*(:[a-z_]+)?%%
def index
show
end
def show
# show page with :url_name
if params[:urlname]
@page = Page.find_by_urlname params... | Ruby |
class ContentsController < ApplicationController
def write_now
@page = Page.find(params[:id])
render :update do |page|
page << "goToMenu('write_content_menu');"
page.replace_html "widgets", :partial => "write_now"
# page.insert_html :bottom, "page_actions", :partial => "write_now"
end
... | Ruby |
ActionController::Routing::Routes.draw do |map|
UJS::routes
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controll... | 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 |
# 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 |
# 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 |
# vim:ts=4:sw=4:
# = RedCloth - Textile and Markdown Hybrid for Ruby
#
# Homepage:: http://whytheluckystiff.net/ruby/redcloth/
# Author:: why the lucky stiff (http://whytheluckystiff.net/)
# Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.)
# License:: BSD
#
... | Ruby |
require 'rake/gempackagetask'
PKG_VERSION = "0.4.0"
PKG_NAME = "compages"
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
spec = Gem::Specification.new do |s|
s.name = PKG_NAME
s.version = PKG_VERSION
s.summary = "a small and lean content management & publishing system"
s.description = %{Here are the m... | Ruby |
require_dependency "page"
module RenderEngine
protected
#
def render_meta_tags( template_code )
meta_tag_pattern = /%%content:([a-z]+)%%/
template_code.gsub( meta_tag_pattern ) { || @content.meta_tags.find_by_key $1 }
end
# overwrite this if you want to restrict access to on... | 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 TokenPosition
attr_reader :line, :position
def initialize(line,position)
@line = line
@position = position
end
def to_s
"linha #{@line}, posicao #{@position}"
end
end
| Ruby |
class Grammar
def initialize(tokens)
@index = 0
@tokens = tokens
# :declara[ors][nterm]
@grammar = {
:programa => [ [:declara, :rotina, /^begin$/, :sentencas, /^end$/] ] ,
:declara => [ [ :tipo_var, :variaveis, ';', :declara] , [:epson] ],
... | Ruby |
$LINE_SEPARATOR = "\n"
class LexicalAnalyzer
attr_reader :tokens,:buffer
def initialize(file_path,errors)
@errors = errors
@file_path = file_path
@line_counter = 0
@char_counter = 0
@file = File.new file_path,"r"
@buffer = []
@tokens = []
@file.ea... | Ruby |
class SyntaxAnalyzer
def initialize(tokens)
end
end | Ruby |
class UI
def UI.log(message)
print message,$LINE_SEPARATOR
end
end
| Ruby |
class Token
attr_reader :token, :klass, :position
def initialize(token,klass,position=nil)
@token = token
@klass = klass
@position = position
end
def line
@position.line if @position
end
def nchar
@position.position if @position
end
def to_s
return "<#{@klass},#{@tok... | Ruby |
#!/usr/bin/ruby
require 'compiler/ui'
require 'compiler/token_position'
require 'compiler/token'
require 'compiler/lexical_analyzer'
require 'getoptlong'
def usage
UI.log "Usage: ruby pamc.rb [OPTIONS] FILE"
end
$params = { :ignore_lexical_error => false }
opts=GetoptLong.new(
['-I', GetoptLong::NO_ARGUMENT]
)
... | Ruby |
#!/usr/bin/ruby
require 'compiler/ui'
require 'compiler/token_position'
require 'compiler/token'
require 'compiler/lexical_analyzer'
require 'getoptlong'
def usage
UI.log "Usage: ruby pamc.rb [OPTIONS] FILE"
end
$params = { :ignore_lexical_error => false }
opts=GetoptLong.new(
['-I', GetoptLong::NO_ARGUMENT]
)
... | Ruby |
require 'compiler/ui'
require 'compiler/token'
require 'compiler/lexical_analyzer'
begin
la = LexicalAnalyzer.new(ARGV[0])
la.run
la.dump
rescue
UI.log $!
end
| Ruby |
def main()
a = 3
b = 2.5
a = b
print a
end
self.main() | Ruby |
x = 0.3
y = 5
z = 5.3
t = (x + y) * z + (y - z)/x
k = t + 0.0
return k | Ruby |
x = 1 + 2
y = x + 0.0
return y | Ruby |
x = y | Ruby |
x = 2
x = x + 1.3 | Ruby |
k = 1.0
if 2 < 3 then
k = 2.5
k = k * 2
else
k = 5.6
k = k - 3
end
return k | Ruby |
x = f(4) | Ruby |
x = 1.0
y = 5.0
z = x + y
return z | Ruby |
x = 0.2
y = 6
z = 5.9
t = (x + y) + z + (z + x)
return t | Ruby |
x = 0.2
y = 2
z = x * y
return z | Ruby |
i = 0.0
while i < 5.0 do
i = i + 1.0
end
return i | Ruby |
x = 1 * 2
y = x + 0.0
return y
| Ruby |
x = 2
y = x(2) | Ruby |
x = 1
x = 2.0 | Ruby |
k = 1.0
if 2 < 3 then
k = 2.5
end
return k | Ruby |
def f(a)
i = 0.0
while i < 5.0 do
i = i + 1.0 + a
end
return i
end
x = f(1.0)
return x | Ruby |
k = 1.0
if 2 > 3 then
k = 2.5
end
return k | Ruby |
CST = 2
CST = 5 | Ruby |
def f(a)
a = a + 1
return a
end
x = f(1.0)
return x | Ruby |
require 'rake'
require 'yaml'
module PhpThumbHelper
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
SRC_DIR = File.join(ROOT_DIR, 'src')
DOCS_DIR = File.join(ROOT_DIR, 'apidocs')
VERSION = YAML.load(IO.read(File.join(ROOT_DIR, 'config.yml')))['CURRENT_VERSION'].gsub(' ', '-').d... | 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 |
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 |
class Mutador
attr_accessor :operacao #proc
def muta(solucao)
@operacao.call(solucao) unless @operacao.nil?
end
end
| Ruby |
require 'gnuplot'
class F6
def initialize(inicio, fim)
@inicio = inicio
@fim = fim
end
def calcula(x)
sum = 0
(1..10).each do |e|
sum += (-1)*(x+e)*Math.sin(Math.sqrt((x+e).abs))
end
(10 * 4189.8291)+ sum
end
def valores_range
@arr = []
(@inicio..@fim).each do |v|
@arr << self.calcula(... | Ruby |
class Solucao
attr_accessor :valor
attr_reader :limite_inferior, :limite_superior
def initialize(valor, limite_inferior, limite_superior)
@valor = valor
@limite_inferior = limite_inferior
@limite_superior = limite_superior
end
end
| Ruby |
require "SolucaoFactory"
require "Mutador"
require "Cruzador"
factory = SolucaoFactory.new 100, -512, 512
populacao = factory.gerar_populacao
populacao.each do |e|
#p e.valor
end
m = Mutador.new
operacao = Proc.new { |e|
aux = e.valor ^ (2 ** (rand * 12))
while(aux < e.limite_inferior or aux > e.limite_superior)
... | Ruby |
require 'gnuplot'
class F8
def initialize(inicio, fim)
@inicio = inicio
@fim = fim
end
def calcula(x)
sum = 0
(1..10).each do |e|
sum += (((x+e) ** 2)/4000)
end
prod = 1
(1..10).each do |v|
prod = prod * Math.cos((x+v)/(Math.sqrt(v)))
end
(1 + sum - prod)
end
def valores_range
... | Ruby |
require "Solucao"
class Cruzador
attr_accessor :oper_cross
def crossover sol1, sol2
@oper_cross.call(sol1, sol2) unless @oper_cross.nil?
end
end
| Ruby |
require 'Solucao'
require 'F6.rb'
require 'SolucaoFactory'
class Seletor
def initialize funcao, quantidade
@funcao = funcao
@quantidade = quantidade
end
def seleciona pop
pop = pop.sort_by do |v|
@funcao.calcula(v.valor)
end
pop.reverse!
return pop[0..(@quantidade-1)]
end
end
=begin
facto... | Ruby |
require "libglade2"
require "SolucaoFactory"
require "Mutador"
require "Cruzador"
require 'F6'
require 'F8'
require 'Seletor'
class Window
@populacao
@mutador
@cruzador
@f
def AG
limite_superior = 0
limite_inferior = 0
if @funcao.active_text == "F6"
limite_superior = 500
limite_inferior = -500
... | Ruby |
require "Solucao"
class SolucaoFactory
attr_accessor :tamanho_populacao, :limite_inferior, :limite_superior
def initialize tamanho_populacao, limite_inferior, limite_superior
@tamanho_populacao = tamanho_populacao
@limite_inferior = limite_inferior
@limite_superior = limite_superior
end
def gerar_populaca... | Ruby |
class A
end
class B < A
def f
return x
end
def g(a, b, c)
return a + b + c
end
end
a = b.f
a = b.f()
a = b.g(1, 2, 3)
if x < y then
x = 2
end
if x == y then
x = x + x
else
y = 5
end
for i in 1 .. 10 do
x = x + 1
end
while x >= y do
y = y + 1
end | Ruby |
a = 1
while a <= 10 do
print(a) = 0
a = a + 1
end | Ruby |
for a in 1 .. 10 do
print(a) = 0
end | Ruby |
a = 1
b = 2
if a < b then
c = a
if c == a then
c = a + 1
end
if a >= c then
a = c - 1
else
a = c + 1
if b < c then
b = c
print(c) = 0
end
end
else
c = b
end
if c == a then
b = c
print(b) = 0
end
print(a) = 0
print(b) = 0
print(c) = 0 | Ruby |
a = 10
print(a) = 0
b = 1.5
print(b) = 0
c = "test"
D = 2
print(D) = 0
e = -5
print(e) = 0
f = 2.5 * a + b * (D * 2 + 1) + e
print(f) = 0
| Ruby |
for a in 1. .. 100. do
b = a
bool = 1
for c in 2. .. (b / 2.) do
d = a / c
while d > 0. do
d = d - 1.
end
if d == 0. then
bool = 0
end
end
if bool == 1 then
print(a) = 0
end
end | Ruby |
a = 1
b = a
c = a + b
d = c + 2
return d
| Ruby |
def f(a,b)
c = a+b
return c
end
x = f(1.0, 3.0)
return x
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.