code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
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 SessionsHelper
end | Ruby |
module HomeHelper
end
| Ruby |
module MoviesHelper
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 Movie < ActiveRecord::Base
validates_presence_of :title, :description
validates_uniqueness_of :title
validates_length_of :description, :minimum => 10
validates_inclusion_of :rating, :in => %w{ G PG PG-13 R NC-17 }
def self.find_all_appropriate_for_birthdate(birthdate)
movies = Movie.find(:a... | Ruby |
class HomeController < ApplicationController
before_filter :login_required
def dashboard
@movies = Movie.find_all_appropriate_for_birthdate(current_user.birthdate)
end
end
| Ruby |
class MoviesController < ApplicationController
before_filter :login_required, :except => [ :index, :show ]
# GET /movies
# GET /movies.xml
def index
@movies = Movie.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @movies }
end
end
# GET /movies... | 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 attacks... | 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 AuthenticatedSystem
helper :all # include all helpers, all the time
protect_from_forgery # See A... | 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 request... | 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/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/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'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about' | Ruby |
#!/usr/bin/env ruby
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/enviro... | Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
puts "Loading Rails environment"
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
require 'optparse'
require 'spec/rails/spec_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/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/console'
| Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
puts "Loading Rails environment"
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
require 'optparse'
require 'spec/rails/spec_server'
| 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
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | 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/plugin'
| Ruby |
#!/usr/bin/env ruby
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/enviro... | 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 CreateMovies < ActiveRecord::Migration
def self.up
create_table :movies do |t|
t.string :title
t.text :description
t.string :rating
t.datetime :released_on
t.timestamps
end
end
def self.down
drop_table :movies
end
end
| Ruby |
class AddBirthdates < ActiveRecord::Migration
def self.up
add_column :users, :birthdate, :datetime
end
def self.down
remove_column :users, :birthdate
end
end
| Ruby |
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
require 'spec/autorun'
require 'spec/rails'
# Requires supporting files with custom matchers and... | 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 |
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
rspec_gem_dir = nil
Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
end
rspec_plugin_dir = File.expand_path(Fil... | 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 |
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 'rubygems'
require 'rake/gempackagetask'
PKG_NAME = 'activecouch'
PKG_VERSION = File.read('VERSION').chomp
PKG_FILES = FileList[
'[A-Z]*',
'lib/**/*.rb',
'spec/**/*.rb'
]
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "Ruby-based wrapper for CouchDB"
s.name = 'ac... | Ruby |
begin
require 'spec'
rescue LoadError
require 'rubygems'
gem 'rspec'
require 'spec'
end
require File.dirname(__FILE__) + "/../lib/active_couch"
| Ruby |
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require 'rubygems'
require 'json'
require 'active_couch/attribute'
require 'active_couch/associations'
require 'active_couch/support'
require 'active_couch/errors'
require 'active_c... | Ruby |
module ActiveCouch
# Base exception class for all ActiveCouch errors.
class ActiveCouchError < StandardError
end
# Raised when there is a configuration error (duh).
class ConfigurationError < ActiveCouchError
end
# Raised when trying to assign a object of an invalid type as an ActiveCouch attribute.
c... | Ruby |
module ActiveCouch
module Callbacks
CALLBACKS = %w(before_save after_save before_delete after_delete)
def self.included(base)
# Alias methods which will have callbacks, (for now only save and delete).
# This creates 2 pairs of methods: save_with_callbacks, save_without_callbacks,
# dele... | Ruby |
# TODO Consider implementing Enumerable semantics.
module ActiveCouch
class HasManyAssociation
attr_accessor :name, :klass, :container
def initialize(name, options = {})
@name, @container, klass = name.to_s, [], options[:class]
if !klass.nil? && klass.is_a?(Class)
@klass = klass
... | Ruby |
Inflector.inflections do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/s$/i, 's')
inflect.plural(/(ax|test)is$/i, '\1es')
inflect.plural(/(octop|vir)us$/i, '\1i')
inflect.plural(/(alias|status)$/i, '\1es')
inflect.plural(/(bu)s$/i, '\1ses')
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
inflect.plura... | Ruby |
module ActiveCouch
Symbol.class_eval do
def singularize; Inflector.singularize(self); end
end
String.class_eval do
require 'cgi'
def url_encode; CGI.escape("\"#{self.to_s}\""); end
# Delegate to Inflector
def singularize; Inflector.singularize(self); end
def demodulize; Inflector.demodul... | Ruby |
# This file is copied from the ActiveSupport project, which
# is a part of the Ruby On Rails web-framework (http://rubyonrails.org).
require 'singleton'
# The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
# and class names to foreign keys. The ... | Ruby |
require 'active_couch/migrations/errors.rb'
require 'active_couch/migrations/migration.rb'
require 'active_couch/migrations/migrator.rb' | Ruby |
require 'active_couch/associations/has_many_association' | Ruby |
module ActiveCouch
class MigrationError < StandardError; end
class InvalidFilter < MigrationError; end
end | Ruby |
# TODO
# - might consider moving create_database and delete_database to an adapter type class to encapsulate CouchDB semantics
# and responses.
module ActiveCouch
class Migrator
class << self # Class methods
def migrate(site, migration)
if migration.view.nil? || migration.database.nil?
r... | Ruby |
require 'json'
module ActiveCouch
class Migration
class << self # Class Methods
# Class instance variables
@view = nil; @database = nil
# These are accessible only at class-scope
attr_accessor :view, :database
# Set the view name and database name in the define method and then exe... | Ruby |
module ActiveCouch
class Attribute
attr_reader :name, :klass, :value
TYPES = {:decimal => Float, :text => String, :number => Integer}
DEFAULTS = {:decimal => 0.0, :text => "", :number => 0}
def initialize(name, options = {})
klass, value = String, ""
# Check for types supported
... | Ruby |
require 'active_couch/support/inflector'
require 'active_couch/support/extensions' | Ruby |
# Connection class borrowed from ActiveResource
require 'net/https'
require 'date'
require 'time'
require 'uri'
require 'benchmark'
module ActiveCouch
class ConnectionError < StandardError # :nodoc:
attr_reader :response
def initialize(response, message = nil)
@response = response
@message = me... | Ruby |
# Used for marshaling and unmarshaling
require 'zlib'
module ActiveCouch
class Base
SPECIAL_MEMBERS = %w(attributes associations connection callbacks)
DEFAULT_ATTRIBUTES = %w(id rev)
# Initializes an ActiveCouch::Base object. The constructor accepts both a hash, as well as
# a block to initial... | Ruby |
# put your whitelist file in RAILS_ROOT/config/whitelists/development.txt, substituting 'development'
# with whatever your environment is
whitelist_file = File.join(RAILS_ROOT, "config", "whitelists", "#{ENV['RAILS_ENV']}.txt")
if File.exist?(whitelist_file)
require File.join(File.dirname(__FILE__), *%w[lib allowed_... | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the finder_cache plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the finder_cache plug... | Ruby |
# desc "Explaining what the task does"
# task :finder_cache do
# # Task goes here
# end | Ruby |
module ActionMailer
class Base
def create_mail_with_whitelist
recipients whitelist_filter(recipients)
cc whitelist_filter(cc)
bcc whitelist_filter(bcc)
create_mail_without_whitelist
end
alias_method_chain :create_mail, :whitelist
def whitelist_filter(addresses)
... | Ruby |
module EmailWhitelist
class AllowedEmail
class << self
def use_file(file)
raise "File not found: #{file}" unless File.exists?(file)
@whitelist_file = file
@email_addresses = []
File.open(@whitelist_file, 'r') do |f|
f.each do |line|
# skip blank lines an... | Ruby |
ActiveRecord::Schema.define(:version => 1) do
create_table :allowed_emails do |t|
t.column :email, :string
end
end | Ruby |
# Include this file in your test by copying the following line to your test:
# require File.expand_path(File.dirname(__FILE__) + "/test_helper")
$:.unshift(File.dirname(__FILE__) + '/../lib')
RAILS_ROOT = File.dirname(__FILE__)
require 'rubygems'
require 'test/unit'
require 'active_record'
require 'action_mailer'
r... | Ruby |
require 'sinatra/activerecord/rake'
require './main' | 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 |
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 |
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 |
def grid(cols, rows, colsize = 1, rowsize = 1, &block)
block = Proc.new {|*args| args} unless block
(0 ... cols * rows).map do |i|
x = colsize * (i % cols)
y = rowsize * i.div(cols)
block.call(x, y)
end
end
Array.module_eval do
def choice
self[rand(length)]
end
end
class Motion
require ... | Ruby |
module Control
require 'java'
require 'rplib.jar'
include_class 'processing.core.PApplet'
include_class 'IPAppletAdapter'
include_class 'java.awt.Insets'
include_package 'javax.swing'
GridBagLayout = java.awt.GridBagLayout
GridBagConstraints = java.awt.GridBagConstraints
class ActionListener
d... | Ruby |
def setup
size screen.width, screen.height, OPENGL
noStroke
end
def draw
lights
background 0
w, h = ceil(width/100.0), ceil(height/100.0)
grid(w, h, 100, 100) do |x, y|
pushMatrix
translate x+50, y+50
rotateY map(mouseX, 0, width, 0, PI)
rotateX map(mouseY, 0, height, 0, PI)
box 9... | Ruby |
include_package 'processing.pdf'
def setup
size 594, 842
@pdf = beginRecord PDF, "RandomBook.pdf"
beginRecord @pdf
end
def draw
background 255
100.times do |i|
if random(1.0) < 0.2
stroke 255
else
stroke 0
end
sw = pow random(1.0), 12
strokeWeight sw * 260
x1 = random ... | Ruby |
require 'control.rb'
include Control
def setup
size 200, 200
smooth
noStroke
fill 0
slider :radius, 100, 0, 200
text_field :msg, 'hello'
button :click
check_box :visible, true
end
def draw
background 255
ellipse 100, 100, radius, radius if visible
end ... | Ruby |
def setup
size 500, 500, OPENGL
@c = 0
@tc = 0
@m = Motion.new do |m|
@c += (@tc - @c) * 0.1
background @c, 0, 0
m.stop if abs(@tc - @c) < 0.1
end
end
def mousePressed
@tc = 255
@m.start
end
def mouseReleased
@tc = 0
@m.start
end | Ruby |
def setup
size 200, 200
background 0
angle = 0
px, py = 0, 0
amplitude = 30
frequency = 0
fill_gap = 3
-75.upto height+75 do |i|
angle = 0
frequency += 0.006
(width+75).times do |j|
py = i + sin(radians(angle)) * amplitude
angle += frequency
r = abs(py - i) * 255 / ampli... | Ruby |
def setup
size 200, 200
noStroke
a = color 165, 167, 20
b = color 77, 86, 59
c = color 42, 106, 105
d = color 165, 89, 20
e = color 146, 150, 127
draw_band [a, b, c, d, e], 4
translate 0, 0.5 * height
draw_band [c, a, d, b, e], 4
end
def draw_band(colors, bar_width)
x = 0
while x < width
co... | Ruby |
def setup
size 200, 200
noStroke
colorMode HSB, 360, height, height
@bar_width = 5
end
def draw
x = @bar_width * mouseX.div(@bar_width)
fill x, height, mouseY
rect x, 0, @bar_width, height
end | Ruby |
def setup
size 200, 200
background 0
noFill
smooth
ellipseMode CENTER_RADIUS
cols = 4
radius = width / cols / 2
grid cols, cols, radius * 2, radius * 2 do |x, y|
x += radius
y += radius
create_gradient x, y, radius, rand_color, rand_color
end
end
def rand_color
color rand_bright, ran... | Ruby |
X_AXIS, Y_AXIS = 1, 2
def setup
size 200, 200
b1 = color 190, 190, 190
b2 = color 20, 20, 20
c1 = color 255, 120, 0
c2 = color 10, 45, 255
c3 = color 10, 255, 15
c4 = color 125, 2, 140
c5 = color 255, 255, 0
c6 = color 25, 255, 200
[
[0, 0, width, height, b1, b2, Y_AXIS],
[25, 25, 75,... | Ruby |
def setup
size 500, 500
noStroke
colorMode HSB, 360, height, height
@bar_width = 5
end
def draw
x = @bar_width * mouseX.div(@bar_width)
fill mouseY, height/1.2, height/1.2
rect x, 0, @bar_width, height
end | Ruby |
def setup
size 200, 200
noStroke
inside = color 204, 102, 0
middle = color 204, 153, 0
outside = color 153, 51, 0
fill outside
rect 0, 0, 200, 200
fill middle
rect 40, 60, 120, 120
fill inside
rect 60, 90, 80, 80
end | Ruby |
def setup
size 200, 200
noStroke
colorMode HSB, 360, height, height
@bar_width = 5
end
def draw
x = @bar_width * mouseX.div(@bar_width)
fill x, mouseY, height/1.5
rect x, 0, @bar_width, height
end | Ruby |
def setup
size 200, 200
noStroke
background 0
c = loadImage "cait.jpg"
xoff, yoff = 0, 0
p = 2
pix = p * 3
c.pixels.each do |here|
fill red(here), 0, 0
rect xoff, yoff, p, pix
fill 0, green(here), 0
rect xoff+p, yoff, p, pix
fill 0, 0, blue(here)
rect xoff+p*2, yoff,... | Ruby |
SEGS = 12
STEPS = 6
ROT_ADJUST = radians 180 / SEGS
INTERVAL = TWO_PI / SEGS
SHADE, TINT = 0, 1
def setup
size 200, 200
background 127
smooth
ellipseMode CENTER_RADIUS
noStroke
create_wheel width/2, height/2, SHADE
end
def create_wheel(x, y, value_shift)
radius = 95
seg_width = radius / STEPS
draw_p... | Ruby |
def setup
size 200, 200
background 0
fill 255
fontA = loadFont "CourierNew36.vlw"
textFont fontA, 36
textAlign CENTER
margin = 6
gap = 30
translate margin * 1.5, margin * 2
grid margin, margin do |x, y|
i = y * margin + x
if i <= 25
case letter = (65... | Ruby |
def setup
size 200, 200
coswave = (0 .. width).map do |i|
ratio = i.to_f / width
abs(cos(ratio*PI))
end
coswave.each_with_index do |v, i|
stroke v * 255
line i, 0, i, width / 3
end
coswave.each_with_index do |v, i|
stroke v * 255 / 4
line i, width / 3, i, width / 3 * 2
end... | Ruby |
def setup
size 200, 200
background 0
max_distance = dist width/2, height/2, width, height
grid width, height, 2, 2 do |x, y|
stroke(255 * dist(width/2, height/2, x, y) / max_distance)
point x, y
end
end | Ruby |
$unit = 40
def setup
size 200, 200
background 176
noStroke
@mods = []
grid(width/$unit, height/$unit, $unit, $unit) do |x, y|
m = Mod.new x, y, $unit/2, $unit/2, random(0.05, 0.8)
@mods.push m
end
end
def draw
@mods.each do |m|
m.update
m.draw(self)
end
end
class Mod
def initiali... | Ruby |
class IRP
require 'pathname'
require 'thread'
require 'yaml'
require 'java'
include_class 'java.awt.Frame'
include_class 'java.awt.Color'
include_class 'java.awt.FileDialog'
include_class 'java.awt.GraphicsEnvironment'
include_class 'java.awt.event.WindowAdapter'
include_class 'java.awt.event.KeyAda... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.