code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
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 |
source :gemcutter
gem 'sinatra', :require => 'sinatra/base'
gem 'thin', '~> 1.3'
gem 'pg'
gem 'data_mapper', '~> 1.2'
gem 'dm-postgres-adapter'
gem 'google-api-client', '>= 0.4.3'
group :development do
gem 'dm-sqlite-adapter', '~> 1.2'
gem 'do_sqlite3', '~> 0.10'
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 |
#!/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 |
#!/usr/bin/env ruby
class Box
BOX_API_KEY = "YOUR_API_KEY"
BOX_LOGIN_EMAIL = "YOUR LOGIN EMAIL" # use '%40' instead of '@'
BOX_PASSWORD = "YOUR PASSWORD"
BOX_FOLDER_ID = 0 # upload to the root folder, 0 is root folder id
BOX_GET_TICKET_URL = "http://www.box.net/api/1.0/rest?action=get_ticket&api_key=#{BOX_A... | Ruby |
#!/usr/bin/env ruby
class Box
BOX_API_KEY = "YOUR_API_KEY"
BOX_LOGIN_EMAIL = "YOUR LOGIN EMAIL" # use '%40' instead of '@'
BOX_PASSWORD = "YOUR PASSWORD"
BOX_FOLDER_ID = 0 # upload to the root folder, 0 is root folder id
BOX_GET_TICKET_URL = "http://www.box.net/api/1.0/rest?action=get_ticket&api_key=#{BOX_A... | Ruby |
#!/usr/bin/env ruby
tool = 'mp3unicode -s GBK -1 UTF-8 -p'
list = `find . -name '*.mp3'`.split("\n")
total = list.size
success = 0
exceptions = {}
list.each do |file|
puts "Processing #{file} ..."
output = `#{tool} '#{file}' 2>&1`
if $?.success?
success += 1
else
exceptions[file] = output
end
end
pu... | Ruby |
#!/usr/bin/env ruby
tool = 'mp3unicode -s GBK -1 UTF-8 -p'
list = `find . -name '*.mp3'`.split("\n")
total = list.size
success = 0
exceptions = {}
list.each do |file|
puts "Processing #{file} ..."
output = `#{tool} '#{file}' 2>&1`
if $?.success?
success += 1
else
exceptions[file] = output
end
end
pu... | Ruby |
#!/usr/bin/env ruby
#--------------------------------------------------
# Author: Jan X <jan.h.xie@gmail.com> http://jan.yculblog.com
# Date: Apr. 14, 2008
#--------------------------------------------------
#--------------------------------------------------
# Test Cases
# http://www.google.com
# ftp://jan:jan@ftp.... | Ruby |
#!/usr/bin/env ruby
#--------------------------------------------------
# Author: Jan X <jan.h.xie@gmail.com> http://jan.yculblog.com
# Date: Apr. 14, 2008
#--------------------------------------------------
#--------------------------------------------------
# Test Cases
# http://www.google.com
# ftp://jan:jan@ftp.... | Ruby |
#!/usr/bin/env ruby
#--------------------------------------------------
# Author: Jan X <jan.h.xie@gmail.com> http://jan.yculblog.com
# Date: May. 23, 2008
#--------------------------------------------------
# settings
UP = 107 #'k'
DOWN = 106 #'j'
EXIT = 104 #'h'
RETURN = 108 #'l'
BROWSER = 'firefox'
FAVORATES="#{... | Ruby |
#!/usr/bin/env ruby
#--------------------------------------------------
# Author: Jan X <jan.h.xie@gmail.com> http://jan.yculblog.com
# Date: May. 23, 2008
#--------------------------------------------------
# settings
UP = 107 #'k'
DOWN = 106 #'j'
EXIT = 104 #'h'
RETURN = 108 #'l'
BROWSER = 'firefox'
FAVORATES="#{... | Ruby |
#!/usr/bin/env ruby
require 'socket'
require 'ipaddr'
port = 5350
print "Listening for NAT-PMP public IP changes:\n"
socket = UDPSocket.new
while true do
begin
# socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
# socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)
socket... | Ruby |
#!/usr/bin/env ruby
require 'socket'
require 'ipaddr'
port = 5350
# A compatible NAT gateway MUST generate a response with the following
# format:
#
# 0 1 2 3
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# +-+-+-+-+-+-+-+-+-+-+-+-+... | Ruby |
#!/usr/bin/env ruby
require 'socket'
require 'ipaddr'
port = 5350
print "Listening for NAT-PMP public IP changes:\n"
socket = UDPSocket.new
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)
socket.bind("224.0.0.1",port)
addr = '0.0.0... | Ruby |
def system(*a)
puts " $ #{a[0]}"
super
end
module Compressor
def self.compress(jscode)
require 'net/http'
require 'uri'
response = Net::HTTP.post_form(URI.parse('http://closure-compiler.appspot.com/compile'), {
'js_code' => jscode,
'compilation_level' => "SIMPLE_OPTIMIZATIONS",
'o... | Ruby |
ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
require 'test_helper'
require 'dummy_rails/config/environment'
require 'rails/test_help'
require 'capybara/rails'
| Ruby |
require 'sass'
require 'bootstrap-sass'
require 'fileutils'
scss_path = File.expand_path('./import_all.sass', File.dirname(__FILE__))
css = Sass.compile File.read(scss_path), syntax: 'sass'
if ARGV[0]
FileUtils.mkdir_p File.dirname(ARGV[0])
File.open(ARGV[0], 'w') { |f| f.write css }
else
puts css
end
| Ruby |
source 'https://rubygems.org'
gem 'sass', '~> 3.2'
gem 'bootstrap-sass', path: '../..'
| Ruby |
module ApplicationHelper
end
| Ruby |
class PagesController < ApplicationController
def root
end
end | Ruby |
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
| Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflec... | 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 to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters f... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... | 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.
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
| Ruby |
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| Ruby |
Dummy::Application.routes.draw do
root to: 'pages#root'
end
| Ruby |
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails'
%w(
action_controller
action_view
sprockets
).each do |framework|
require "#{framework}/railtie"
end
require 'slim-rails'
require 'jquery-rails'
require 'compass'
require 'bootstrap-sass'
require 'uglifier'
module Dummy
class Application < Rail... | Ruby |
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Dummy::Application.initialize!
| Ruby |
Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web server... | Ruby |
Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.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 web ser... | Ruby |
Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.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 sui... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
| 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.expand_path('../config/application', __FILE__)
Dummy::Application.load_tasks
| Ruby |
require 'minitest/autorun'
require 'minitest/reporters'
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
require 'active_support/core_ext/kernel/reporting'
Dir['test/support/**/*.rb'].each do |file|
# strip ^test/ and .rb$
file = file[5..-4]
require_relative File.join('.', file)
end
GEM_PATH = Fi... | Ruby |
require 'capybara'
require 'fileutils'
module DummyRailsIntegration
include Capybara::DSL
def setup
super
FileUtils.rm_rf('test/dummy_rails/tmp/cache', secure: true)
end
def teardown
super
Capybara.reset_sessions!
Capybara.use_default_driver
end
def screenshot!
path = "tmp/#{name}... | Ruby |
module Kernel
def silence_stdout_if(cond, &run)
silence_stream_if(cond, STDOUT, &run)
end
def silence_stderr_if(cond, &run)
silence_stream_if(cond, STDERR, &run)
end
def silence_stream_if(cond, stream, &run)
if cond
silence_stream(stream, &run)
else
run.call
end
end
end
| Ruby |
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bootstrap-sass/version'
Gem::Specification.new do |s|
s.name = "bootstrap-sass"
s.version = Bootstrap::VERSION
s.authors = ["Thomas McDonald"]
s.email = 'tom@conceptcoding.co.uk'
s.summary = ... | Ruby |
source 'https://rubygems.org'
gemspec
# Compass for the dummy app
gem 'compass', require: false
group :development do
gem 'byebug', platform: :mri_21, require: false
end
| Ruby |
description 'Bootstrap for Sass'
# Stylesheet importing bootstrap
stylesheet 'styles.sass'
# Bootstrap variable overrides file
stylesheet '_bootstrap-variables.sass', :to => '_bootstrap-variables.sass'
# Copy JS and fonts
manifest = Pathname.new(File.dirname(__FILE__))
assets = File.expand_path('../../assets', man... | Ruby |
require 'find'
require 'json'
require 'pathname'
namespace :bower do
find_files = ->(path) {
Find.find(Pathname.new(path).relative_path_from(Pathname.new Dir.pwd).to_s).map do |path|
path if File.file?(path)
end.compact
}
desc 'update main and version in bower.json'
task :generate do
requir... | Ruby |
# coding: utf-8
# Based on convert script from vwall/compass-twitter-bootstrap gem.
# https://github.com/vwall/compass-twitter-bootstrap/blob/master/build/convert.rb
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this work except in compliance with the License.
# You may obtain a ... | Ruby |
class Converter
module JsConversion
def process_javascript_assets
log_status 'Processing javascripts...'
save_to = @save_to[:js]
contents = {}
read_files('js', bootstrap_js_files).each do |name, file|
contents[name] = file
save_file("#{save_to}/#{name}", file)
end
... | Ruby |
class Converter
module FontsConversion
def process_font_assets
log_status 'Processing fonts...'
files = read_files('fonts', bootstrap_font_files)
save_to = @save_to[:fonts]
files.each do |name, content|
save_file "#{save_to}/#{name}", content
end
end
def bootstrap_... | Ruby |
class Converter
class Logger
include Term::ANSIColor
def log_status(status)
puts bold status
end
def log_file_info(s)
puts " #{magenta s}"
end
def log_transform(*args, from: caller[1][/`.*'/][1..-2].sub(/^block in /, ''))
puts " #{cyan from}#{cyan ": #{args * ', '}" ... | Ruby |
require 'shellwords'
class Converter
module Network
protected
def get_paths_by_type(dir, file_re, tree = get_tree(get_tree_sha(dir)))
tree['tree'].select { |f| f['type'] == 'blob' && f['path'] =~ file_re }.map { |f| f['path'] }
end
def read_files(path, files)
full_path = "https://raw.git... | Ruby |
require_relative 'char_string_scanner'
# This is the script used to automatically convert all of twbs/bootstrap LESS to Sass.
#
# Most differences are fixed by regexps and other forms of string substitution.
# There are Bootstrap-specific workarounds for the lack of parent selectors, recursion, mixin namespaces, exten... | Ruby |
# regular string scanner works with bytes
# this one works with chars and provides #scan_next
class Converter
class CharStringScanner
extend Forwardable
def initialize(*args)
@s = StringScanner.new(*args)
end
def_delegators :@s, :scan_until, :skip_until, :string
# advance scanner to pos a... | Ruby |
lib_path = File.join(File.dirname(__FILE__), 'lib')
$:.unshift(lib_path) unless $:.include?(lib_path)
load './tasks/bower.rake'
require 'rake/testtask'
task :test do |t|
$: << File.expand_path('test/')
Dir.glob('./test/**/*_test.rb').each { |file| require file }
end
desc 'Dumps output to a CSS file for testing'
... | Ruby |
module Bootstrap
module Rails
class Engine < ::Rails::Engine
initializer 'bootstrap-sass.assets.precompile' do |app|
%w(stylesheets javascripts fonts images).each do |sub|
app.config.assets.paths << root.join('assets', sub).to_s
end
app.config.assets.precompile << %r(bootst... | Ruby |
module Bootstrap
VERSION = '3.3.3'
BOOTSTRAP_SHA = 'bcf7dd38b5ab180256e2e4fb5da0369551b3f082'
end
| Ruby |
require 'bootstrap-sass/version'
module Bootstrap
class << self
# Inspired by Kaminari
def load!
register_compass_extension if compass?
if rails?
register_rails_engine
elsif sprockets?
register_sprockets
end
configure_sass
end
# Paths
def gem_path
... | Ruby |
source 'https://rubygems.org'
gem 'jekyll', '~> 1.0'
gem 'sass', '~> 3.0'
| Ruby |
##
# Flattens the icons object to a one-dimensional array of possible search terms.
require 'set'
module Jekyll
module FlattenArray
def flattenIconFilters(icons)
flattened = Set.new
icons.each do |icon|
toAdd = []
toAdd.push(icon["class"].downcase) # Add class as a filter value
... | Ruby |
##
# Provide an icons attribute on the site object
require 'yaml'
require 'forwardable'
module Jekyll
class Icon
attr_reader :name, :id, :unicode, :created, :categories
def initialize(icon_object)
@icon_object = icon_object
# Class name used in CSS and HTML
@icon_object['class'] = icon... | Ruby |
##
# Create individual pages for each icon in the FontAwesome set
require 'yaml'
module Jekyll
class IconPage < Page
##
# Take a single icon and render a page for it.
def initialize(site, base, dir, icon)
@site = site
@base = base
@dir = dir
@name = "#{icon.id}.html"
@ic... | Ruby |
require 'rake'
require 'rake/clean'
task :default => :test
ROOT = File.expand_path('..', __FILE__)
MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js'))
def mustache_version
match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/)
match[1]
end
def minified_file
ENV['FILE'] || 'mustache.min.js'
end
desc "... | 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' }])
# Mayor.create(name: 'Emanuel... | Ruby |
class CreateEvents < ActiveRecord::Migration
def change
create_table :events do |t|
t.date :event_day
t.text :content
t.text :comment
t.integer :student_id
t.timestamps
end
end
end
| Ruby |
class CreateStudents < ActiveRecord::Migration
def change
create_table :students do |t|
t.string :code
t.string :name
t.string :class_name
t.timestamps
end
end
end
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integrati... | Ruby |
#!/usr/bin/env rake
# 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.expand_path('../config/application', __FILE__)
Task3::Application.load_tasks
| Ruby |
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.... | Ruby |
module ApplicationHelper
end
| Ruby |
module EventsHelper
end
| Ruby |
module StudentsHelper
end
| Ruby |
class Student < ActiveRecord::Base
has_many :events
attr_accessible :class_name, :code, :name
end
| Ruby |
class Event < ActiveRecord::Base
belongs_to :student
attr_accessible :comment, :content, :event_day, :student_id
end
| Ruby |
class EventsController < ApplicationController
def create
@student = Student.find(params[:id])
@event = @student.events.build(params[:event])
if @event.save
redirect_to student_path(:id => @student.id),:notice => "Event has been updated"
end
end
end
| Ruby |
class ApplicationController < ActionController::Base
protect_from_forgery
end
| Ruby |
class StudentsController < ApplicationController
def index
@students = Student.all
end
def show
@student = Student.find(params[:id])
@events = @student.events
@event = @student.events.build
end
def new
@student = Student.new
end
def create
@student = Student.new(params[:studen... | 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.
# 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 to debug a probl... | Ruby |
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters ... | Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies 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 attac... | 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.
Task3::Application.config.session_store :cookie_store, key: '_task3_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails gener... | Ruby |
Task3::Application.routes.draw do
resources :students
resources :events
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
#... | Ruby |
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.requi... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Task3::Application.initialize!
| Ruby |
Task3::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_c... | Ruby |
Task3::Application.configure do
# Settings specified here will take precedence over those in config/application.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 web serv... | Ruby |
Task3::Application.configure do
# Settings specified here will take precedence over those in config/application.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 suit... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Task3::Application
| Ruby |
#!/usr/bin/env rake
# 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.expand_path('../config/application', __FILE__)
Task3::Application.load_tasks
| Ruby |
require 'mathn'
puts 'A = '
A = gets.chomp.to_i
prime_power = [1, 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, 31, 32, 37, 41, 43, 47, 49, 53, 59, 61, 64,
67, 71, 73, 79, 81, 83, 89, 97, 101, 103, 107, 109, 113, 121, 125, 127, 128, 131, 137, 139, 149, 151, 157, 163, 167,
169, 173, 179, 181, 191, ... | Ruby |
hash = { "Thanh" => 100, "Tien" => 200 }
$flag = "yes";
while $flag=="yes" do
print 'Hello! Type you keyword:'
keyword = gets.chomp.to_s
unless hash.has_key?(keyword)
puts "There is no hash, create hash:"
print keyword+" => "
value = gets.chomp.to_s
hash[keyword] = value
else
pu... | Ruby |
require File.join File.dirname(__FILE__), 'task5_lib'
# square , edge = 10
print "The perimeter of a Square with edge = 10:"
puts p_square(10)
print "The area of a Square with edge = 10:"
puts s_square(10)
# rectangle , width = 10, height = 15
print "The perimeter of a Rectangle with width = 10 and height = 1... | Ruby |
# Calculation the perimeter of a square with edge length
# * *Args* :
# - +edge+ -> edge length as double
# * *Returns* :
# - perimeter of a square as double
def p_square(edge)
return edge*4
end
# Calculation the area of a square with edge length
# * *Args* :
# - +edge+ -> edge length as ... | Ruby |
#input
puts 'A = '
A = gets.chomp.to_f
if (A == 0)
puts 'Not a quadratic equation.'
return
end
puts 'B = '
B = gets.chomp.to_f
puts 'C = '
C = gets.chomp.to_f
#process
D = B*B - 4*A*C
#output
if (D == 0)
puts 'x = '+sprintf('%.4f',(-B/(2*A)*1.0000)).to_s
else
if (D > 0)
puts 'x1... | Ruby |
class FileProcess
attr_accessor :input, :output
def initialize(input,output)
begin
$input = File.new(input, "r")
$output = File.new(output, "w")
rescue
puts "file not found"
Process.exit
end
end
def conver( )
puts "Start conver"
while (line = $input.gets... | 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.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies 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 atta... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.