blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 4 137 | path stringlengths 2 355 | src_encoding stringclasses 31
values | length_bytes int64 11 3.9M | score float64 2.52 5.47 | int_score int64 3 5 | detected_licenses listlengths 0 49 | license_type stringclasses 2
values | text stringlengths 11 3.93M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
542bbd78ba6b7fd8832e59faddd6b749b444e2cd | Ruby | helenakolberg/project_book_shop | /models/author.rb | UTF-8 | 2,020 | 3.4375 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
class Author
attr_reader :id
attr_accessor :first_name, :last_name, :bio, :status
def initialize(options)
@id = options['id'].to_i if options['id']
@first_name = options['first_name']
@last_name = options['last_name']
@bio = options[... | true |
451bb815c0d74c1eb40fcbb45a189c671265a532 | Ruby | andypike/stupid_data | /spec/stupid_data_spec.rb | UTF-8 | 6,711 | 2.796875 | 3 | [] | no_license | require "spec_helper"
describe StupidData do
subject(:database) { StupidData.new("dbname=stupid_data") }
context "#query" do
it "populates a collection with the correct number of records" do
results = database.query("select id, name from users")
results.count.should == 3
end
it "defines ... | true |
6ad404a5c361ef3d1ccf7c099ab4c60537e875cc | Ruby | wdcjernigan/CS561 | /automated/pageinsight.rb | UTF-8 | 1,565 | 2.578125 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'net/http'
require 'net/https'
require 'uri'
@log = File.open("pageSpeedresults.csv", 'a')
def logAndOutput s
@log.write(s)
@log.write("\t")
puts s
end
@log2 = File.open("MobileOKresultsDetails.log", 'a')
def logAndOutput2 s
@log2.write(s)
@log2... | true |
9d0d77ddf5f58bb01a058118538ae2ceaa8850a4 | Ruby | netizer/transitions | /lib/mongoid/transitions.rb | UTF-8 | 1,808 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # Copyright (c) 2010 Krzysiek Herod
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, dis... | true |
0edb71635c154100bafd41ddb34ee73dd8594dee | Ruby | GabrielRMorales/enumerable_methods | /lib/enumerable.rb | UTF-8 | 1,865 | 3.28125 | 3 | [] | no_license | module Enumerable
def my_each
return "This needs a block" unless block_given?
i=0
while i!=self.length
yield(self, i)
i+=1
end
end
def my_each_with_index
return "This needs a block" unless block_given?
i=0
while i!=self.length
j=self.index(self[i])
yield(self, i, j)
i+=1
end ... | true |
08c8c72413b5cef5ab4b69b701c0f7d034048c9a | Ruby | Umnums/ruby-music-library-cli-online-web-sp-000 | /lib/song.rb | UTF-8 | 1,186 | 2.953125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative './concerns/method.rb'
require_relative './artist.rb'
require_relative './genre.rb'
require_relative './music_importer.rb'
require_relative './MusicLibraryController.rb'
class Song
attr_accessor :name, :artist, :genre
@@all = []
include Concerns::Methods::InstanceMethods
extend Concerns::Find... | true |
317662ac9d29bfb81bfa8131b63dbd76b2757c93 | Ruby | kakao/cmux | /lib/cmux/utils/errors.rb | UTF-8 | 4,203 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | module CMUX
# Raise when a command not registered in cmux is executed
class CMUXCommandError < StandardError
def initialize(msg = nil)
@message = msg
end
def message
"Invalid CMUX command: #{@message}"
end
end
# Raise when two or more commands are executed without being attached to... | true |
40f648d9b106d440af07e52a352dbae0466f7013 | Ruby | markmontymark/patterns | /ruby/src/common/VegetableSoup.rb | UTF-8 | 202 | 2.671875 | 3 | [] | no_license |
require "common/Soup"
class VegetableSoup < Soup
def initialize()
@soupName = 'Vegetable Soup'
@soupIngredients = [
'1 cup bullion',
'1/4 cup carrots',
'1/4 cup potatoes', ]
end
end
| true |
3feb020a3903011e5ea850a7ffc2cf8e7eedaa4b | Ruby | Nyelanioustour/programming-univbasics-4-array-simple-array-manipulations-part-2-wdc01-seng-ft-060120 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 341 | 3.0625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_concat(array, arraytwo)
array.concat(arraytwo)
end
def using_insert(array, arraytwo)
array.insert(4,arraytwo)
end
def using_uniq(array)
array.uniq
end
def using_flatten(array)
array.flatten
end
def using_delete(array, string)
array.delete(string)
end
def using_delete_at(array, number)
array.d... | true |
2580396fcc0d13475e08fe99f47180d72991bbf7 | Ruby | jj222-stack/S2D2Ruby | /jj_exo_11.rb | UTF-8 | 121 | 3.078125 | 3 | [] | no_license | puts "Entre le nb de répétition:"
print ">"
user_rep=gets.chomp.to_i
n=0
for n in 0..user_rep
puts " Hello"
end
| true |
47645c9ed45e35d1db8add438d0eef1df7e73440 | Ruby | kimvitug05/tdd-exercise | /lib/blackjack_score.rb | UTF-8 | 610 | 4.09375 | 4 | [] | no_license | # blackjack_score.rb
VALID_CARDS = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']
def blackjack_score(hand)
score = 0
hand.each do |card|
case card
when 'Jack', 'Queen', 'King'
score += 10
when 'Ace'
score += 11
else
card.class == Integer && card >= 2 && card <= 10... | true |
ed80e5f0fabe55bb3d5137ea9ff6cbd953ed8994 | Ruby | muff1nman/Vim | /scripts/pkgbuild_submodule_sources.rb | UTF-8 | 2,333 | 2.6875 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
#
# Copyright © 2014 Andrew DeMaria (muff1nman) <ademaria@mines.edu>
#
# All Rights Reserved.
require 'pathname'
require 'uri'
require 'optparse'
GIT_ENDING = ".git"
def base_name name
uri = URI.parse(name)
base = File.basename(uri.path)
base = base[0..-(GIT_ENDING.length+1)] if base.end_w... | true |
f654b9e2218eefbdd245ae57046de78a2d2ceece | Ruby | JochenFromm/EssentialAlgorithms | /spec/levenshtein_spec.rb | UTF-8 | 512 | 3.265625 | 3 | [] | no_license | require './algorithms/levenshtein.rb'
RSpec.describe Levenshtein do
describe 'distance' do
it 'calculates similarity of strings' do
h = {
['kitten', 'fetching'] => 6,
['kitten', 'knowing'] => 5,
['kitten', 'sitting'] => 3,
['kitten', 'kitchen'] => 2,
['kitten', 'kitt... | true |
651937b37303ccfc1cd4bc96d1db39216fe37314 | Ruby | yvettecook/Rock-Paper-Scissors | /spec/player_spec.rb | UTF-8 | 456 | 2.703125 | 3 | [] | no_license | require './app/models/player'
describe Player do
let (:player) { Player.new('Yvette') }
it "should have a name" do
expect(player.name).to eq 'Yvette'
end
it "should add a win when .win called" do
player.win
expect(player.wins).to eq(1)
end
it "should add a loss when .lose called" do
player.lose
ex... | true |
a48cbe9d5d2a3a0f64e2faa58c8f6196797f4dc8 | Ruby | nkeller1/hatchways | /app/services/posts_service.rb | UTF-8 | 506 | 2.625 | 3 | [] | no_license | class PostsService
def connection
Faraday.new(
url: 'https://hatchways.io'
)
end
def gather_posts_from_tags(tags)
response = tags.map do |tag|
connection.get('/api/assessment/blog/posts') do |req|
req.params['tag'] = tag
end
end
combine_posts(response)
end
def ... | true |
579029c095c97a8da42a3b738a56d8d6109bf27b | Ruby | epoch/songstable | /app/models/song.rb | UTF-8 | 1,413 | 2.515625 | 3 | [] | no_license | class Song < ActiveRecord::Base
attr_accessible :titles, :titles_attributes, :versions_attributes
has_many :titles, :dependent => :destroy
has_many :versions, :dependent => :destroy
accepts_nested_attributes_for :titles, :reject_if => :all_blank, :allow_destroy => true
accepts_nested_attributes_for :version... | true |
8d2df607805d49fa89846142e0021a85024ae07b | Ruby | Aleph-works/ruby-metaprogramming | /first_week/exercise4.rb | UTF-8 | 185 | 3.109375 | 3 | [] | no_license | class A
@@a = 1
@a = 2
a = 3
# Write your code here. Use binding method.
end
p eval('[@@a, @a, a]', *****) # Replace '*****' to your code
# Expected output is '[1, 2, 3]'
| true |
c309f5c9528c3b2b32eff0f9bb168faa78f91159 | Ruby | soumyaveer/ruby-algorithms | /spec/containers/stack_spec.rb | UTF-8 | 3,128 | 3.421875 | 3 | [] | no_license | module Containers
describe Stack do
before do
@stack = Stack.new
end
describe 'initialize' do
it 'creates an empty stack when no data is provided' do
expect(@stack.size).to eql(0)
expect(@stack.empty?).to be_truthy
end
it 'creates a stack with elements when data i... | true |
b9f46488a25c844478cd5ade2235622af8231c3b | Ruby | chelseadeane14/RubyProjects | /cheight.rb | UTF-8 | 282 | 3.09375 | 3 | [] | no_license | #Hackerrank Challenge 8
n = gets.to_i
i = 0
s = {}
while i < n
str1, str2 = gets.split.map(&:to_s)
s["#{str1}"] = "#{str2}"
i+=1
end
p s
i = 0
while line = gets
if s["#{line}"] != nil
puts "#{line}=#{s[line]}"
else
puts "Not found"
end
end
| true |
363ae70e596fd5444655dacf7ea09a88cba87eae | Ruby | aasm/aasm | /lib/aasm/aasm.rb | UTF-8 | 7,508 | 2.734375 | 3 | [
"MIT"
] | permissive | module AASM
# this is used internally as an argument default value to represent no value
NO_VALUE = :_aasm_no_value
# provide a state machine for the including class
# make sure to load class methods as well
# initialize persistence for the state machine
def self.included(base) #:nodoc:
base.extend AAS... | true |
e5a46f3b5a92e5ffe48b00e0d8766103da780950 | Ruby | Beagle123/visualruby | /examples/golf_handicap/src/Score.rb | UTF-8 | 818 | 2.890625 | 3 | [
"MIT"
] | permissive |
class Score
attr_accessor :date, :score, :course_name, :course_rating, :course_slope, :used, :handicap
include GladeGUI
def initialize(course, rating, slope)
@course_name = course
@course_rating = rating
@course_slope = slope
@date = DateTime.now
@score = "0"
@used = nil
@handicap... | true |
ce7f362bda0b04e9cc584f88a95b831c681d30d3 | Ruby | suryagaddipati/linqr | /lib/providers/enumerable_expression_evaluator.rb | UTF-8 | 1,210 | 2.859375 | 3 | [] | no_license | require 'ostruct'
require 'expression_evaluator_base'
class EnumerableExpessionEvaluator < ExpressionEvaluator
def visit_group_by(node)
node.expression.visit(self)
end
def visit_hash(node)
record = OpenStruct.new
node.elements.each do |e|
key = e.key.visit(self)
value = e.value.visit(sel... | true |
910dfa5377520a69479bdac3d0b675cb3dc6fe05 | Ruby | rsinger/free_cite | /lib/utf8_parser.rb | UTF-8 | 1,232 | 2.890625 | 3 | [
"MIT"
] | permissive | class UTF8Parser < StringScanner
STRING = /(([\x0-\x1f]|[\\\/bfnrt]|\\u[0-9a-fA-F]{4}|[\x20-\xff])*)/nx
UNPARSED = Object.new
UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
UNESCAPE_MAP.update({
?" => '"',
?\\ => '\\',
?/ => '/',
?b => "\b",
?f => "\f",
?n => "\n",
?r =>... | true |
1b971e5bd3934097453acc7424f88f0a17a6e348 | Ruby | linaresmariano/marianol-eis20131 | /ejercicios/code_breaker_app/application.rb | UTF-8 | 957 | 3.046875 | 3 | [] | no_license | require 'sinatra/base'
require '../code_breaker/code_breaker.rb'
class MyApplication < Sinatra::Base
enable :sessions
get '/' do
redirect '/palabra'
end
get '/palabra' do
palabra = params[:p]
if palabra
begin
session[:game] = CodeBreaker.new(palabra, 3)
session[... | true |
b19a247e4063f25a02665daa29ed08f36d6d57e2 | Ruby | ElMassimo/crouton | /lib/crouton/presenter.rb | UTF-8 | 797 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'crouton/message'
module Crouton
class Presenter
attr_reader :placeholder, :messages
delegate :each, to: :messages
def initialize(messages, options={})
@placeholder = options.delete(:placeholder) || '.crouton-placeholder'
messages = from_hash(messages) if messages.is_a?(Hash)
@... | true |
b3a035222b0814337e5761e6e71a1f4c5cc8982e | Ruby | fencedin/train_system | /spec/line_spec.rb | UTF-8 | 1,946 | 2.984375 | 3 | [] | no_license | require 'spec_helper'
describe 'Line' do
it 'initializes with a name' do
line = Line.new({:name => 'Blue'})
line.should be_an_instance_of Line
end
it 'gives back the line name' do
line = Line.new({:name => 'Green'})
line.name.should eq 'Green'
end
describe '.all' do
it 'starts as an em... | true |
7355bf211bd1c33f08d18d9cf6008a260a497e81 | Ruby | stridera/wellington | /app/models/membership.rb | UTF-8 | 2,951 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# Copyright 2020 Matthew B. Gray
#
# 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 applica... | true |
82a0e7b782017dc6aaea4ecbad5cb4ae1562d6a9 | Ruby | Eschults/food-delivery | /app/repositories/orders_repository.rb | UTF-8 | 1,320 | 3.078125 | 3 | [] | no_license | require "csv"
require_relative "../models/order"
require_relative "base_repository"
class OrdersRepository < BaseRepository
attr_reader :employees_repository, :customers_repository, :meals_repository
def initialize(csv_file, employees_repository, customers_repository, meals_repository)
@employees_repository =... | true |
e8c90b96fc4aa16776f4055bd03b6756e85abb10 | Ruby | domw30/Learn-To-Program-Chris-Pine | /Ch5-CenterString.rb | UTF-8 | 550 | 3.0625 | 3 | [] | no_license | lineWidth = 50
puts( 'Old Mother Hubbard'.center(lineWidth))
puts( 'Sat in her cupboard'.center(lineWidth))
puts( 'Eating her curds an whey,'.center(lineWidth))
puts( 'When along came a spider'.center(lineWidth))
puts( 'Which sat down beside her'.center(lineWid... | true |
6eb9028c27eb6f83c5d05cbb10e4889b437e0d68 | Ruby | vin-droid/Airport-Fuel-Inventory-Solution | /functional_spec/spec/airport_fuel_inventory_spec.rb | UTF-8 | 1,795 | 2.625 | 3 | [
"MIT"
] | permissive | require 'singleton'
require "./bin/airport_fuel_inventory_system.rb"
RSpec.describe AirportFuelInventorySystem do
let(:airport_fuel_inventory){AirportFuelInventorySystem.instance}
let(:fuel_quantity){200000}
let(:airport_id){3}
let(:aircrapt){Aircraft.new('6E-102')}
before do
Singleton.__init__(AirportFuelInven... | true |
b7c04d26bc491c1ca6b5aea65f6a4beb73bd2699 | Ruby | cariaso/smwcon2012bots | /lang/ruby/bot1.rb | UTF-8 | 4,341 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
#########################################
#
# Read more at
#
# http://github.com/jpatokal/mediawiki-gateway
#
#########################################
#
# comment out 'private' in mediawiki-gateway/lib/media_wiki/gateway.rb line 563
# since the standard version makes make_api_request() inaccessible... | true |
04bea365d35c5e5b7203abc7b507880842c48cd1 | Ruby | AJFaraday/sand_fall | /lib/row.rb | UTF-8 | 269 | 3.296875 | 3 | [
"MIT"
] | permissive | class Row
attr_reader :cells
def initialize(width, row_number, grid)
@width = width
@grid = grid
@cells = []
@width.times do |cell_number|
@cells << Cell.new(cell_number, row_number, grid)
end
end
def [](x)
@cells[x]
end
end
| true |
44792f7c52b1aa691ab3e7e6c4a0a52ada078a42 | Ruby | tannerwelsh/code-training | /web-dev/dev_bootcamp/RubyProjects/sudoku/sudoku_v2.rb | UTF-8 | 3,817 | 3.3125 | 3 | [
"MIT"
] | permissive | require 'rspec'
module Sudoku
class Puzzle
attr_reader :rows, :columns, :boxes
attr_accessor :board
def initialize(board)
@board = board.split(//)
self.format
end
def format
self.reset
@board.each.with_index do |value, cell|
@rows[row_id(cell)][cell % 9] = val... | true |
499313fa64f2f2c6181c7d19739379cf3cf7a537 | Ruby | necocen/nand2tetris | /njc/VMWriter.rb | UTF-8 | 755 | 3.296875 | 3 | [] | no_license | class VMWriter
def initialize(file)
@file = file
end
def writePush(segment, index)
@file.puts "push #{segment} #{index}"
end
def writePop(segment, index)
@file.puts "pop #{segment} #{index}"
end
def writeArithmetic(command)
@file.puts "#{command}"
end
def writeLabel(label)
@fil... | true |
7e7ce1af48252f8e28ea4590414e8e94624ff7cd | Ruby | JeremyVe/game_of_life | /spec/models/cells_spec.rb | UTF-8 | 6,402 | 3.03125 | 3 | [] | no_license | require 'rails_helper'
describe Cells do
context '#create_cell' do
cell = {'x'=>5, 'y'=>4, 'color'=>[2,3,4]}
result = Cells.new.send(:create_cell, cell)
it 'should return a cell' do
expect(result).to eq({'x' => '5', 'y' => '4', 'color' => [2,3,4]})
end
end
context '#get_new_color' do
c... | true |
8395f7217937da2822f2a6fb58e4bb10b8457132 | Ruby | bcoffin9/ruby-chess | /lib/chess/pieces/knight.rb | UTF-8 | 411 | 3.1875 | 3 | [
"MIT"
] | permissive | require_relative "piece.rb"
class Knight < Piece
def initialize(color)
img = color == "white" ? "\u2658" : "\u265e"
moves = [
[1,2], # x y
[2,1],
[2,-1],
[1,-2],
[-1,-2],
[-2,-1],
[-2,1],
[-1,2]
... | true |
8e49025695df02f68a73a6dfb4c3a1bf0e68edd1 | Ruby | williamsjs/guessing_game | /guessing_game.rb | UTF-8 | 970 | 4.125 | 4 | [] | no_license | require 'date'
def guessing(guess)
new_milli = DateTime.now.strftime('%s').to_i.to_s
milli_array = new_milli.split('')
random_num = milli_array[8] + milli_array[9]
random_num = random_num.to_i
count = 0
hot_or_cold(guess, random_num, count)
end
def hot_or_cold(guess, random_num, count)
guessed_nums = []... | true |
ddb1459b82bf3e0e3539aa2a12f0904f105891b8 | Ruby | simplay/word_suggestor | /lib/core_extensions/array.rb | UTF-8 | 531 | 2.984375 | 3 | [
"MIT"
] | permissive | class Array
def levenshtein_suggestions(input, options={})
global_min_distance = options[:treshold] || WordSuggestor::DEFAULT_TRESHOLD
suggestion_tuples = []
self.each do |s|
next unless s.is_a?(String)
d = s.levenshtein_distance input
tuple = WordSuggestor::Tuple.new(d, s)
su... | true |
dceb01d0d0cd6efb07fd7903ac8afc5f795bceb0 | Ruby | stevemcquaid/trailerapp | /app/helpers/application_helper.rb | UTF-8 | 204 | 2.515625 | 3 | [] | no_license | module ApplicationHelper
#standard date for the app
def time(d)
d.strftime("%I:%M%p")
end
def date(d)
d.strftime("%m/%d/%y")
end
def date_and_time(d)
[date(d), time(d)].compact.join(" ")
end
end
| true |
41a64ab37552f8271dc9f9fb1f5bef80d1e9d0bd | Ruby | Btate712/pokemon-scraper-online-web-sp-000 | /lib/pokemon.rb | UTF-8 | 644 | 3.171875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_accessor :id, :name, :type, :db, :hp
@@all = []
def initialize(arguments)
arguments.each { |key, value| self.send(("#{key}="), value) }
@@all << self
end
def self.save(name, type, db)
db.execute("INSERT INTO pokemon (name, type) VALUES (?, ?)", [name, type])
end
def self.... | true |
a9b361c5f93805b5ac5aa1c1b8a14d7461217456 | Ruby | yasmim-cieb/geos-backend | /app/models/school_regionals_search.rb | UTF-8 | 863 | 2.75 | 3 | [] | no_license | class SchoolRegionalsSearch
attr_accessor :state, :city, :type
attr_reader :schools
def initialize(query: nil, sort_field: nil, sort_direction: nil, state: nil, city: nil, page: nil, type: nil, limit: nil)
@schools = School
@state = state
@city = city
@type = type
filter_by_type
filter_b... | true |
32e20867300d25764169bd4736583716eb652af7 | Ruby | tobico/openaustralia2 | /config/initializers/time_formats.rb | UTF-8 | 649 | 2.875 | 3 | [] | no_license | # Used for date formatting in OpenAustralia
# has form: 18 November 2008
Date::DATE_FORMATS[:simple] = lambda {|date| date.strftime("#{date.day} %B %Y")}
Date::DATE_FORMATS[:simple_with_day] = lambda {|date| date.strftime("#{Date::DAYNAMES[date.wday]}, #{date.day} %B %Y")}
Date::DATE_FORMATS[:simple_short] = lambda {|d... | true |
b1e5e1e3489e7d8c5f3b93a6b483b73653c8a4af | Ruby | mdb/times_grapher | /spec/models/times_query_collection_spec.rb | UTF-8 | 1,537 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe TimesQueryCollection do
before :each do
ENV.stub(:[]).and_return 'API_KEY'
end
subject { times_query_collection }
let(:times_query_collection) { described_class.new(['bush', 'gore']) }
describe '#erms' do
subject { times_query_collection.terms }
it { should eq ... | true |
4895927024d9edff67b41cdff95377fb6a4eda6e | Ruby | wizzywit/Ruby-Training-Session | /Quest03/ex05/college_course_average.rb | UTF-8 | 881 | 4.09375 | 4 | [] | no_license | =begin
function whch take a hash with all marks for a test and returns average mark
for the test
=end
def class_average(class_results)
# sum to hold the sum of values
sum = 0
# validate if it is a valid hash passed
if !class_results.is_a? Hash
print "Pass in a hash value"
retur... | true |
47bc6053506e181e76f9f62a0250a42442b85adf | Ruby | Svawek/thinknetica | /lesson_7/route.rb | UTF-8 | 330 | 3.3125 | 3 | [] | no_license | class Route
include InstanceCounter
attr_reader :stations
def initialize(station_first, station_last)
@stations = [station_first, station_last]
register_instance
end
def add_station(station)
self.stations.insert(-2, station)
end
def remove_station(station)
self.stations.delete(station)
... | true |
9772a193f609c7bc154ba30ef32e62bb5dfa8554 | Ruby | ignazioc/QuizletNerdClient | /lib/QuizletNerdClient/preference_manager.rb | UTF-8 | 1,269 | 2.546875 | 3 | [
"MIT"
] | permissive |
class PreferenceManager
include Singleton
def settings_file
"#{Dir.home}/.qnc.conf"
end
def reset
File.delete(settings_file) if File.exist?(settings_file)
end
def store(settings)
File.open(settings_file, 'w') do |file|
file.write(settings.to_yaml)
end
end
def store_preferences... | true |
c7ce6267c87aca80e3c5caf5a1c087eba7e0c012 | Ruby | piotrmurach/github_cli | /lib/github_cli/ui.rb | UTF-8 | 964 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
require 'forwardable'
module GithubCLI
# Class responsible for displaying different level information
class UI
extend Forwardable
def_delegators :@prompt, :ask, :mask, :suggest
def initialize(prompt)
@prompt = prompt
@quite = false
@debug = ENV['DEBUG'... | true |
f55c44f8feac0b6446155d4aed82687972febb65 | Ruby | kevinnio/crowd_exercises | /palindromes/lib/strategies/palindrome_strategy.rb | UTF-8 | 583 | 3.53125 | 4 | [] | no_license | # encoding: utf-8
# Palindrome generation algorithm.
# This strategy creates a palindrome by sorting the string's chars
# and split them in two strings.
class PalindromeStrategy
def generate(string)
chars = string.chars.sort
isolated_char = chars.select { |c| chars.count(c).odd? }.uniq.join
chars.delete_... | true |
d2f760d649ef39e6207cc5197c759b6bbac8b9a7 | Ruby | jcarlosgarcia/porter-stemmer | /test/test_stemmer.rb | UTF-8 | 717 | 3.03125 | 3 | [] | no_license | require 'minitest/autorun'
require 'porter-stemmer'
class StemmerTest < MiniTest::Test
include Porter
def setup
@input = File.read('test/input.txt')
@expected_output = File.read('test/output.txt')
end
def test_stem
input = @input.split(/\W+/)
expected = @expected_output.split(/\W+/)
inp... | true |
6f0836313acd8c0d251b27614ec75e9a32cac0e9 | Ruby | JyCyunMe/rails5_mall_demo | /app/models/cart.rb | UTF-8 | 574 | 2.796875 | 3 | [] | no_license | class Cart < ApplicationRecord
# 一对多关联,销毁自身时删除所有关联项
has_many :cart_items, :dependent => :destroy
# 添加商品,累加数量
def add_product(product)
current_item = cart_items.find_by(product_id: product.id)
if current_item
current_item.count += 1
else
current_item = cart_items.build(product_id: produc... | true |
8e318e11ae8a253551a9c6f92e98702a8744852b | Ruby | Gnuside/infobipapi | /test/test.rb | UTF-8 | 26,021 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | # vim: set sw=4 ts=4 et :
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'minitest/autorun'
require 'infobipapi/client'
API_USERNAME = ENV["API_USERNAME"]
API_PASSWORD = ENV["API_PASSWORD"]
if (API_USERNAME.nil? || API_USERNAME == '') || (API_PASSWORD.nil? ... | true |
19f50f057aff12f580ef2d88e03063a9cd2c9599 | Ruby | itggot-ludvig-pennert/standard-biblioteket | /lib/min_of_three.rb | UTF-8 | 438 | 4.4375 | 4 | [] | no_license | # Public: Compare three numbers and return the smallest
#
# n1 - The first number to be compared.
# n2 - The second number to be compared.
# n3 - The third number to be compared.
#
# Examples
# min_of_four('4', '5', '6')
# # => '4'
#
# Returns the smallest number
def min_of_three(n1, n2, n3)
smallest = n1
... | true |
8ac5c5da103c9647582e3a29db8dc61b7d063529 | Ruby | kevinladkins/playlister-sinatra-v-000 | /app/models/genre.rb | UTF-8 | 319 | 2.578125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre < ActiveRecord::Base
has_many :song_genres
has_many :songs, :through => :song_genres
has_many :artists, through: :songs
def slug
slug = self.name.downcase.strip.gsub(' ', '-')
slug
end
def self.find_by_slug(slug)
genre = self.all.detect {|s| s.slug == slug}
genre
end
end
| true |
5f7c7bbef3633aae7cf19e801b69a0f23fcc83c1 | Ruby | mjester93/ice-cream-app-backend | /app/models/store.rb | UTF-8 | 451 | 2.578125 | 3 | [] | no_license | class Store < ApplicationRecord
has_many :reviews
has_many :favorite_stores
has_many :ice_cream_stores
has_many :ice_creams, through: :ice_cream_stores
def ice_cream_count
return self.ice_creams.count
end
def avg_rating
if self.reviews.count != 0 then
return... | true |
5c39fff3c586670de373a8dd098284244d5c066f | Ruby | adnanpirota/echopirota | /app/workers/matching_worker.rb | UTF-8 | 2,266 | 2.859375 | 3 | [] | no_license | require 'json'
class MatchingWorker
include Sidekiq::Worker
def perform(file_name, radio_id)
# We execute the shell command to get the echoprint codegen
cmd = `echoprint-codegen #{file_name}`
data = JSON.parse(cmd)
# we extract the fingerprint
fp_code = data[0]['code']
track_id = does_... | true |
b5b5651acb451e6d02081e92505c491cc46a3d16 | Ruby | maryrosecook/playmarymixtape | /app/models/file_upload.rb | UTF-8 | 2,758 | 2.703125 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../../config/boot'
class FileUpload < ActiveRecord::Base
has_one :track
FILE_DIRECTORY = "public/mp3s/"
HTTP_OK_CODE = "200"
MIN_FILE_LENGTH = 100000
def file=(file_field)
self.save_content_and_upload(file_field.original_filename, file_field.read)
self
end... | true |
bde431eca8dc3ae901f5f82aff542a29bb7c5d12 | Ruby | fanjieqi/LeetCodeRuby | /1201-1300/1217. Play with Chips.rb | UTF-8 | 320 | 3.09375 | 3 | [
"MIT"
] | permissive | # @param {Integer[]} chips
# @return {Integer}
def min_cost_to_move_chips(chips)
positions = chips.inject({}) { |hash, position| hash.merge(position => hash[position].to_i + 1) }
positions.keys.map do |i|
positions.inject(0) do |sum, (j, count)|
sum += (j-i).abs.odd? ? 1 * count : 0
end
end.min
end
| true |
c308f214ac6b29c1be5618cf67ad7db9d6a949ef | Ruby | acltc/vg_tools | /lib/helper_tools/update_map.rb | UTF-8 | 701 | 3.09375 | 3 | [
"MIT"
] | permissive | module UpdateMap
def reset_screen
print "\e[2J\e[H"
end
def reset_map
self.presenting_map = dup_map
end
def place_character(alt_map=nil)
if alt_map
alt_map[current_square[0]][current_square[1]] = character
else
presenting_map[current_square[0]][current_square[1]] = character
... | true |
65010336b429ec40e93f9050b9c86a1f284163bf | Ruby | Harritone/Thinknetica | /lesson_4/lib/dialogs/train_routes_management_dialog.rb | UTF-8 | 988 | 3.078125 | 3 | [] | no_license | require_relative 'dialog'
# require_relative 'station'
class TrainRoutesManagementDialog < Dialog
private
def get_input
@current_choice = nil
@current_route = nil
@current_train = nil
clear
show_dialog_name 'Train routes management dialog'
puts 'Here you can set route to train.'
show_... | true |
15a1a72775b7b90f316f3e2b0007e831b158d35a | Ruby | Colex/trojan-rb | /lib/trojan/spy.rb | UTF-8 | 1,064 | 3.109375 | 3 | [] | no_license | module Trojan
class Spy
DEFAULT_CALL_STRATEGY_VALUE = [nil]
attr_reader :calls
def initialize(obj, method_name)
@hooked = false
@object = obj
@method_name = method_name
@original_method = @object.method(method_name)
@calls = []
@call_s... | true |
6086811ac944092d76f29d4f0fdf86f509d0d366 | Ruby | BuonOmo/brawlstats | /main.rb | UTF-8 | 666 | 2.765625 | 3 | [] | no_license | # frozen_string_literal: true
require "json"
require_relative "lib/brawl_api"
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkaXNjb3JkX3VzZXJfaWQiOiIzMTk" \
"zMjMwOTcxNjM0OTc0NzIiLCJyZWFzb24iOiJQZXJzb25uYWwiLCJ2ZXJzaW9uIjoxLCJ" \
"pYXQiOjE1NjkwODc0NTh9.UNR49QnwwHcFA85vyDwGYrE_9cD4VsAbzNvIUxK_gXE"
b... | true |
b8c61097d08b42a426689b37efa58076ff3d1db1 | Ruby | danbernier/zombie_scout | /lib/zombie_scout/flog_scorer.rb | UTF-8 | 577 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | require 'flog'
module ZombieScout
class FlogScorer
def initialize(zombie, flog=nil)
@zombie = zombie
@flog = flog || Flog.new(methode: true, quiet: true, score: false)
end
def score
raw_score.round(1)
end
private
attr_reader :flog
def raw_score
all_scores = flo... | true |
1aa3773dd6797092b7c71f9239d50461044f7a48 | Ruby | atduskgreg/slipcover | /lib/slipcover.rb | UTF-8 | 849 | 3.046875 | 3 | [] | no_license | class Slipcover
attr_accessor :silenced_errors, :members
def initialize(members)
@members = Array(members)
@silenced_errors = []
end
def add_member member
@members << member
end
def remove_member(member=nil, &block)
@members.delete(member) if member
@members.reject!{ |m| block.cal... | true |
f77e9209fab844606f88c79052cf0da2fbc60e09 | Ruby | rubygitflow/thinknetica_ruby | /first_lesson/idial_weight.rb | UTF-8 | 712 | 4 | 4 | [] | no_license | load 'ex_routines.rb'
def result(name, height)
weight = ((height - 110) * 1.15).round(1)
if weight < 0.0
puts "#{name}. Ваш вес уже идеальный"
else
puts "#{name}. Ваш вес: #{weight}"
end
end
def dialogue(name)
print 'Ваш рост в сантиметрах: '
height = gets.chomp
if check_exit(height)
puts ... | true |
55bec626a05f5277fdceeb57c2c5aeb6232afb19 | Ruby | Aaron-McD/connect-four | /lib/game.rb | UTF-8 | 4,357 | 3.765625 | 4 | [] | no_license | require_relative "board.rb"
class Game
attr_reader :board, :winner
def initialize(symbol1, symbol2)
@symbol1 = symbol1
@symbol2 = symbol2
@board = Board.new
@winner = nil
@previous_pos = []
@rounds = 0
@previous_player = nil
@current_player = @sym... | true |
b4845da326bbd7df483b242bceb38b42e27cdd45 | Ruby | alabamaair/thinknetica | /Lesson2/2.rb | UTF-8 | 70 | 3.265625 | 3 | [] | no_license | array = []
i = 10
while i <= 100
array << i
i += 5
end
puts array | true |
6253fd86361cf66c22e1e0ce7d8017004b0125d1 | Ruby | lmaths/RailsApi---APS | /app/models/skill.rb | UTF-8 | 718 | 2.71875 | 3 | [] | no_license | class Skill < ApplicationRecord
belongs_to :character
validates :name, presence: true
validates_inclusion_of :ability, in: [ "strength","dexterity", "constitution","intelligence","wisdom" ,"charisma"], presence: true
def get_atributo
if Character.column_names.include?self.ability
sel... | true |
a1b26a185fe0f0523714ed33ef553d53c6c77517 | Ruby | louispellerin/afloat-budget | /budget/test/unit/period_test.rb | UTF-8 | 2,066 | 2.75 | 3 | [] | no_license | require 'test_helper'
class PeriodTest < ActiveSupport::TestCase
test "the transactions sum is correctly calculated" do
period = Period.new(:start_date => Date.today, :end_date => Date.today)
period.transactions.build(:description => "description", :date => Date.today, :amount => BigDecimal("30"))
period.transact... | true |
67306a7c3790632f1fd9911cef18869880073dcb | Ruby | edpaget/mini_tarball | /lib/mini_tarball/header_writer.rb | UTF-8 | 2,189 | 2.734375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module MiniTarball
class HeaderWriter
def initialize(io)
@io = io
end
def write(header)
write_long_name_header(header) if has_long_name?(header)
@io.write(to_binary(header))
end
private
def to_binary(header)
values_by_field = {}
... | true |
603137207a73644e30b5f1f4fe13bfdd507d1919 | Ruby | ketan/dmon | /lib/dmon/proc_or_object.rb | UTF-8 | 956 | 2.890625 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2011 Ketan Padegaonkar.
# Licenced under the MIT License (http://www.opensource.org/licenses/mit-license.php)
module Dmon
# Use in place of +attr_accessor+ that can use return values of procs
# class Person
# include Dmon::ProcOrObject
# proc_or_object :name
# end
#
# p =... | true |
f4c8ae202b8521b76e95b9d3aac427201aa03add | Ruby | carlosjhr64/helpema | /test/tc_ssss | UTF-8 | 675 | 2.625 | 3 | [
"MIT"
] | permissive | #! ruby
require 'test/unit'
require 'helpema'
class TestSSSS < Test::Unit::TestCase
def test_ssss
pwds = Helpema::SSSS.split(secret: 'MyTopSecretPassphrase', threshold: 3, shares: 6)
assert_equal 6, pwds.length
secret1 = Helpema::SSSS.combine(secrets: pwds.shuffle, threshold: 3)
secret2 = Helpema::SS... | true |
a5dcb5a07855070f81b172613fc61a6915fd6786 | Ruby | cdsandoval/codeable-exercises-wk2 | /cat/cat.rb | UTF-8 | 278 | 2.875 | 3 | [] | no_license | require 'http'
require 'json'
# API text
response = HTTP.get('https://cat-fact.herokuapp.com/facts/random')
hash = JSON.parse(response)
puts hash["text"]
#API img
response_img = HTTP.get('https://aws.random.cat/meow')
hash_img = JSON.parse(response_img)
puts hash_img["file"]
| true |
c925e382d5c9204e3fc61a91e362cf3a639b4055 | Ruby | jweissman/vico | /lib/vico/cli.rb | UTF-8 | 2,196 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'thor'
require 'vico'
module Vico
module Name
def self.generate!
adjs = %w[ wooly wild weird wonderful wannabe weeping whataboutist waxy wheeling warlike ]
nouns = %w[ wallaby walrus warthog whale wasp narwhal wildebeest wondertron willow winterbear ]
[ adjs.sample, nouns.sample ].join(... | true |
59f716a23dbcb14b5fed3f035fc36d7312c66ac1 | Ruby | georgeredinger/CoffeeStatus | /get_current.rb | UTF-8 | 411 | 2.828125 | 3 | [] | no_license | require "serialport"
port_str = "/dev/ttyUSB0"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
series=[]
done=false
until done
currents=sp.gets
unless currents.nil?
a,b = currents.split
if a == b
puts "... | true |
d14d42493c7712e75f77390515fc2005dc60ed32 | Ruby | nathanworden/RB130-Ruby-Foundations-More-Topics | /04.Studying With Other Students/43.120319_juliette_siny.rb | UTF-8 | 3,126 | 4.46875 | 4 | [] | no_license | # Juliette gave me this problem she found on leetcode.
# She said it was a easy or medium level problem.
# Given a string, find the length of the longest substring without repeating characters.
# Example 1:
# Input: "abcabcbb"
# Output: 3
# Explanation: The answer is "abc", with the length of 3.
# Example 2:
# I... | true |
ff4eca87c9724b0c1960faf31f92642fe62b9efb | Ruby | darvs/advent-of-code | /2018/1805.rb/lib/1805.rb | UTF-8 | 712 | 2.984375 | 3 | [] | no_license | def parse(line, skip = nil)
head = []
tail = line.chars
until tail.empty?
if !skip.nil? && skip.casecmp?(tail[0])
tail.shift
elsif head.empty?
head = [tail.shift]
elsif head[-1].swapcase == tail[0]
head.pop
tail.shift
else
head.concat([tail.shift])
end
end
... | true |
a919b02f4ff682aaaf2790881f4ecdee991a62f6 | Ruby | agc/aplicacionesrails | /tutorialruby/basico/ejcadena1_spec.rb | UTF-8 | 1,303 | 3.0625 | 3 | [] | no_license | require_relative "ejcadena1.rb"
require_relative 'spec/spec_helper'
#require File.expand_path("../ejcadena1.rb", __FILE__)
describe "Operaciones basicas con Strings" do
subject {"Hola mundo"}
its(:length) {should == 10}
it "Las cadenas se pueden concatenar" do
subject.should eq("Hola... | true |
e41550ee05f44d9aa4ead133c5dfd266484c6720 | Ruby | njonsson/cape | /lib/cape/dsl.rb | UTF-8 | 7,824 | 3.09375 | 3 | [
"MIT"
] | permissive | require 'cape/capistrano'
require 'cape/rake'
module Cape
# Provides methods for integrating Capistrano and Rake.
module DSL
# Enumerates Rake tasks.
#
# @param [String, Symbol] task_expression the full name of a task or
# namespace to filter
# @param [... | true |
087169f12c4e5bc787e52897e2ec2256268ff58f | Ruby | sergii/daily-ruby-tips | /130/struct_values_as_hash.rb | UTF-8 | 794 | 4.15625 | 4 | [] | no_license | # Class Struct includes enumerable so we get a little more than a normal Class.
# Today's example shows the output of our attributes
Course = Struct.new(:name, :student_ids)
@struct = Course.new("Eastern Art History", [23, 456, 2342, 221, 3, 45, 987])
@struct.each_pair { |name, value| p("#{name} => #{value}") }
#=> "n... | true |
06e02df503c72a81dfc0e191cff989bc41210f23 | Ruby | PiotrWald/Sinatra | /hangman.rb | UTF-8 | 2,398 | 3.171875 | 3 | [] | no_license | require 'sinatra'
require "sinatra/reloader" if development?
require 'sass'
require 'set'
get('/styles.css'){scss :styles}
#Caesar class used to encode a string
@@ciphered = ""
class Caesar
def encode_string(my_string, shift_value)
shift_value %= 26
for i in 0..my_string.size-1 do
if my_string[i].ord > 122... | true |
0c1c73a99f2c3c38e545cdc51c59ee9783cab1fd | Ruby | weicool/weitracer | /shape.rb | UTF-8 | 1,252 | 3.234375 | 3 | [] | no_license | require 'utilities'
require 'ray'
class Shape
attr_reader :brdf
def initialize(brdf, transform)
@brdf = brdf
@transform = transform
end
def intersect(ray)
nil
end
end
class Sphere < Shape
def initialize(center, radius, brdf, transform)
super(brdf, transform)
@center = center
... | true |
b1999ad235b8c828e34b7bfa1a35880a26e18d48 | Ruby | designedbyscience/Pinboard.in-Adium-Script | /pinboardurl.rb | UTF-8 | 1,104 | 2.59375 | 3 | [] | no_license | #!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'net/https'
require 'uri'
require 'cgi'
require 'nokogiri'
require 'open-uri'
#sender found at ARGV[0]
#message found at STDIN
#Pull out url
message = STDIN.read.strip
foundurl = URI.extract(message)[0]
if foundurl
#Get page title
page =... | true |
754652528c8e2bc0776c24c3c2c65ad56e70efbf | Ruby | ocpsoft/rewrite | /transform-markup/src/main/resources/ruby/sass/lib/sass/tree/supports_node.rb | UTF-8 | 1,212 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | module Sass::Tree
# A static node representing a `@supports` rule.
# `@supports` rules behave differently from other directives
# in that when they're nested within rules,
# they bubble up to top-level.
#
# @see Sass::Tree
class SupportsNode < DirectiveNode
# The name, which may include a browser pref... | true |
a4741515e07b9610a1c478b673502a3f0d27bae1 | Ruby | ashishvalu/ruby-1 | /exer1/shop_order.rb | UTF-8 | 2,466 | 3.625 | 4 | [] | no_license | class Order
def initialize
@order ={}
end
def new_order
print "Enter your order:" #date and amount
order = gets.chomp
# date & amount lakhva order ne split karvu pade
date,amount = order.split(' ')
day,month,year = date.split('-')
if @order[year].nil?
@order[year] = {}
end
... | true |
a7e9b40a0f4b2459dec880dc6ffa7b789ac31c4d | Ruby | kinsbrunner/interview-cake-ruby | /10-second-largest-in-bst/spec/binary_tree_node_spec.rb | UTF-8 | 1,232 | 2.859375 | 3 | [] | no_license | require 'spec_helper'
RSpec.describe BinaryTreeNode, type: :model do
describe "#get_second_largest method" do
let(:btree1){
root = BinaryTreeNode.new(5)
second_level_a = root.insert_left(3)
second_level_b = root.insert_right(8)
third_level_a = second_level_a.insert_left(1)
third_le... | true |
40c6e38d12023c85893543b645c8eaf626cae368 | Ruby | TommyTeaVee/critter4us | /test/end-to-end/taking-out-of-service-tests.rb | UTF-8 | 2,359 | 2.515625 | 3 | [] | no_license | require './test/testutil/requires'
require 'capybara'
class TakingOutOfServiceTestCase < EndToEndTestCase
def setup
super
Procedure.random(:name => 'venipuncture')
Procedure.random(:name => 'physical', :days_delay => 3)
Animal.random(:name => 'veinie')
Animal.random(:name => 'bossie')
... | true |
01ad7dc3f2e9ebb7831cfec2b3431b1a7fda9232 | Ruby | theinterned/faq_engine | /test/unit/faq_test.rb | UTF-8 | 896 | 2.609375 | 3 | [] | no_license | require 'test/test_helper'
class FaqTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
test "faq should save wiht question and answer provided" do
faq = Faq.new(:question => "What?", :answer => "I don't know!")
assert faq.save
end
test ... | true |
86b339ad4c5b3a15a496881dcd54842879b5c931 | Ruby | davidhu2000/coursework | /w2d3/poker/lib/player.rb | UTF-8 | 1,239 | 3.640625 | 4 | [] | no_license | require_relative 'hand'
class Player
attr_reader :name, :hand, :folded
attr_accessor :chips
def initialize(name, chips)
@name = name
@hand = Hand.new
@chips = chips
@folded = false
end
def get_discard
# puts "Enter in the suit and card value that you want to discard: "
suit, value =... | true |
8d0de1372e65c4e4270a29304cac0a0e413e5356 | Ruby | bstiber/launch_school_exercises | /small_problems/easy4/1.rb | UTF-8 | 1,317 | 4.84375 | 5 | [] | no_license | # Write a method that takes two strings as arguments, determines the longest of the two strings, and then
# returns the result of concatenating the shorter string, the longer string, and the shorter string once
# again. You may assume that the strings are of different lengths.
# using my method
def short_long_short(s... | true |
f5384d65a6a57abc57cbd02b367bec2173deda4a | Ruby | qwaszx102938/smaile-remember | /app/services/memory_service.rb | UTF-8 | 2,029 | 2.75 | 3 | [] | no_license | =begin
第一个记忆周期是 5分钟
第二个记忆周期是30分钟
第三个记忆周期是12小时
这三个记忆周期属于短期记忆的范畴。
下面是几个比较重要的周期。
第四个记忆周期是 1天
第五个记忆周期是 2天
第六个记忆周期是 4天
第七个记忆周期是 7天
第八个记忆周期是15天
=end
class MemoryService
#下一级间隔时间(秒)
@@alert_list=[
#0-1
5*60,
#1-2
25*60,
#2-3
11.5*60*60,
... | true |
a77f916f56c144fcd0ceec3e71d0a1538a2c7109 | Ruby | Carriane/Image123 | /image.rb | UTF-8 | 259 | 3.46875 | 3 | [] | no_license | class Image
def initialize(row)
@row = row
end
def output_image
@row.each do |cell|
puts cell.join
end
end
end
image = Image.new([
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]
])
image.output_image
| true |
9e601eb89ae597aa016055108ebf05f4ccbdc5c5 | Ruby | ursmartini/webserver-mock | /webserver.rb | UTF-8 | 1,747 | 2.625 | 3 | [
"MIT"
] | permissive | def add_headers(res, headers)
headers.each_pair { |key, val| res[key] = val }
res
end
def echo(req)
body = "#{req.request_line}\n"
req.raw_header.each { |header| body += "#{header.strip}\n" }
body += "\n#{req.body}"
body
end
require 'webrick'
if ENV['allow_http_verbs']
module WEBrick
module HTTPSer... | true |
4d9add27d01410556a37f104d611426feeb70aeb | Ruby | lsamano/key-for-min-value-dumbo-web-121018 | /key_for_min.rb | UTF-8 | 378 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # prereqs: iterators, hashes, conditional logic
# Given a hash with numeric values, return the key for the smallest value
def key_for_min_value(name_hash)
current_minimum = nil
minimum_key = nil
name_hash.each do |name, value|
if current_minimum == nil || value < current_minimum
current_minimum = value... | true |
b8bde3592fcf9bed8f60c1cc8d5c681a870726a9 | Ruby | BaltimorePublicArtCommons/baltimore_public_art_commons | /app/models/importers/csv/image_creator.rb | UTF-8 | 1,260 | 2.5625 | 3 | [] | no_license | module Importers
class Csv::ImageCreator
def self.create_item_images_from_row(item, row, image_file_path)
return if image_file_path.nil?
self.new.create_item_images_from_row(item, row, image_file_path)
end
def create_item_images_from_row(item, row, image_file_path)
image = create_item_i... | true |
5045b8a4aac6319a445a48b7b6db42958bb6c7d1 | Ruby | NREL/OpenStudio-analysis-spreadsheet | /measures/LifeCycleCostReport/resources/os_lib_reporting_custom.rb | UTF-8 | 5,290 | 2.984375 | 3 | [] | no_license | require 'json'
module OsLib_Reporting
# setup - get model, sql, and setup web assets path
def self.setup(runner)
results = {}
results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets')
return results
end
# developer notes
# - Other thant the 'setup' sect... | true |
165234817f4337cd83675fea2a6b44591c402d6b | Ruby | sul-dlss/stacks | /app/models/approved_location.rb | UTF-8 | 649 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
###
# Simple class that will return an approved location (for restricted content)
# based on a provided locatable object's IP address
class ApprovedLocation
delegate :to_s, to: :location_for_ip
def initialize(locatable)
@locatable = locatable
end
def locations
return [] u... | true |
239d705cf39b4e8fbf172c0a0e0f75aa9f0b6fa7 | Ruby | joeltio/proficiency | /src/proficiency/math/prime_checker/prime_checker.rb | UTF-8 | 256 | 3.75 | 4 | [
"MIT"
] | permissive | def prime_checker(n)
if n < 2
false
elsif n == 2
true
elsif n % 2 == 0
false
else
for i in (3..n).step(2)
if n % i == 0
return false
end
end
true
end
end
puts prime_checker(ARGV[0].to_i)
| true |
34b69b997700300ce20a01785d7df5df6f62558c | Ruby | abarnes1/ruby-exercises | /data-structures/linked-list/linked_list.rb | UTF-8 | 2,766 | 3.578125 | 4 | [] | no_license | require_relative 'node'
class LinkedList
attr_reader :head, :tail
def initialize
@head = nil
@tail = nil
@size = 0
end
def append(value)
if @head.nil?
@head = Node.new(value)
@tail = @head
else
new_tail = Node.new(value)
@tail.next_node = new_tail
@tail = new... | true |
cad42f3ff733b8e5c8d81af3c52457590cb623e3 | Ruby | digibib/bokanbefalinger | /lib/api.rb | UTF-8 | 5,426 | 2.59375 | 3 | [] | no_license | # encoding: UTF-8
# -----------------------------------------------------------------------------
# api.rb - API abstraction
# -----------------------------------------------------------------------------
# The API module is responsible for fetching and pushing resources to the API.
# All methods yields to a block if... | true |
97d180d9c74fe18a45a5f7a81e41256ffdc3243d | Ruby | Ssenkowski/sinatra-mvc-lab-v-000 | /models/piglatinizer.rb | UTF-8 | 1,119 | 3.765625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class PigLatinizer
def piglatinize(word)
alpha = ('a'..'z').to_a
vowels = %w[a e i o u A E I O U]
consonants = alpha - vowels
if vowels.include?(word[0])
word + 'way'
elsif consonants.include?(word[0]) && consonants.include?(word[1]) && consonants.include?(word[2])
wor... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.