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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8a2b3be5625fd5091959ced9f043297801a524dd | Ruby | MrMarvin/rattlcache | /lib/backends/filesystem.rb | UTF-8 | 1,937 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'json'
require 'base64'
module Rattlecache
module Backend
class Filesystem < Cache
def initialize(prefix = "/tmp/rattlecache/")
@prefix = prefix
end
def get(objectKey)
#puts "Filesystem gets you: #{objectKey}"
# get the file from the filesystem
ret = {:... | true |
3da78e8b832e274b417bb1105a7a434f6676f3c0 | Ruby | forksaber/ec2 | /lib/ec2/subnet.rb | UTF-8 | 2,402 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'ec2/helper'
require 'ec2/logger'
module Ec2
class Subnet
include Helper
include Logger
def initialize(name, vpc_id: nil)
error "vpc_id not specified for subnet" if not vpc_id
@vpc_id = vpc_id.to_s
@name = name.to_s
end
def id!
load_id if not @id
error "spe... | true |
7fab66b8d0e406ffe193fee0d1a97c78816c44e9 | Ruby | seielit/figaro | /lib/figaro/settings.rb | UTF-8 | 2,456 | 2.921875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'bigdecimal'
module Figaro
#
# This class should be extended in your own application to provide a higher
# level API for use in your application.
#
# Your app shouldn't use ENV, Figaro.env not Settings#[]. It also shouldn't
# fiddle with data conversion in settings.
... | true |
a64861b348164d71786144df37b574c96b7d6b8d | Ruby | zychmichal/smartflix | /app/adapters/movies/omdb/requests/search_movie_request.rb | UTF-8 | 590 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'uri_omdb_builder'
module Movies
module Omdb
module Requests
class SearchMovieRequest
include UriOmdbBuilder
def search_movies_by_title_and_year(title, year = nil)
request_uri = build_uri_by_search(title, year)
res = Net::... | true |
0e69bd7e383be765ca104141e3b43713e363f98c | Ruby | jklbj/hw_3-credit_card_crypto | /substitution_cipher.rb | UTF-8 | 1,573 | 3.234375 | 3 | [] | no_license | module SubstitutionCipher
module Caesar
# Encrypts document using key
# Arguments:
# document: String
# key: Fixnum (integer)
# Returns: String
def self.encrypt(document, key)
# TODO: encrypt string using caesar cipher
x = document.to_s.each_char.map{|a| a.ord + key }
... | true |
53880a34dfdd393832a76cf6ae6d7b454d418dda | Ruby | MarkFChavez/maokai | /app/models/user.rb | UTF-8 | 642 | 2.625 | 3 | [] | no_license | class User < ActiveRecord::Base
attr_accessible :email, :name, :image, :provider, :uid
validates :email, :name, :image, :provider, :uid, presence: true
#looks on the db for a matching provider & uid, if nothing si found, will create new record
def self.from_omniauth(auth_hash)
where(auth_hash.slice("provid... | true |
e09142af0577d33fc34bae6233cd345c42cc7c7b | Ruby | banurekha/poker_hands | /lib/hand.rb | UTF-8 | 4,792 | 3.515625 | 4 | [] | no_license | # Parser to decode hand and find the rank. It can also compare one hand with other
# frozen_string_literal: true
class Hand
include Comparable
attr_reader :cards
def initialize(array_of_cards)
raise ArgumentError, 'There must be 5 cards' unless array_of_cards.count == 5
card_hashes =
array_of_card... | true |
8f8927942c4486d0e116963cfd755a1d3120816d | Ruby | liamtlr/learn_to_program | /ch14-blocks-and-procs/grandfather_clock.rb | UTF-8 | 259 | 3 | 3 | [] | no_license | def grandfather_clock &block
twenty_hour_time = Time.new.hour
if twenty_hour_time > 12
twelve_hour_time = twenty_hour_time - 12
else
twelve_hour_time = twenty_hour_time
end
twelve_hour_time.times do
puts "DONG!"
end
end
grandfather_clock
| true |
e60ce9c2f3df1813941d219590d80c538f532479 | Ruby | dgriego/code-challenges | /hacker-rank/ruby/sock-merchant.rb | UTF-8 | 2,495 | 3.828125 | 4 | [] | no_license | # integers represent sock colors
#
# this is represented as an array of integers where
# each integer represents an individual sock
#
# large pile of socks that need to be matched, think laundry day.. ugghg that sucks
# ok....fine, I'll pair the sucks
#
# the result should be a count of how many pairs of matching socks... | true |
75c3e9a657ae6e0f098a9add4d554949a21aa611 | Ruby | guppy0356/rspec-receive | /user.rb | UTF-8 | 382 | 2.96875 | 3 | [] | no_license | class User
def initialize(name, age)
@name = name
@age = age
end
def insert
postgresql.insert(attributes)
end
def attributes
{name: @name, age: @age}
end
private
def postgresql
@postgresql ||= PostgreSql.new
end
end
# Postgresql に接続するクライアント
class PostgreSql
def insert(a... | true |
d7fdf5741eac2dcad5effe45d3fb7f4bd7fe9174 | Ruby | hellokenta1024/til | /algorithm/singly-linked-list-check-if-it-contains-circle.rb | UTF-8 | 1,081 | 4.40625 | 4 | [
"MIT"
] | permissive | =begin
You have a singly-linked list ↴ and want to check if it contains a cycle.
A cycle occurs when a node’s @next points back to a previous node in the list. The linked list is no longer linear with a beginning and end—instead, it cycles through a loop of nodes.
Write a method contains_cycle() that takes the first ... | true |
02e650ae4dd2c9ebdceaa9491838224b7ff41100 | Ruby | vpnfpfvl/FBC_rubyTutorial | /CHAPTER04/chapter4-3q06.rb | UTF-8 | 39 | 2.84375 | 3 | [] | no_license | array = [1, 3]
array.unshift 1
p array
| true |
0def8de84d0095848b23527fe888e36acea99631 | Ruby | mstmari/school-domain-v-000 | /lib/school.rb | UTF-8 | 407 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # code here!
require 'pry'
class School
attr_accessor :name, :roster
def initialize(name)
@name = name
@roster = {}
end
def add_student (student_name, grade)
roster[grade] ||= []
roster[grade] << student_name
end
def grade(grade)
roster[grade]
end
def sort
sorted_students = {}
roster.each do ... | true |
c12c001962e5cb46c33ee378768dfe408c941445 | Ruby | phrase/phraseapp-ruby | /test/auth_test.rb | UTF-8 | 1,197 | 2.5625 | 3 | [
"MIT"
] | permissive | require "minitest/autorun"
require 'phraseapp-ruby/auth'
describe PhraseApp::Auth::Credentials do
let(:token) { "123456789" }
let(:username) { "tom" }
let(:password) { "secret-password" }
let(:credentials) {
PhraseApp::Auth::Credentials.new(
token: token,
username: username,
password: ... | true |
52287542d129db17177281774a6e58bdc4f12ea3 | Ruby | yTakkar/Fun-With-Ruby | /strings.rb | UTF-8 | 339 | 3.65625 | 4 | [] | no_license | str = "Hello, World!!"
puts str.size
puts str.include? "H"
puts str.count "!"
puts str.chop
puts str.chomp "!!"
puts str.upcase
puts str.downcase
puts str.delete "ll"
str.each_char { |chr| puts chr }
puts str.start_with?"d"
puts str.end_with?"!!"
puts str.replace "Hello, India!!"
puts str.reverse
str.split(", ").each ... | true |
78d4404d303b09f897e3e760947195056d7feb28 | Ruby | DaFaD/progetto_cyber_challenge | /test/models/user_studente_test.rb | UTF-8 | 6,805 | 2.625 | 3 | [] | no_license | require 'test_helper'
class UserStudenteTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@userStudente = UserStudente.new(name: "Matteo", surname: "Vari", email: "mattew98.01@gmail.com", username: "Mattew98-01", fiscalCode: "VRAMTT98M06C858Y", birthDay: Date.new(1998,... | true |
b59ca62afe5fba2bac72eac67fae70f9f4f79250 | Ruby | Alicespyglass/fizzbuzz | /lib/fizzbuzz.rb | UTF-8 | 206 | 3.484375 | 3 | [] | no_license | def fizzbuzz(number)
# only return fizz if num = 3
if (number % 3 == 0) && (number % 5 == 0)
'fizzbuzz'
elsif number % 3 == 0
'fizz'
elsif number % 5 == 0
'buzz'
else number
end
end
| true |
6a6ebb4bb6c15fe2e62c350dea4ebbda74011037 | Ruby | bitdomo/bs2 | /Scripts/_.50.rb | UTF-8 | 4,096 | 2.9375 | 3 | [] | no_license | #==============================================================================
# ■ RGSS3 誤選択防止処理 Ver1.01 by 星潟
#------------------------------------------------------------------------------
# イベントで選択肢を選ぶ際に
# 選択肢ウィンドウインデックスを-1にし
# そのままでは選択できない状態にします。
# 上下の方向キーを押す事で、はじめて選択可能となります。
# これにより、決定キー連打による誤選択を防止することが出来ま... | true |
3c0f35fe6e2d3d134dbffc90afb99a7398f948c6 | Ruby | NaCl-Ltd/yarunee-2018 | /lib/nanobot/model.rb | UTF-8 | 2,686 | 3.078125 | 3 | [] | no_license | class Nanobot
# 形状データを表すクラス
class Model
# .mdlファイルを読み込む
def self.load(mdl_path)
new(File.binread(mdl_path))
end
# 全マスがVoidなモデルを生成する
def self.empty(resolution)
raise ArgumentError if resolution <= 0
b = "0" * resolution**3
mdl = [resolution].pack("C*") + [b].pack("b*")
... | true |
dc835ca9a0307a60f78590702d172a6577661d85 | Ruby | cdcarter/gingko | /app/models/bracket.rb | UTF-8 | 2,332 | 3.03125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | require 'ostruct'
require 'facets/array'
class Bracket < ActiveRecord::Base
has_many :game_assignments
has_many :games
has_many :bracketings
has_many :teams, :through => :bracketings
has_many :room_assignments
has_many :rooms, :through => :room_assignments
belongs_to :tournament
belongs_to :ph... | true |
46886832f262a70a45bbfe47ecd339d191c9069c | Ruby | skyfox93/week-1-group-review-nyc-web-102918 | /review-question-3.rb | UTF-8 | 1,184 | 3.4375 | 3 | [] | no_license | # begin to build a simple program that models Instagram
# you should have a User class, a Photo class and a comment class
class User
attr_accessor :name
def initialize(name)
@name=name
end
end ##end user class
class Photo
attr_accessor :user
def initialize(user)
@user=user
end
def make_comment(c... | true |
dc5cb81bebf5792e3240094ad318bdcd73c1cbb5 | Ruby | CeliaTHP/Day2 | /exo_07_a.rb | UTF-8 | 148 | 3.09375 | 3 | [] | no_license | puts "Bonjour, c'est quoi ton blase ?"
#récupère la variable user_name, qui sera donnée par l'utilisateur.
user_name = gets.chomp
puts user_name
| true |
395a5901ef89370c47a0ef2899ba9c01e1fe45d0 | Ruby | abbshr/Kedi | /lib/kedi/container.rb | UTF-8 | 933 | 2.671875 | 3 | [
"MIT"
] | permissive | module Kedi
class Container
attr_reader :pipelines
def initialize
# 每个 pipe 按 unique name 装入
@pipelines = {}
end
# 激活所有 pipes
def run
@pipelines.each &:streaming
end
def pause(id = nil)
if id
@pipelines[id]&.pause
else
@pipelines.each &:paus... | true |
7db0470508eab41fb86a591846442a2b9ebe36a0 | Ruby | droptheplot/apipony | /spec/apipony/parameter_spec.rb | UTF-8 | 1,109 | 2.78125 | 3 | [
"MIT"
] | permissive | describe Apipony::Parameter do
let(:parameter) { Apipony::Parameter.new(:name) }
describe '#type' do
it 'returns :string by default' do
expect(parameter.type).to eq(:string)
end
end
describe '#required' do
it 'returns false by default' do
expect(parameter.required).to be false
end
... | true |
ee1154672fc424d3928deb717cd4dd4f5d51cfe6 | Ruby | Rob-rls/geckoboard-techtest | /lib/geckoboard_request.rb | UTF-8 | 869 | 2.78125 | 3 | [] | no_license | require 'geckoboard'
require 'date'
class GeckoboardRequest
def initialize
@client = Geckoboard.client('e70c81cd6610f867dd72bcc56d8b1b47')
check_api_key
load_dataset
end
def update_dataset(weather_data)
@dataset.put(weather_data)
end
private
def check_api_key
puts "API Key is Valid"... | true |
5155ada31007c06e90eee2d1238babbf6f9feb6d | Ruby | emill3000/my-collect-v-000 | /lib/my_collect.rb | UTF-8 | 132 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(collection)
i = 0
list = []
while i < collection.length
list << yield(collection[i])
i += 1
end
list
end
| true |
5d3e9f398e06b2d322a783ceceb661208a13cf29 | Ruby | jaredonline/baconator | /app/models/bacon/array.rb | UTF-8 | 726 | 3.6875 | 4 | [] | no_license | # Special array class for quick insertion of sorted elements
# specifically for sorting BaconNodes by their depth.
# This way we can #shift the first one off the array and be
# confident we're searching from the best position
#
class Bacon::Array < Array
def self.[](*array)
self.new(array)
end
def initializ... | true |
7204ab2eeec26b1b79f66faeee6f0ba85c51145c | Ruby | tiyd-ruby-2016-09/text_miner | /spec/separator_spec.rb | UTF-8 | 5,070 | 3.140625 | 3 | [] | no_license | require 'separator'
describe Separator do
before do
@s = Separator.new
end
describe '#words' do
it 'returns an Array of words' do
expect(@s.words('hello')).to eq ['hello']
expect(@s.words('hello world')).to eq ['hello', 'world']
expect(@s.words('raggggg hammer dog')).to eq ['raggggg', ... | true |
8af3af050c9fba65226f2234ba103069933fe8bb | Ruby | skarger/rails-deadlock-example | /app/models/parallel_mapper.rb | UTF-8 | 480 | 2.71875 | 3 | [] | no_license | # uncommenting will make things work
#require_relative './collaborator_one.rb'
#require_relative './collaborator_two.rb'
class ParallelMapper
def work_in_threads
data = [1, 2, 3]
Parallel.map(data, in_threads: 3) do |item|
ActiveRecord::Base.connection_pool.with_connection do |conn|
puts "Paral... | true |
190f47306c54544a7df5342f0c42a6ced852bbae | Ruby | avinoth/slack-snippet | /app.rb | UTF-8 | 4,592 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'sinatra'
require 'active_support/json/encoding'
require 'json'
require 'sinatra/activerecord'
require './config/environments'
require './models/user'
require './models/snippet'
get '/gateway' do
message = ""
@trigger = params[:command]
@user = User.find_by(slack_user_id: params[:user_id])
if @user... | true |
7fdd438bd79d763a9a093617fd550dd060da173b | Ruby | hyzs25/homework | /ruby/human.rb | UTF-8 | 1,430 | 4.125 | 4 | [] | no_license | #module 理解为一组方法的集合
#include module表示将module里的所有方法都定义成class的instance mathod
module Puruanimal
def blood
'warm'
end
def eat_milk?
true
end
end
module Fish
def blood
'cold'
end
def eat_milk?
false
end
end
class Human
include Puruanimal
attr_accessor :name, :age
attr_read... | true |
0e6e4945a2e9a458a2b50b1612d1e35e64187a4a | Ruby | maedi/ticket_terminal | /helpers/app_helper.rb | UTF-8 | 979 | 2.703125 | 3 | [] | no_license | module AppHelper
# Project path.
@@root = nil
##
# Expose app to components.
#
# @param app [App] The main Sinatra::Base instance.
##
def self.set_app(app)
@@app ||= app
end
##
# Expose session to components.
#
# @param session [Session] The server session.
##
def self.set_session(s... | true |
4f01c4df7a775ecdcffb0d2c8136e5fb9dfa082b | Ruby | paulor8bit/find-the-number | /main.rb | UTF-8 | 4,127 | 3.6875 | 4 | [] | no_license | def boas_vindas
puts
puts " P /_\ P "
puts " /_\_|_|_/_\ "
puts " n_n | ||. .|| | n_n Bem vindo ao "
puts " |_|_|nnnn nnnn|_|_| Jogo de Adivinhação!"
puts " |' ' | |_| |' ' | "
... | true |
8dbda0887fd629c18d9bab166670c7b1a7976fbf | Ruby | flawrencis/CodeLessons | /Basics/RubyBasics/personal_chef.rb | UTF-8 | 1,391 | 3.765625 | 4 | [] | no_license | class PersonalChef
def make_toast(color)
if color.nil?
puts "How am I supposed to do that?!?"
else
puts "Making your toast #{color}"
end
return self
end
def make_eggs(quantity)
quantity.times do
puts "Making an egg."
end
puts "I'm done!"
return self
end
def make_milkshake(flavor)
... | true |
7b720a1522575b7e79b2af9a0867fa321f532a16 | Ruby | eslamelkholy/Ruby-Codewars-Problem-Solving | /17-facebook like system.rb | UTF-8 | 485 | 3.65625 | 4 | [] | no_license | def likes(names)
if (names.length == 0)
return "no one likes this"
elsif (names.length == 1)
return names[0] + " likes this"
elsif (names.length == 2)
return names[0] + " and " + names[1] +" like this"
elsif (names.length == 3)
return names[0] + ", "+ na... | true |
9dc397a926feecb5e04e65ca573c2cf7081db9cb | Ruby | radioactive001/learn_ruby | /06_timer/timer.rb | UTF-8 | 267 | 3.109375 | 3 | [] | no_license | class Timer
attr_accessor :seconds,
def initialize
@seconds=0
end #seconds
def time_string
s=@seconds%60
m=@seconds/60
h=m/60
m=m%60
@time_string="%02d:%02d:%02d" %[h,m,s]
end #time_string
end #class
| true |
10a2c625d8697974fb54161eb950995b7396322a | Ruby | c1505/game-chooser | /app/models/search.rb | UTF-8 | 774 | 2.765625 | 3 | [] | no_license | class Search
# Searches the google api specifically to boardgamegeek.com and returns JSON.
def initialize(query)
@query = query
@api_key = Rails.application.secrets.google_api_key
@url = "https://www.googleapis.com/customsearch/v1?key=#{@api_key}&cx=006396486437962354856:dhkps_7te2y&q=#{@query}"
end
... | true |
5a5649c9b0fec9464b687831063f35be198f0694 | Ruby | Tomistong/Leetcode-Ruby-1 | /hard-ruby/315-count-smaller-numbers-after-self.rb | UTF-8 | 791 | 4.09375 | 4 | [] | no_license | # You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].
# Example:
# Input: [5,2,6,1]
# Output: [2,1,1,0]
# Explanation:
# To the right of 5 there are 2 smaller elements (2 and 1).
# ... | true |
573dc18a1cc19dc43f11f7c025243537d188db7e | Ruby | IceDragon200/mruby-sfml-audio | /docstub/sound_source.rb | UTF-8 | 1,808 | 2.75 | 3 | [] | no_license | module SFML
# Base class defining a sound's properties
class SoundSource < AlResource
# Enumeration of the sound source states
module Status
# @return [Integer]
Stopped = 0
# @return [Integer]
Paused = 1
# @return [Integer]
Playing = 2
end
# @param [Float] pitch... | true |
5b9fe8a1c15bdea6592d6872ca7f7ec6bcb53352 | Ruby | alovak/time_report | /spec/time_report_spec.rb | UTF-8 | 530 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe TimeReport do
describe "#output" do
it "returns tasks with time for each day" do
input = <<-JSON
22.01
10:00 - 11:31 First task 1
11:40 - 12:00 Last task 2
21.01
06:00 - 08:00 First task 3
09:00 - 10:00 Last task 4
JSON
report = TimeReport::Processor.new(input)
... | true |
d10fa963a8d578639c6ab404b3e27d32b16fa990 | Ruby | IsolatePy/Learn-How-To-Code-With-Ruby | /7- Arrays I - Creation, Addition, and Modification/More_With_Array.rb | UTF-8 | 169 | 3.703125 | 4 | [] | no_license | a = [1,2,3,4,5,6,7,8,9,"Ali"]
p a.join
b = a.join("-")
p b.split("-")
#you can write array with %w
z = %w(my name is Ali and this is great Ruby is amazing)
p z
p z[0]
| true |
16450b7c84ac0e790176eff3afe977968836818a | Ruby | coreywhiting/fanfueled | /app/controllers/baseball_matchup_controller.rb | UTF-8 | 4,789 | 2.5625 | 3 | [] | no_license | class BaseballMatchupController < ApplicationController
def index
@first_week = week_range_params[:first] || 1
#TODO find default last week
@last_week = week_range_params[:last] || 99
@stats = [ :runs,
:hr,
:rbi,
:sb,
:obp,
... | true |
e4d5e526a2268fc80a9954858dfe973644fa0a6e | Ruby | jnatalini/problems | /binary_search.rb | UTF-8 | 828 | 4.09375 | 4 | [] | no_license | #!/usr/bin/ruby
require 'byebug'
#Given a sorted array A[] ( 0 based index ) and a key "k" you need to complete the function bin_search to determine the position of the key if the key is present in the array. If the key is not present then you have to return -1. The arguments left and right denotes the left most i... | true |
d6055619995f3298cc7493abe20cfb03e5ecacde | Ruby | ktlacaelel/ix | /bin/ix-files | UTF-8 | 119 | 2.703125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
STDIN.each_line do |line|
fname = line.chomp
if File.exists?(fname)
puts fname
end
end
| true |
826b0f6af5a76f737d5e5a029157ee2b2d775a07 | Ruby | nickell75/phase-0-tracks | /ruby/word_game/word_game.rb | UTF-8 | 3,284 | 4.40625 | 4 | [] | no_license | =begin
# Pseudocode a class for a word-guessing game that meets the following specifications.
create a class word_game
Method for player input
user input - player enters a string(word or phrase)
Method for guesses
limited guesses based on the length of the string
guessing the same thing twic... | true |
c3e9c1abbbd86b4511110122d80139f0ea4ba5b3 | Ruby | a-thom/advent-of-code | /2020/day12_01.rb | UTF-8 | 1,081 | 3.5625 | 4 | [] | no_license | require 'byebug'
instructions = []
File.read('day12_input.txt').lines.map do |line|
action, value = line.match(/(\w)(\d+)/)[1, 2]
instruction = {
action: action,
value: value.to_i
}
instructions << instruction
end
puts instructions.inspect
def change_direction(current, instruction)
directions = ... | true |
00ae62d9c6c9f63fa8530cb421738302c99a6a54 | Ruby | YashTotale/learning-ruby | /basics/enumerables/merge.rb | UTF-8 | 430 | 3.328125 | 3 | [
"MIT"
] | permissive | h1 = { a: 2, b: 4, c: 6 }
h2 = { a: 3, b: 4, d: 8 }
h1.merge(h2) # -> { a: 3, b: 4, c: 6, d: 8 }
h2.merge(h1) # -> { a: 2, b: 4, c: 6, d: 8 }
h1.merge(h2) { |key, old, new| new } # -> { a: 3, b: 4, c: 6, d: 8 }
h1.merge(h2) { |key, old, new| old } # -> { a: 2, b: 4, c: 6, d: 8 }
h1.merge(h2) { |k, o, n| o < n ? o : ... | true |
bebf81adaea6cfab4d3c1f302b9afcd509fba330 | Ruby | sailakshmiv/TicTacToe | /lib/tic_tac_toe/tic_tac_toe_game.rb | UTF-8 | 941 | 3.234375 | 3 | [] | no_license | class TicTacToeGame
attr_accessor :current_turn, :game_board
attr_reader :check_winner, :computer_ai
include Constants
def initialize(game_board = GameBoard.new, check_winner = CheckWinner, computer_ai = ComputerAI)
@game_board = game_board
@check_winner = check_winner
@computer_ai = computer_ai
... | true |
5b9218cdf75afa40d02e5fc199b3e3e98300d922 | Ruby | gwiederecht11/sp18-hw1 | /hw1.rb | UTF-8 | 987 | 3.109375 | 3 | [] | no_license | def squared_sum(a, b)
# Q1 CODE HERE
sum = a + b
return sum * sum
end
def sort_array_plus_one(a)
n = a.length
i = 0
while i < n do
minIndex = i
k = i + 1
while k < n do
if a[k] < a[minIndex] then
minIndex = k
end
k +=1
end
temp = a[minIndex]
a[minIndex] = ... | true |
ab7df1b657805f642160dd89e00075464e2fb851 | Ruby | lite72/puavo-oauth-client | /src/client.rb | UTF-8 | 4,308 | 2.671875 | 3 | [] | no_license | require 'sinatra/base'
require 'haml'
require 'addressable/uri'
require 'net/http'
require 'uri'
require 'json'
require 'restclient'
class Client < Sinatra::Base
# Predefined application identification data
set :redirect_uri, 'https://my.client.software/callback/' # We choose, and tell Opinsys our redirect_uri... | true |
9464edc14aa72003345fb01c49e521c22a2de802 | Ruby | erikbjoern/ruby_exercise | /movie_titles.rb | UTF-8 | 1,009 | 3.765625 | 4 | [] | no_license | the_fellowship_of_the_ring = {title: "The Fellowship of the Ring ", year: 2001}
the_two_towers = {title: "The Two Towers ", year: 2002}
the_return_of_the_king = {title: "The Return of the King ", year: 2003}
nineteen_seventeen = {title: "1917 ", year: 20... | true |
d1cfa0a5e2c2bafe9910ac9cce12152831ca4e4a | Ruby | ariendeau-usgs/Boiler | /Library/Boiler/cmd/help.rb | UTF-8 | 2,460 | 2.8125 | 3 | [] | no_license | BOILER_HELP = <<-EOS
:: commands ::
help
=> <command>
create
=> php
=> html
=> node
serve
=> h5bp
=> foundation
download
=> jquery
=> modernizr
=> underscore
... | true |
838d78de10be97be95a8fe6c5168e9139decf408 | Ruby | orlandorubydojo/2014-04-16-state-machine | /dog_spec.rb | UTF-8 | 1,085 | 3.25 | 3 | [] | no_license | require './dog.rb'
describe Dog do
before do
@baron = Dog.new("Baron")
end
it 'should have a name' do
expect(@baron.name).to eq("Baron")
end
it 'should start out sleeping' do
expect(@baron.state).to eq("sleeping")
end
it 'should wake up and play' do
@baron.wake_up
expect(@baron.st... | true |
0dd7f1603e6b1f9725523a065df52a4bce98664e | Ruby | kknd113/code | /easy/climbing_test.rb | UTF-8 | 489 | 3.875 | 4 | [] | no_license | # You are climbing a stair case. It takes n steps to reach to the top.
#
# Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
#
# Note: Given n will be a positive integer.
# @param {Integer} n
# @return {Integer}
def climb_stairs(n)
return 0 if n <= 0
return n if n <... | true |
ffe90bd2f3e73dcc8a5d0e90410e2b85354fcbad | Ruby | shijith/ColoringProblem-Rails | /app/controllers/home_controller.rb | UTF-8 | 1,091 | 2.6875 | 3 | [] | no_license | class HomeController < ApplicationController
def index
@nodes = {}
@adj = {}
@adj_arg = {}
i = 0
@colors = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
d = [0, 0, 0]
counter = 0
k = 0
@graph = {}
while params[String(k)]
@graph[k] = params[String(k)]
k += 1
end
k = 0
for a in @graph
n = a[0]
... | true |
54a8d49515e8f9e6fc493c91d2c9f429b5af8f1d | Ruby | alejandro-medici/retrospectiva | /vendor/plugins/tiny-git/lib/tiny_git/object/commit.rb | UTF-8 | 2,861 | 2.546875 | 3 | [
"MIT"
] | permissive | module TinyGit
module Object
class Commit < Abstract
PRETTY = %Q(%H%n%T%n%P%n%an <%ae> %aD%n%cn <%ce> %cD%n%s%n%b)
def initialize(base, sha, options = {})
super(base, sha)
@tree = nil
@parents = nil
@author = nil
@committer = nil
@message... | true |
33b648c86f5e11eb440ba2dda736674abdfefa48 | Ruby | dpick/crypto | /hw2/decrypt_vigenere.rb | UTF-8 | 737 | 3.15625 | 3 | [] | no_license | require 'vigenere'
ciphertext = "lpekwylwxmykyrevyvzkabngccpqjgosbaavemjotasinaaueinwfvsixifmlrzwxjlzevypzxdqfieszwgpnikzlytgaazgsezxwgaizqfvzxdmtqzodmjutwpmjylwnmsftrcjmvtxdivpzteklwciowjezrrmjulxewfutrebspoadilkdxdmmupsbitqzoppgwrlpidknisqljzypxaeeynmkqcgkvngcwwbaqywkazgheokgpdmzmjkykevzgcssvekyhwaogwpwakjpgkcdfqsnb... | true |
80e36c8fd8aad289e7a0acc587c28b67476c7f16 | Ruby | mrkchoi/aa_prep | /02_ruby/06_data_structures/03_knights_travails_v2/knights_travails.rb | UTF-8 | 1,795 | 3.46875 | 3 | [] | no_license | require_relative './poly_tree_node.rb'
require 'byebug'
class KnightPathFinder
DELTAS = [
[-2, -1],
[-2, 1],
[-1, -2],
[-1, 2],
[2, -1],
[2, 1],
[1, -2],
[1, 2],
]
def self.valid_moves(pos)
possible_moves(pos).select {|coords| on_board?(coords)}
end
def initialize(root_... | true |
dab8a3ba44e877846e89fdc879d63ac333dce440 | Ruby | dougal/cpu_latency_forwarder | /lib/cpu_latency_forwarder/command.rb | UTF-8 | 1,543 | 2.578125 | 3 | [] | no_license | require 'optparse'
module CPULatencyForwarder
class Command
def initialize
@graphite_host = 'localhost'
@graphite_port = '2003'
@script_location = '/root/cpu_latency.bt'
@flush_interval = 15
end
def run!
parse_options
puts "Sampling..."
store = SampleStor... | true |
a6f5d322c769e534acb5494a15e540b3cf2082f0 | Ruby | karlisV/appium_workshop | /features/pages/numbers.rb | UTF-8 | 619 | 2.59375 | 3 | [] | no_license | require './features/modules/base_numbers'
# contains all application's keyboard elements
class NumbersScreen < BaseNumbersScreen
def initialize(driver)
@driver = driver
end
def type_element(type)
type_elements = @driver.find_elements(id: 'select_unit_spinner')
case type
when 'base'
type_ele... | true |
5e72b6c0fd7154d386b7deef07b37cd1da694ea3 | Ruby | larger96/stock-picker | /stock_picker.rb | UTF-8 | 760 | 4.25 | 4 | [] | no_license | =begin
Implement a method #stock_picker that takes in an array of stock prices,
one for each hypothetical day. It should return a pair of days representing
the best day to buy and the best day to sell. Days start at 0.
=end
def stock_picker(array)
best_days = []
max_profit = 0
array.each do |buy|
buy_idx = a... | true |
60a95ce71cb5f7ff423e62645e47030db3d4df2c | Ruby | akshay0609/hotel_application | /test/models/category_test.rb | UTF-8 | 685 | 2.703125 | 3 | [] | no_license | require 'test_helper'
class CategoryTest < ActiveSupport::TestCase
def setup
@category = Category.new(category_type:"Deluxe Rooms", facility:"Queen size Bed", price:7000)
end
test "Should be valid" do
assert @category.valid?
end
test "category type should be present" do
@category.category_ty... | true |
eb918dafe7cd129fc4d825f957104cee5ab7bde5 | Ruby | saloni1911/WDI_12_HOMEWORK | /Saloni/wk04/4-thu/animals.rb | UTF-8 | 2,895 | 3.8125 | 4 | [] | no_license | require 'pry'
class Animal
def initialize(aname, age, gender, species, toys)
@name = aname
@age = age
@gender = gender
@species = species
@toys = []
# @@counter += 1
# @@shelterani << self
end
def ani_toys(toy)
@toys.push(toy)
end
def get_species
@species
end
# class << Animal
# def al... | true |
407b51c64eae2b0c251ec22545b68d4e00839cd7 | Ruby | jordansissel/jruby-elasticsearch | /lib/jruby-elasticsearch/request.rb | UTF-8 | 646 | 2.609375 | 3 | [] | no_license | require "jruby-elasticsearch/namespace"
require "jruby-elasticsearch/actionlistener"
class ElasticSearch::Request
# Create a new index request.
def initialize
@handler = ElasticSearch::ActionListener.new
end
# See ElasticSearch::ActionListener#on
def on(event, &block)
#puts "Event[#{event}] => #{blo... | true |
c4bfe7c47558e4c85578c13f5a5591dd1dc12851 | Ruby | pivotal-cf/bookbinder | /spec/lib/bookbinder/ingest/git_accessor_spec.rb | UTF-8 | 11,755 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'pathname'
require 'tmpdir'
require_relative '../../../../lib/bookbinder/ingest/git_accessor'
require_relative '../../../helpers/git_repo'
require_relative '../../../helpers/redirection'
module Bookbinder
module Ingest
describe GitAccessor do
include GitRepo
include Redirection
it "clo... | true |
d55e5a44dd66df5dc89ea3fd99ff57db44123d39 | Ruby | allbecauseyoutoldmeso/tic_tac_toe | /spec/game_spec.rb | UTF-8 | 1,817 | 3.265625 | 3 | [] | no_license | require 'game'
describe Game do
subject(:game) { described_class.new(3) }
describe '#current_player' do
it 'is initially x' do
expect(game.current_player.symbol).to eq 'x'
end
end
describe '#switch_player' do
it 'changes the player' do
game.switch_player
expect(game.current_pla... | true |
cf740d834431d14d4ba05ca36bfb83cb1136a448 | Ruby | clairemariko/d2-homework | /ruby_functions_practice.rb | UTF-8 | 1,057 | 3.46875 | 3 | [] | no_license | def return_10()
return 10
end
def add (num_1, num_2)
return num_1 + num_2
end
def subtract (num_1, num_2)
return num_1 - num_2
end
def multiply (num_1, num_2)
return num_1 * num_2
end
def divide (num_1, num_2)
return num_1 / num_2
end
def length_of_string(var_1)
return var_1.length
end
#STU... | true |
74cbb8208c04ef67c5703221b5818b2f0eae78b0 | Ruby | tetetratra/contest | /abc128/c.rb | UTF-8 | 652 | 2.90625 | 3 | [] | no_license | N, M = gets.chomp.split.map(&:to_i) # N個のスイッチ, Mの電球
a = []
c = []
M.times do |_m|
g = gets.split.map(&:to_i)
c << g[0] # 電球に紐づくスイッチの個数
a << [*g[1..-1]] # 電球に紐づくスイッチ
end
b = gets.split.map(&:to_i) # i番目の電球が、紐づくスイッチのうちONのものを2で割ってこれに一致したら、点灯する
count = 0
[true, false].repeated_permutation(N) do |sw| # arrには, M 個の {T,... | true |
41eab9a6f3e9739aca84e9595cf6048865cb571c | Ruby | srdja/aes-ruby | /lib/ruby/aes_cbc.rb | UTF-8 | 2,427 | 3.390625 | 3 | [
"MIT"
] | permissive |
# Cipher Block Chaining mode
#
# Plain text blocks are XORed with the previous block's cipher text, however the
# first block requires a random IV to be XORed with since there is no previous
# cipher text block.
class AES_CBC
def initialize(cipher)
@cipher = cipher
end
# XORs the first buffer with the se... | true |
1b48a2ef0d5537fae1411fad4928545c756b4029 | Ruby | kengonakajima/snippets | /ruby/dumper/dumper.rb | UTF-8 | 634 | 2.625 | 3 | [] | no_license | #
# Convert binary data to a C source with arrays named by file names
#
src = "/* generated source code by dumper.rb */\n"
def to_array(name,data)
ary = data.unpack("C*")
l = ary.size
out = "const char #{name}[#{l}] = {\n"
l.times do |i|
out += sprintf( "0x%02x",ary[i] )+ ","
out += " " if (i%16) ==... | true |
b609f332d8f51e58552f712f62715ea2063d6736 | Ruby | chickensmitten/iambic | /lib/iambic/lexical_item.rb | UTF-8 | 525 | 3.15625 | 3 | [] | no_license | module Iambic
class LexicalItem
attr_reader :word, :pronounciations
def initialize(word, pronounciations)
@word = word
@pronounciations = pronounciations
end
def stress_patterns
pronounciations.map &:to_stress_pattern
end
def string
word.string
end
def to_s
... | true |
c672b5e06d0e2ce26fc890dfd6a10fb6a1949a2c | Ruby | figursagsmats/sketchup-script-handler | /scripthandler.rb | UTF-8 | 2,566 | 2.71875 | 3 | [] | no_license | module ScriptHandler
class ScriptFileWatcher
def initialize(script_path, is_single_file=false)
@is_single_file = is_single_file
@dir_path = File.dirname(script_path)
@script_path = script_path
@prev_ruby_files = []
@main_script = script_path.split(... | true |
2ff303dea5dae2586f9cbf841f806d67b41e71de | Ruby | endorama/ruby-version-utils | /lib/version_manipulation.rb | UTF-8 | 1,593 | 2.953125 | 3 | [
"MIT"
] | permissive | module VersionUtils
def self.upgrade_major(
version,
update_build_version: false)
version = self.parse(version)
version[:major] += 1
if version[:minor] != nil
version[:minor] = 0
end
version = self.update_patch(version)
version = self.update_pre_release(version)
versi... | true |
857b1856219c30bc8129c9ba589985b21745797a | Ruby | zettsu-t/cPlusPlusFriend | /scripts/convert_opcode/convert_opcode.rb | UTF-8 | 4,128 | 3.3125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
# coding: utf-8
# Converting HEX strings to x86 mnemonics
#
# Usage: pass a HEX word to the first argument
# $ ruby convert_opcode.rb coffee
# > c0,ff,ee sar bh,0xee
#
# This script
# - treats o as 0 and i,l as 1 and applies less common rules
# - writes convert_opcode.out and does not delete it automa... | true |
4d43a1c5d0e1d14061c04b22cf144f660d67aafe | Ruby | rranshous/openscreener | /pipeline_overrides.rb | UTF-8 | 1,711 | 2.90625 | 3 | [] | no_license | require 'thread'
Thread.abort_on_exception = true
class FanPipe
include Messenger
def initialize create_new, get_key
@create_new = create_new
@get_key = get_key
@handlers = {}
bind_queues IQueue.new, IQueue.new
end
def handler_for_message m
key = @get_key.call m
raise "BAD KEY: #{m.k... | true |
a09b33d144f98d89dc610d604b696d67d48046eb | Ruby | Austin-dv-Evans/programming-univbasics-2-statement-repetition-with-while-den01-seng-ft-051120 | /casefamily.rb | UTF-8 | 415 | 2.734375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | case "Robbie"
when "Austin"
puts "I love Renee!!"
when "Renee"
puts "I love my beautiful family and Austin too"
when "Jeanie"
puts "I am a beautiful princess!"
when "Robbie"
puts "Robbie smash! grrrrr!"
when "Jerry"
puts "woof woof"
when "Woody"
puts "woof woof"
when "Dom"
puts "I have the best kids!"
... | true |
bf8c502bd78009d502ae99bb0acfe6cb96ea759e | Ruby | dillonkearns/legit | /lib/legit/cli.rb | UTF-8 | 3,399 | 2.625 | 3 | [
"MIT"
] | permissive | require 'legit/helpers'
module Legit
class CLI < Thor
include Thor::Actions
include Legit::Helpers
desc "log [ARGS]", "print a graph-like log"
method_option :me, :type => :boolean, :desc => 'Only include my commits'
def log(*args)
command = []
command << Legit::Helpers::LOG_BASE_COMM... | true |
604295a481c4cd5c444f1276c07e7ce0d7de6b35 | Ruby | dev1-sig/stresser | /lib/grapher.rb | UTF-8 | 3,386 | 2.78125 | 3 | [] | no_license | require 'ruport'
require 'gruff'
require 'yaml'
require 'csv'
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
module Grapher
extend self
#
# Parses command line options and creates one or a bunch of
# reports, stores them in the given directory, and advises
# the user to go ahead and ... | true |
50734af11d3c9e28dd7396329fe6346565852bbf | Ruby | AntoineInsa/stay_fit | /parse_swim.rb | UTF-8 | 4,166 | 3.125 | 3 | [] | no_license | require 'nokogiri'
require 'nori'
require 'gyoku'
require 'pry'
def find_distance(time)
average_pace = 120 # s/100m
pool_length = 50
margin = 0.8
lap_time = average_pace * (100 / (pool_length * 2))
i = 1
while time > lap_time * (i + margin) do
i += 1
end
pool_length * 2 * i
# if time < lap_... | true |
1a37bb8aae88df2401853012df47d6e23fbc2803 | Ruby | kasharaylo/RubyCore-Selenium | /Screencast/ep5.rb | UTF-8 | 289 | 2.984375 | 3 | [] | no_license | # frozen_string_literal: true
puts (2 + 3) * 5
puts 2 + 3 * 5
puts true && true
puts (1 < 2) && (3 > 2)
puts true && false
puts false && false
puts (1 > 2) && (3 > 2)
puts false && true
puts true || true
puts (1 > 2) || (3 > 2)
puts true || false
puts false || false
puts false || true
| true |
a84e73a7fdc093688544a153e8d43512bd0a56ec | Ruby | SoatGroup/redis | /redis_cluster/examples/cluster.rb | UTF-8 | 10,388 | 2.546875 | 3 | [
"BSD-3-Clause"
] | permissive | # Copyright (C) 2013 Salvatore Sanfilippo <antirez@gmail.com>
#
# 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, mo... | true |
e31b0a2dff067203c093c97bf1b0c69f555ec820 | Ruby | nrk/ironruby | /External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p368/lib/ruby/gems/1.8/gems/arel-0.2.pre/lib/arel/engines/sql/predicates.rb | UTF-8 | 1,111 | 2.625 | 3 | [] | no_license | module Arel
module Predicates
class Binary < Predicate
def to_sql(formatter = nil)
"#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
end
end
class CompoundPredicate < Binary
def to_sql(formatter = nil)
"(#{operand1.to_sql(formatter)} #{predicate_sql} #{o... | true |
396ed0539b61cf303fb3b52700871bb9a7bd357d | Ruby | gree/lwf | /tools/swf2lwf/lib/rkelly/lexeme.rb | UTF-8 | 364 | 2.828125 | 3 | [
"Zlib",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"MIT",
"BSL-1.0",
"Apache-2.0",
"Ruby",
"LicenseRef-scancode-public-domain",
"JSON"
] | permissive | require 'rkelly/token'
module RKelly
class Lexeme
attr_reader :name, :pattern
def initialize(name, pattern, &block)
@name = name
@pattern = pattern
@block = block
end
def match(scanner)
match = scanner.check(pattern)
return Token.new(name, match.to_s, &@bl... | true |
460f241e0e477fbab9f29cfb6d258f31359330aa | Ruby | crsanders/hackarogue | /lib/classlist.rb | UTF-8 | 834 | 2.9375 | 3 | [
"MIT"
] | permissive | class BaseClass
attr_reader :hp,
:inv,
:equip,
:lvl,
:str,
:mind,
:dex,
:vit,
:class,
:cash,
:xp
end
class Squire < BaseClass
def initialize
@hp = 10
@inv = []
@eq... | true |
fec327b1e9f97dc964b7c83307328810f4af9c59 | Ruby | Toam99/Leprosorium | /app.rb | UTF-8 | 2,637 | 3.015625 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
def init_db
@db = SQLite3::Database.new 'leprosorium.db'
@db.results_as_hash = true
end
# before called back each time reload executed
# any page
before do
# individualization of DB
init_db
end
# configure -> c... | true |
58bc534841be2e153c6acbe53e4a482639013d74 | Ruby | c8af43d37a3ae1ab0789afe3f56e9a4b/random | /lib4chan/test/homepage_spec.rb | UTF-8 | 1,406 | 2.703125 | 3 | [] | no_license | require 'lib/4chan.rb'
describe FourChan do
before :each do
@fourchan = FourChan.new
end
it "should fetch the homepage" do
homepage = @fourchan.home
describe homepage do
it "should be of the right class" do
homepage.should be_a(FourChan::Homepage)
end
it "should contain summaries of the active... | true |
576142a5a4e61ac6a5c3c8bd229c177f997e9976 | Ruby | njh/dbpedialite | /spec/category_spec.rb | UTF-8 | 6,986 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'category'
describe Category do
context "creating a category from a page id" do
before :each do
@category = Category.new(4309010)
end
it "should return an object of type Category" do
@category.class.should == Category
end
it "should have the correct UR... | true |
456e2d7e8ef99c89d967ed00f0de993f04cffb89 | Ruby | cielavenir/procon | /atcoder/abc/tyama_atcoderABC033B.rb | UTF-8 | 136 | 2.859375 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
h={}
s=0
gets.to_i.times{
x,y=gets.split
s+=h[x]=y.to_i
}
r=h.select{|k,v|v>s/2}
puts !r.empty? ? r.keys[0] : :atcoder | true |
10305547f9451edc45a63a35f26c4d52451641b9 | Ruby | WizelineHackathon2018/amalgama-hacks | /app/services/facebook_api_log_in/facebook_api.rb | UTF-8 | 1,177 | 2.625 | 3 | [] | no_license | require 'net/http'
require 'uri'
require 'json'
class FacebookApi
include ErrorRaiser
def initialize( auth_code:, platform: )
@auth_code = auth_code
@access_token = "?access_token=#{auth_code}"
@platform = platform
end
def get_user_data
response = get_data
response.merge( { "avatar_url" => get_image["da... | true |
ab27530bd9b685ca4edc9c89830d87fd8844cdcd | Ruby | f1nesse13/aA_anagrams | /anagrams.rb | UTF-8 | 1,728 | 4.125 | 4 | [] | no_license | def first_anagram?(str1, str2)
all_variations = str1.chars.permutation.map(&:join)
all_variations.include?(str2)
end
# first_anagram? increases exponetially with 3 letters having 6 possible combinations, 5 letters having 120 and 10 letters having a incredible 3628800 - O(kn) with more letters involving more variat... | true |
3342994b446ee5c1af6eabe906973386f8b91486 | Ruby | aaronsama/string-calculator-kata | /ruby/lib/string_calculator.rb | UTF-8 | 641 | 3.4375 | 3 | [] | no_license | module StringCalculator
class << self
# Splits a set of comma separated numbers and sums them
def add(numbers)
split_numbers = numbers.split(default_delimiter(numbers)).map(&:to_i)
negative_numbers = split_numbers.select(&:negative?)
raise "negatives not allowed: #{negative_numbers.join(',... | true |
3bf2f647a0468b0171e13ab9c6cd33e44f4de55f | Ruby | sapient/spelly | /test/test_bloomfilter.rb | UTF-8 | 560 | 2.75 | 3 | [] | no_license | require 'test/unit'
require File.join(File.dirname(__FILE__), "..", "lib", "spelly", "bloomfilter")
class TestBloomfilter < Test::Unit::TestCase
def test_adding_to_bloom
bloom = BloomFilter.new(100)
assert_equal 0, bloom.saturation
bloom.add("test")
assert bloom.includes?("test")
assert !bloom.i... | true |
273a84e0a19850f102a5d166ddc8a8b5ea109ad0 | Ruby | arpannln/aA-projects | /W2D2/chess/rook.rb | UTF-8 | 380 | 3.046875 | 3 | [] | no_license | require_relative 'slideable'
require_relative 'piece'
require_relative 'board'
require 'byebug'
class Rook < Piece
attr_reader :direction, :color, :board
attr_accessor :pos
def initialize(color, pos, board)
@direction = "straight"
super
end
include Slideable
def symbol
:Rook
end
def to_... | true |
fb809945ba8c11d51ad3404ff5e6ebee142ba813 | Ruby | renuo/google-hash-code-team-und-struppi | /spec/parse/parser_spec.rb | UTF-8 | 1,290 | 2.65625 | 3 | [] | no_license | require_relative '../spec_helper'
require_relative '../../rides/parser'
RSpec.describe Parser do
context(:example_dataset) do
let(:parser) do
parser = Parser.new('rides/datasets/a_example.in')
parser.parse
parser
end
it 'parses the first line' do
expect(parser.num_rows).to eq(3)
... | true |
adde518f97776658f82b19a242b315fc8e35f7cf | Ruby | databasically/harvestime | /lib/harvestime/invoice_filter.rb | UTF-8 | 1,230 | 2.5625 | 3 | [
"MIT"
] | permissive | require'harvested'
module Harvestime
class InvoiceFilter
def initialize(client)
@client = client
end
def all_with_status(state)
@client.invoices.all(status: state.to_s)
end
def all_invoices
@client.invoices.all
end
def all_by_client_id(client_id)
... | true |
7f41c6b28ad2f3d6e143824c5bf7976e5e38c344 | Ruby | jtibbertsma/flight-search | /lib/tasks/fetch_airports.rake | UTF-8 | 635 | 2.625 | 3 | [] | no_license | require 'set'
task fetch_airports: :environment do
major_airports = Set.new(
Typhoeus.get('http://www.nationsonline.org/oneworld/major_US_airports.htm')
.body.scan(/\b[A-Z]{3}\b/)
)
File.open(Rails.root.join('airports.dat')) do |file|
file.each_line do |line|
data = line.split(/,/)
cod... | true |
dee4be8fefddf61bfa9b02e1f75939321e666a35 | Ruby | CarlosCanizal/learn_to_program | /chapter_13/extend_built_in_classes.rb | UTF-8 | 436 | 4.09375 | 4 | [] | no_license | load "../chapter_9/modern_roman_function.rb"
load "../chapter_10/shuffle_function.rb"
class Integer
def factorial
if self < 0
return 'You can\'t take the factorial of a negative number!'
end
if self <= 1
1
else
self * (self-1).factorial
end
end
def to_roman
modern_roman self
end
en... | true |
2af9b664e1b420165bf9b71a5779e8971cb889e9 | Ruby | learn-co-students/yale-web-2019 | /06-uber/app/models/driver.rb | UTF-8 | 1,143 | 3.625 | 4 | [] | no_license | class Driver
@@all = []
attr_reader :name
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def rides
Ride.all.select do |ride|
ride.driver == self
end
end
def passengers
self.rides.map do |ride|
ride.passenger
end
end
def pa... | true |
37cc9539a9c70e5e03e86aa1b08b09c598159508 | Ruby | masdjab/elang | /compiler/code.rb | UTF-8 | 211 | 2.578125 | 3 | [] | no_license | module Elang
class Code
def self.align(code, align_size = 16)
if (extra_size = (code.length % 16)) > 0
code = code + (0.chr * (16 - extra_size))
end
code
end
end
end
| true |
1395af8752ca35d1ae82cbae698f91745e3bbf83 | Ruby | nulian/casted_hash | /lib/casted_hash.rb | UTF-8 | 3,509 | 3.03125 | 3 | [
"MIT"
] | permissive | class CastedHash < Hash
VERSION = "0.7.1"
def initialize(constructor = {}, cast_proc = nil)
raise ArgumentError, "`cast_proc` required" unless cast_proc
@cast_proc = cast_proc
@casting_keys = []
if constructor.is_a?(CastedHash)
super()
@casted_keys = constructor.instance_variable_get(... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.