code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#!/usr/bin/env ruby
# == Synopsis
# The parser parses the XML files provided by the BlueObelisk Project and
# generates objects of the type ChemicalElement
# == Copyright
# Copyright (c) 2008 Carsten Niehaus <cniehaus at kde dot org>
# Licence GPLv3
require "rexml/document"
require "chemicalclasses"
# This class pa... | Ruby |
#!/usr/bin/env ruby
# == Synopsis
# This programm makes it possible to query the
# == Usage
# ruby query.eb [ -h | --help | -? ] [ -n elementnumber ]
#
# elementnumber::
# The +number+ of an element (eg '6' for Carbon)
#
# == Copyright
# Copyright (c) 2008 Carsten Niehaus <cniehaus at kde dot org>
# Licence GPLv3
re... | Ruby |
# example usage of one lua scriptlet inside a spec
# notice the most importat thing is the fact there's one bug in rpm or lua
# that forces me to not call "print" more than once, so I have to keep all
# lines in a table before dumping it
Name: bla
Version: 1.0
Release: 1
Group: Foo/bar
License: GPL
Summary: bli
Build... | 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 |
#!/usr/bin/env ruby
# encoding: utf-8
project = 'battery-indicator'
user = `cat ~/.netrc | awk '{print $4;}'`.strip
pass = `cat ~/.netrc | awk '{print $6;}'`.strip
version = `grep "android:versionName=" AndroidManifest.xml`.split('"')[1]
apk_location = "BatteryIndicatorPro-#{version}.apk"
system("cp bin/*-release.ap... | Ruby |
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
LANGS_URI = 'http://ath.darshancomputing.com/bi/langs/'
langs = Net::HTTP.get(URI.parse(LANGS_URI)).split()
langs.each do |lang|
if lang.length == 2
dir = 'res/values-' << lang
else
dir = 'res/values-' << lang[0,2] << '-r' << lang[2,2]
end
if ! D... | Ruby |
#!/usr/bin/env ruby
require 'nokogiri'
string_to_remove = ['pref_cat_themes',
'theme_settings',
'theme_settings_summary',
'theme_settings_help']
string_files = []
Dir.glob('res/values*').each do |d|
file = d << "/strings.xml"
string_files << file if Fil... | Ruby |
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
# read in convert.xml to see which how to convert the string-arrays
# for each strings.xml in res/values res/values-?? res/values-??-*
# find the string-arrays that match the ones in convert.xml and for each
# remove opening and closing string-array tag
#... | Ruby |
require 'RMagick'
class NumberImageGenerator
@@IMAGE_DIR = 'numbers-hdpi/'
def generate(text, fs=18)
#filename = "b" + sprintf("%03d", text) + ".png";
filename = "" + sprintf("%03d", text) + ".png";
font_size = fs;
height = 35;
width = 35;
image = Magick::Image.new(width, height) {self.ba... | Ruby |
# Include hook code here
require 'boling_for_batches' | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the boling_for_batches plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the boling_for_... | Ruby |
# desc "Explaining what the task does"
# task :boling_for_batches do
# # Task goes here
# end
| Ruby |
# Uninstall hook code here
| Ruby |
# Install hook code here
| Ruby |
# BolingForBatches
#Copyright ©2008 Peter H. Boling, released under the MIT license
#Plugin for Rails: A Better Way To Run Heavy Queries
#License: MIT License
#Labels: Ruby, Rails, Plugin
#Project owners:
# peter.boling
module BolingForBatches
class Batch
#We need to include this so we have access to the p... | Ruby |
# File boggle_solver.rb
require 'trie'
require 'set'
# The BoggleSolver class is used to solve Boggle boards. It has
# nested classes to represent individual letter blocks (e.g., "a" or
# "qu"), Boggle boards, and a class that can load in a dictionary and
# then solve multiple boards.
class BoggleSolver
# Repre... | Ruby |
# File trie.rb
# Implements the trie data structure.
class Trie
def initialize(level = 0)
@level = level
@hash = Hash.new
end
# Adds the string parameter to the trie.
def add(string)
letter = curr_letter(string)
if letter.nil?
@hash[letter] = string
else
trie = @hash[letter]... | Ruby |
#!/usr/bin/env ruby
# Represents and generates Boggle Boards. It randomly rolls simulated
# Boggle Dice and places them randomly in a 4x4 grid.
# Note: one die has the side 'QU'.
class BoardGenerator
BoggleDie = [
['F', 'O', 'R', 'I', 'X', 'B'],
['M', 'O', 'QU', 'A', 'B', 'J'],
... | Ruby |
#!/usr/bin/env ruby
# File boggle.rb
#require 'enumerator'
require 'pp'
require 'solver'
require 'board_generator'
# If there's a command-line argument use it as the Boggle board.
# Otherwise create a random Boggle board.
board_count = 1
board_count = ARGV[0].to_i if ARGV.size >= 1
config = ""
unless STDIN.tty... | 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 |
# 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 |
# Be sure to restart your server when you modify this file.
# 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.
ActiveReco... | 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 |
# Be sure to restart your server when you modify this file.
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Act... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying do debug a probl... | 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
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_reque... | 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
# 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 :order_items
map.resources :orders
map.resources :admins
map.resources :categories
map.resources :products
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'pr... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
module OrdersHelper
end
| Ruby |
module ProductsHelper
end
| Ruby |
module AdminsHelper
end
| Ruby |
module CategoriesHelper
end
| Ruby |
module OrderItemsHelper
end
| Ruby |
class Category < ActiveRecord::Base
has_many :products
validates_presence_of :name
validates_presence_of :description
end
| Ruby |
class Order < ActiveRecord::Base
end
| Ruby |
class OrderItem < ActiveRecord::Base
end
| Ruby |
class Admin < ActiveRecord::Base
validates_length_of :name, :within => 3..40
validates_length_of :password, :within => 5..40
validates_presence_of :name, :username, :email, :password, :password_confirmation
validates_format_of :email, :with => %r{^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-... | Ruby |
class Product < ActiveRecord::Base
belongs_to :category
validates_presence_of :name
validates_presence_of :description
validates_presence_of :category_id
validates_numericality_of :price, :greater_than => 0
end
| Ruby |
class ProductsController < ApplicationController
# GET /products
# GET /products.xml
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
# GET /products/1
# GET /products/1.xml
def show
@pro... | Ruby |
class AdminsController < ApplicationController
# GET /admins
# GET /admins.xml
def index
@admins = Admin.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @admins }
end
end
# GET /admins/1
# GET /admins/1.xml
def show
@admin = Admin.find(par... | Ruby |
class OrdersController < ApplicationController
# GET /orders
# GET /orders.xml
def index
@orders = Order.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @orders }
end
end
# GET /orders/1
# GET /orders/1.xml
def show
@order = Order.find(par... | Ruby |
class CategoriesController < ApplicationController
# GET /categories
# GET /categories.xml
def index
@categories = Category.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @categories }
end
end
# GET /categories/1
# GET /categories/1.xml
def s... | 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
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryPr... | Ruby |
class OrderItemsController < ApplicationController
# GET /order_items
# GET /order_items.xml
def index
@order_items = OrderItem.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @order_items }
end
end
# GET /order_items/1
# GET /order_items/1.xml
... | Ruby |
class StoreController < ApplicationController
def index
@products = Product.all
@categories = Category.all
@showCat = 0
@Cat = nil
@loggedIn = false
if Admin.find_by_username(session[:user_name])
@loggedIn = true
end
if params[:paramCat] != nil
@Cat = Category.find_by... | 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.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 CreateOrders < ActiveRecord::Migration
def self.up
create_table :orders do |t|
t.integer :client_id
t.timestamps
end
end
def self.down
drop_table :orders
end
end
| Ruby |
class CreateClients < ActiveRecord::Migration
def self.up
create_table :clients do |t|
t.string :name
t.string :email
t.string :username
t.string :password
t.timestamps
end
end
def self.down
drop_table :clients
end
end
| Ruby |
class RemoveClientIdOfOrders < ActiveRecord::Migration
def self.up
remove_column :orders, :client_id
end
def self.down
end
end
| Ruby |
class RenameClientsToAdmins < ActiveRecord::Migration
def self.up
rename_table :clients, :admins
end
def self.down
end
end
| Ruby |
class RemoveAddressIdOfAdmins < ActiveRecord::Migration
def self.up
remove_column :admins, :address_id
end
def self.down
end
end
| Ruby |
class AddGenderToClient < ActiveRecord::Migration
def self.up
add_column :clients, :gender, :string
end
def self.down
remove_column :clients, :gender
end
end
| Ruby |
class CreateVendors < ActiveRecord::Migration
def self.up
create_table :vendors do |t|
t.string :username
t.string :password
t.string :email
t.timestamps
end
end
def self.down
drop_table :vendors
end
end
| Ruby |
class CreateAddresses < ActiveRecord::Migration
def self.up
create_table :addresses do |t|
t.string :country
t.string :city
t.string :street
t.integer :postal
t.string :housenumber
t.timestamps
end
end
def self.down
drop_table :addresses
end
end
| Ruby |
class CreateOrderItems < ActiveRecord::Migration
def self.up
create_table :order_items do |t|
t.integer :product_id
t.integer :order_id
t.integer :count
t.timestamps
end
end
def self.down
drop_table :order_items
end
end
| Ruby |
class DropAddresses < ActiveRecord::Migration
def self.up
drop_table :addresses
end
def self.down
end
end
| Ruby |
class Products < ActiveRecord::Migration
def self.up
add_column :products, :image_path, :string
end
def self.down
remove_column :products, :image_path
end
end
| Ruby |
class ClientAddressId < ActiveRecord::Migration
def self.up
add_column :clients, :address_id, :integer
end
def self.down
remove_column :clients, :address_id
end
end
| Ruby |
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :name
t.decimal :price
t.string :description
t.timestamps
end
end
def self.down
drop_table :products
end
end
| Ruby |
class DropVendors < ActiveRecord::Migration
def self.up
drop_table :vendors
end
def self.down
end
end
| Ruby |
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.string :description
t.timestamps
end
end
def self.down
drop_table :categories
end
end
| Ruby |
class ProductsForeignKey < ActiveRecord::Migration
def self.up
add_column :products, :category_id, :integer
end
def self.down
remove_column :products, :category_id
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 |
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 |
#!/usr/bin/ruby -w
require 'optparse'
require 'socket'
OPTIONS = {
:host => 'localhost',
:port => 7777,
:size => 50000,
}
ARGV.options do |opts|
script_name = File.basename $0
opts.banner = "Usage: ruby #{script_name} [options]"
opts.separator ""
opts.on("-H", "--host=host", String,
"Connects to s... | Ruby |
#!/usr/bin/ruby -w
require 'optparse'
require 'socket'
OPTIONS = {
:interface => '',
:port => 7777,
:size => 50000,
}
ARGV.options do |opts|
script_name = File.basename $0
opts.banner = "Usage: ruby #{script_name} [options]"
opts.separator ""
opts.on("-i", "--interface=interface", String,
... | Ruby |
#!/usr/bin/ruby -w
require 'optparse'
require 'socket'
OPTIONS = {
:interface => '',
:port => 7777,
:size => 50000,
}
ARGV.options do |opts|
script_name = File.basename $0
opts.banner = "Usage: ruby #{script_name} [options]"
opts.separator ""
opts.on("-i", "--interface=interface", String,
... | Ruby |
#!/usr/bin/ruby -w
require 'optparse'
require 'socket'
OPTIONS = {
:host => 'localhost',
:port => 7777,
:size => 50000,
}
ARGV.options do |opts|
script_name = File.basename $0
opts.banner = "Usage: ruby #{script_name} [options]"
opts.separator ""
opts.on("-H", "--host=host", String,
"Connects to s... | Ruby |
#!/usr/bin/ruby -w
#
# == Synopsis
#
# Creates a list of all packages in google-code's bollin project with links to
# svn and with descriptions.
#
# == Usage
#
# package_list.rb > Packagelist.wiki
#
# package_list.rb -h|--help
#
# == Author
#
# Torsten Werner <twerner@debian.org>
#
# == Copyright
#
# Copyright (c) 200... | Ruby |
#!/usr/bin/ruby -w
#
# == Synopsis
#
# Creates a list of all packages in google-code's bollin project with links to
# svn and with descriptions.
#
# == Usage
#
# package_list.rb > Packagelist.wiki
#
# package_list.rb -h|--help
#
# == Author
#
# Torsten Werner <twerner@debian.org>
#
# == Copyright
#
# Copyright (c) 200... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.