code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# 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.
# 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 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.
#
# 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.
TranslateApp::Application.config.session_store :cookie_store, key: '_translate_app_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 wi... | 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 |
TranslateApp::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.a... | Ruby |
TranslateApp::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 w... | Ruby |
TranslateApp::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 te... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
TranslateApp::Application.initialize!
| 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 |
TranslateApp::Application.routes.draw do
resources :users
resources :dictionaries
resources :translates
root to: 'translates#index'
match '/show', to: 'translates#show', via: :post
match '/remember', to: 'translates#remember', via: :get
match '/getNumber', to: 'translates#calculate', via: :get
match ... | Ruby |
module ApplicationHelper
end
| Ruby |
module UsersHelper
end
| Ruby |
module DictionariesHelper
end
| Ruby |
module TranslatesHelper
end
| Ruby |
class Category < ActiveRecord::Base
attr_accessible :category_id, :name
belongs_to :dictionary
end
| Ruby |
class Sentence < ActiveRecord::Base
attr_accessible :chinese_sentence, :english_sentence, :word_id
belongs_to :dictionary
end
| Ruby |
class Difficulty < ActiveRecord::Base
attr_accessible :word_difficulty_id, :word_difficulty_string
end
| Ruby |
class Dictionary < ActiveRecord::Base
attr_accessible :word_category, :word_chinese, :word_difficulty_id, :word_english, :word_id, :pronunciation
validates :word_id, uniqueness: true
has_many :understands
has_many :difficulties
has_many :users, through: :understands
end
| Ruby |
class User < ActiveRecord::Base
attr_accessible :user_id, :user_name, :if_translate, :translate_categories
validates :user_id, uniqueness: true
validates :user_name, uniqueness: true
has_many :understands, dependent: :destroy
has_many :dictionaries, through: :understands
end
| Ruby |
class Transaction < ActiveRecord::Base
attr_accessible :if_remembered, :transcation_code, :url, :user_name, :word_english
end
| Ruby |
class Understand < ActiveRecord::Base
attr_accessible :strength, :user_id, :word_id
validates_uniqueness_of :user_id, :scope => :word_id
belongs_to :user
belongs_to :dictionary
end
| Ruby |
class Translate < ActiveRecord::Base
# attr_accessible :title, :body
end
| Ruby |
#!bin/env ruby
#encoding: utf-8
class TranslatesController < ApplicationController
# GET /translates
# GET /translates.json
include Bing
def index
@translates = Translate.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @translates }
end
end
# G... | Ruby |
class DictionariesController < ApplicationController
# GET /dictionaries
# GET /dictionaries.json
def index
@dictionaries = Dictionary.all
respond_to do |format|
format.html { render :layout => false }# index.html.erb
format.json { render json: @dictionaries }
end
end
# GET /dictiona... | Ruby |
module Bing
# Specify all arguments
def Bing.translate(text, from, to)
translator = BingTranslator.new('LearnNews', 'jvdytVMvoC+DNOHQUBk2UbMBv3kydl8/hPFGUtxlod0=', false, 'lZwqxEqMjH0MdzFeqsJ6dv3JsU859h/D+Mz2WFN4NYM')
# Or... Specify only required arguments
#translator = BingTranslator.new('LearnNews', 'jvdytVM... | Ruby |
class ApplicationController < ActionController::Base
protect_from_forgery
after_filter :set_access_control_headers
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
end
end
| Ruby |
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end
# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])
... | 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__)
TranslateApp::Application.load_tasks
| Ruby |
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
| Ruby |
source 'https://rubygems.org'
gem 'rails', '3.2.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
group :assets do
gem 'sass-rails',... | Ruby |
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.integer :user_id
t.string :user_name
t.timestamps
end
end
end
| Ruby |
class AddIfUnderstandToUnderstands < ActiveRecord::Migration
def change
add_column :understands, :if_understand, :integer
end
end
| Ruby |
class CreateTranslates < ActiveRecord::Migration
def change
create_table :translates do |t|
t.timestamps
end
end
end
| Ruby |
class CreateDictionaries < ActiveRecord::Migration
def change
create_table :dictionaries do |t|
t.string :word_english
t.string :word_chinese
t.string :word_category
t.integer :word_difficulty_id
t.timestamps
end
end
end
| Ruby |
class AddColumnNameToUnderstand < ActiveRecord::Migration
def change
add_column :understands, :url, :string
end
end
| Ruby |
class CreateNotUnderstands < ActiveRecord::Migration
def change
create_table :not_understands do |t|
t.integer :user_id
t.integer :word_id
t.integer :strength
t.timestamps
end
end
end
| Ruby |
class CreateUnderstands < ActiveRecord::Migration
def change
create_table :understands do |t|
t.integer :user_id
t.integer :word_id
t.integer :strength
t.timestamps
end
end
end
| Ruby |
class AddIfTranslateToUsers < ActiveRecord::Migration
def change
add_column :users, :if_translate, :integer
end
end
| Ruby |
class RenameColumn < ActiveRecord::Migration
def up
rename_column :transactions, :transcation_code, :transaction_code
end
def down
end
end
| Ruby |
class AddWordIdToDictionaries < ActiveRecord::Migration
def change
add_column :dictionaries, :word_id, :integer
end
end
| Ruby |
class CreateDifficulties < ActiveRecord::Migration
def change
create_table :difficulties do |t|
t.integer :word_difficulty_id
t.string :word_difficulty_string
t.timestamps
end
end
end
| Ruby |
class DropNotUnderstandsTable < ActiveRecord::Migration
def up
drop_table :not_understands
end
def down
end
end
| Ruby |
class AddTranslateCatoriesToUsers < ActiveRecord::Migration
def change
add_column :users, :translate_categories, :string
end
end
| Ruby |
class AddPronunciationToDictionaries < ActiveRecord::Migration
def change
add_column :dictionaries, :pronunciation, :string
end
end
| Ruby |
class CreateSentences < ActiveRecord::Migration
def change
create_table :sentences do |t|
t.integer :word_id
t.text :english_sentence
t.text :chinese_sentence
t.timestamps
end
end
end
| Ruby |
class CreateTransactions < ActiveRecord::Migration
def change
create_table :transactions do |t|
t.integer :transcation_code
t.string :user_name
t.integer :word_english
t.integer :if_remembered
t.string :url
t.timestamps
end
end
end
| Ruby |
class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name
t.integer :category_id
t.timestamps
end
end
end
| Ruby |
class CreateDictionary < ActiveRecord::Migration
def up
end
def down
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' }])
# Mayor.create(name: 'Emanuel... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run TranslateApp::Application
| 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 |
header = <<-eos
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
eos
require 'find'
dirs = ["../src","../test"]
paths = []
for dir in dirs
Find.find(dir) do |path|
if FileTest.directory?(path)
if File.basename(path) == '.svn'
... | 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 |
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 |
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 |
require 'sinatra/activerecord/rake'
require './main' | Ruby |
puts 'Hello world'
| Ruby |
require 'Form1.rb'
System::Windows::Forms::Application.EnableVisualStyles
System::Windows::Forms::Application.SetCompatibleTextRenderingDefault(false)
System::Windows::Forms::Application.Run(Form1.new)
| Ruby |
require 'mscorlib.dll'
require 'System.dll'
require 'System.Drawing.dll'
require 'System.Windows.Forms.dll'
class Form1 < System::Windows::Forms::Form
def initialize
self.InitializeComponent
end
def InitializeComponent
self.Text = 'Form1'
end
end
| Ruby |
class Class1
end
| Ruby |
require 'System.dll'
require 'System.Drawing.dll'
require 'System.Windows.Forms.dll'
class $safeitemname$ < System::Windows::Forms::Form
def initialize
self.InitializeComponent
end
def InitializeComponent
self.SuspendLayout
self.ClientSize = System::Drawing::Size.new(300, 300)
self.Name = ... | Ruby |
class $safeitemrootname$
end
| Ruby |
class %className%
end
| Ruby |
class %className%
end
| Ruby |
module $safeitemrootname$
end
| Ruby |
# This Windows Forms example must be compiled first:
# rubycompiler myform.rb mscorlib.dll System.Windows.Forms.dll System.Drawing.dll
require 'mscorlib.dll'
require 'System.dll'
require 'System.Data.dll'
require 'System.Drawing.dll'
require 'System.Deployment.dll'
require 'System.Windows.Forms.dll'
require '... | Ruby |
require 'mscorlib'
require 'System'
l = System::Collections::Generic::List[System::String].new
l.Add <<"EOF";
public class Test
{
public static int Sum(int[] a)
{
int n = 0;
foreach (int i in a)
n += i;
return n;
}
public static object First(object[] a)
{
return a[0]... | Ruby |
require "mscorlib"
a = System::Collections::ArrayList.new
class System::Collections::ICollection
def first
self[0] if (self.Count > 0)
end
def last
self[self.Count - 1] if (self.Count > 0)
end
end
puts a.first
puts a.last
a.Add(0)
a.Add(1)
puts a.first
puts a.last
| Ruby |
require 'mscorlib'
require 'System'
l = System::Collections::Generic::List[System::String].new
l.Add <<"EOF";
public class Test<T>
{
public class Inner{}
public class Inner<V> {}
public class Inner<V,V2> {}
}
public class Test2
{
public class Inner {}
public class Inner<V> {}
public class ... | Ruby |
require 'mscorlib'
require 'System'
l = System::Collections::Generic::List[System::String].new
l.Add <<"EOF";
namespace test_lower_namespace
{
public class test_lower_class
{
public static int test_lower_method()
{
return 1;
}
}
}
namespace Test_upper_namespace
{
public cla... | Ruby |
$KCODE = "none"
$testnum=0
$ntest=0
$failed = 0
def test_check(what)
printf "%s\n", what
$what = what
$testnum = 0
end
def test_ok(cond,n=1)
$testnum+=1
$ntest+=1
if cond
printf "ok %d\n", $testnum
else
where = caller(n)[0]
printf "not ok %s %d -- %s\n", $what, $testnum, wh... | Ruby |
$testnum = 0
def test_ok(cond)
$testnum += 1
if cond
printf("ok %d\n", $testnum)
else
printf("not ok %d\n", $testnum)
end
end
require 'complex'
number = Complex(1, 1)
test_ok(number * number.conjugate == number.abs2)
require 'csv'
line = '1,2,3'
test_ok(CSV.parse_line(line).join(',') == line)
requir... | Ruby |
require 'test/unit'
class TestString < Test::Unit::TestCase
def setup
@obj = Object.new
end
def test_respond_to_eh
# String
assert(@obj.respond_to?('respond_to?'))
assert(!@obj.respond_to?('foo'))
assert_raise(ArgumentError) { @obj.respond_to?('') }
# Fixnum
# Should w... | Ruby |
require 'test/unit'
class TestArray < Test::Unit::TestCase
# TODO:
# - rb_ary_at line 1
# - rb_ary_splice line 3
# - rb_ary_eql lines 3-5
# - rb_ary_transpose line 5: special case, do we need to test this?
# - rb_ary_replace line 5: special case, do we need to test this?
# - What about warning-o... | Ruby |
# TODO: This is completely unfinished.
require 'test/unit'
class TestSymbol < Test::Unit::TestCase
# Requires String#intern.
def setup
@sym = "Hello!".intern
end
def test_inspect_can_be_evaluated
# Whatever the internal representation is, `sym.inspect'
# "returns the representation ... | Ruby |
require 'test/unit'
# Note:
# - The STR_ASSOC flag is helper for pack.c (Array#pack and String#unpack).
# Associated strings cannot be gc'ed. This probably needs to be tested.
# - string_value is helper for a lot of things, used everywhere.
# In particular, StringValueCStr raises ArgumentError if the string ... | Ruby |
require 'test/unit'
class TestFixnum < Test::Unit::TestCase
def setup
@fix = 5
end
def test_aref
# There is no Fixnum#[]=
assert_raise(NoMethodError) { 2[0] = 1 }
end
def test_div_use_correct_method_if_coerced
assert_equal('/', 1 / CoerceToDivSlash.new)
assert_equal('div',... | Ruby |
# Next: Hash#invert
require 'test/unit'
class TestHash < Test::Unit::TestCase
def setup
@h = {'a'=>5, 0=>'b'}
end
def test_aref_arity
# 1
assert_raise(ArgumentError) { @h[] }
assert_raise(ArgumentError) { @h['a', 'b'] }
end
def test_aset
assert_nothing_raised { @h[4] = ... | Ruby |
require 'test/unit'
class TestModule < Test::Unit::TestCase
def test_alias_method
# TODO: Test when method is singleton.
# How? alias_method(:a, :b) doesn't work if b is singleton method.
AliasModule.do_alias_method_x_1
assert_equal(1, AliasModule.x)
# XXX If verbose, this print... | Ruby |
require 'test/unit'
class TestRange < Test::Unit::TestCase
def test_each_custom
r = Range.new(FixnumWrapper.new(2), FixnumWrapper.new(5))
res = 0
r.each {|x| res += x.n }
assert_equal(14, res)
end
def test_each_returns_self
util_returns_self(:each)
end
def test_initialize_... | Ruby |
require 'test/unit'
class TestMath < Test::Unit::TestCase
EPSILON = 1e-7
def test_acos
assert_in_delta(1.0471975511966, Math.acos(0.5), EPSILON)
end
def test_acosh
assert_in_delta(4.60507017098476, Math.acosh(50), EPSILON)
end
def test_asin
assert_in_delta(0.523598775598299, Ma... | Ruby |
require 'test/unit'
class TestProc < Test::Unit::TestCase
def setup
@proc = Proc.new { 5 }
end
def test_aref
util_invoke(Proc.method(:new), :[])
util_invoke_non_lambda(Proc.method(:new), :[])
util_invoke(Kernel.method(:lambda), :[])
util_invoke_lambda(Kernel.method(:lambda), :[]... | Ruby |
# TODO: This is completely unfinished.
require 'test/unit'
class TestThread < Test::Unit::TestCase
def test_keys
# When thread locals is empty, Thread#key?('') returns false.
th = Thread.new {}
assert_equal(false, th.key?(''))
# When thread locals is not empty, Thread#key?('') throws exce... | Ruby |
require 'test/unit'
# TODO: num_remainder
class TestNumeric < Test::Unit::TestCase
def setup
@fix = 5
@flo = 5.5
@big = 20 ** 20
@my = MyNumeric.new
end
# TODO: Maybe try to coerce with invalid args?
def test_coerce
assert_equal([1, 2], 2.coerce(1))
assert_equal([1.5, 2... | Ruby |
require 'test/unit'
# TODO: exit! does not raise SystemExit, so the only way to test is by calling
# another ruby process.
#~ Not yet tested:
#~ => ["`", "at_exit", "binding",
#~ "callcc", "catch", "chomp", "chomp!", "chop", "chop!",
#~ "eval", "exec", "exit!", "fork", "format", "getc", "gets",
#~ "gsub", "g... | Ruby |
require 'test/unit'
class TestNumeric < Test::Unit::TestCase
def setup
@fix = 5
@big = 20 ** 20
end
def test_ceil_bignum
i = (@big - 0.9).ceil
assert_equal(@big, i)
assert_instance_of(Bignum, i)
b = -@big
assert_equal(b, (b - 0.9).ceil)
end
def test_floor_bignu... | 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 |
# 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 |
# 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 |
require 'pp'
def estimate_acceleration_distance(initial_rate, target_rate, acceleration)
(target_rate*target_rate-initial_rate*initial_rate)/(2*acceleration)
end
def intersection_distance(initial_rate, final_rate, acceleration, distance)
(2*acceleration*distance-initial_rate*initial_rate+final_rate*final_ra... | Ruby |
require 'rubygems'
require 'optparse'
require 'serialport'
options_parser = OptionParser.new do |opts|
opts.banner = "Usage: stream [options] gcode-file"
opts.on('-v', '--verbose', 'Output more information') do
$verbose = true
end
opts.on('-p', '--prebuffer', 'Prebuffer commands') do
$prebuffer = ... | Ruby |
#!/usr/bin/ruby
require 'script/stream' | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.