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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
eed0dce9f395e6f36926225488d0389f8d3a57c0 | Ruby | hassanrehman/project_euler | /problem066.rb | UTF-8 | 1,990 | 3.5625 | 4 | [] | no_license | #http://www.numbertheory.org/pdfs/keith_midpoint.pdf
#2. https://en.wikipedia.org/wiki/Pell%27s_equation#Fundamental_solution_via_continued_fractions
#according to 2 .. we need to contunally find fractions h/k where
#for explanation on why X is like that ... see problem064.rb
class X
attr_reader :r, :a, :b, :c, :... | true |
9f39e2616ad0a70be02fb9fee472263ef73a064a | Ruby | jacooobi/university_projects | /Algorytmy i Struktury Danych/Sorting/spec/counting_sort_spec.rb | UTF-8 | 1,375 | 3.234375 | 3 | [] | no_license | require_relative '../lib/counting_sort'
require_relative '../lib/shared'
RSpec.describe 'Counting sort' do
let(:array) { [8,9,2,3,4,1,0,14] }
let(:big_array) { generate_numbers(10000) }
it 'returns false, instead of array' do
expect(counting_sort_asc('str')).to eq false
expect(counting_sort_asc([1, 2, 3... | true |
cc094101a6c3699d04d32ada9cce188aec32c292 | Ruby | jgibbel/blood-oath-relations-dumbo-web-82619 | /app/models/cult.rb | UTF-8 | 2,767 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Cult
@@all = []
attr_reader :name, :location, :founding_year, :slogan
def initialize(name, location, founding_year, slogan)
@name = name
@location = location
@founding_year = founding_year
@slogan = slogan
@@all << self
end
def recruit_follower(f... | true |
80e8a7303a44345e8611570c01345f0cba346608 | Ruby | latticetower/icfpc_2013_raw | /rubies/basic_evaluator.rb | UTF-8 | 4,358 | 2.84375 | 3 | [] | no_license | require 'net/http'
require 'rubygems'
require 'json'
require "./problem"
require "./noisy_listener"
require "./eval_request"
require "./eval_response"
UNARIES = ["not", "shl1", "shr1", "shr4", "shr16"]
BINARIES = ["and", "or", "xor", "plus"]
module BinaryMethods
def and_method(x, y)
((x).modulo(0x100000000000... | true |
b4dff45ab78ac3666d65778eff4f75a334b13ef8 | Ruby | WilfredTA/algorithmic_acrobatics | /Recursion/longest_increasing_subsequence.rb | UTF-8 | 2,228 | 3.859375 | 4 | [] | no_license | # Problem source: https://leetcode.com/problems/longest-increasing-subsequence/description/
# Given an array of integers, find the longest increasing subsequence
# General: Given an array of integers, find the longest increasing sunsequence from index 0 to N
# Question: How can the longest increasing subsequence fro... | true |
f2834a5d2fc61ef1132f24f5040b06919be770ed | Ruby | neosaurrrus/ruby-collaborating-objects-lab-online-web-sp-000 | /lib/artist.rb | UTF-8 | 681 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist
attr_accessor :name, :all, :find_or_create_by_name
@@all = []
def initialize(name)
@name = name
@songs = []
end
def add_song(song)
@songs << song
end
def songs
@songs
end
def save
@@all << self
end # of save
def self.all
@@all
end
def self.find_or_create_... | true |
f12112d1f8432f45313e2d8d1417956c1b472ce7 | Ruby | robinbird88/sum17-social-media-project | /app/helpers/application_helper.rb | UTF-8 | 338 | 2.609375 | 3 | [] | no_license | module ApplicationHelper
def total_followers(user_id)
total = 0
# followers = []
User.all.each do |follower|
if follower.following.include? user_id
total += 1
end
end
return total
end
def total_tweets(user_id)
tweets =[]
tweets = Tweet.where(user_id: user_id)
return tweets.... | true |
554f74f65dcb016763158e951efd98ae9eb93378 | Ruby | nathanknautz/object_oriented_ruby | /lamb.rb | UTF-8 | 168 | 3.09375 | 3 | [] | no_license | class Sheep
@@count = 0
def initialize
end
def bleet
puts has_money
end
private
def has_money
true
end
end
sheep = Sheep.new
sheep.bleet
| true |
05382c7c941f5595634b7ffc17a2d245f4c68a09 | Ruby | dyoder/filebase | /test/test.rb | UTF-8 | 2,066 | 2.53125 | 3 | [] | no_license | require 'rubygems'
require 'bacon'
Bacon.extend Bacon::TestUnitOutput
Bacon.summary_on_exit
$:.unshift '../lib'
require 'lib/filebase'
require 'lib/filebase/model'
require 'lib/drivers/yaml'
class Person ; include Filebase::Model[ 'test/db/person' ] ; has_one :organization ; end
class Organization ; include Filebase... | true |
cafb82485d40481a92fa8ac0008f43de472c3464 | Ruby | paulmcmanus2021/travel_bucket_list | /controllers/city_controller.rb | UTF-8 | 983 | 2.75 | 3 | [] | no_license | require_relative('../models/continent.rb')
require_relative('../models/country.rb')
require_relative('../models/city.rb')
require_relative('../models/sight.rb')
require ('pry')
# INDEX
get '/cities' do
@cities = City.all()
erb(:"/cities/index")
end
# NEW
get '/cities/new' do
@cities = City.all()
erb(:"cities... | true |
1fc2a32efb6482500483db30dbfd95ab70c4ad5d | Ruby | nutsiepully/mad-eye | /old_proj/bkup_system/price.rb | UTF-8 | 528 | 3.546875 | 4 | [] | no_license |
# Class that encapsulates the price for a particular flight
class Price
attr_accessor :category
attr_accessor :currency
attr_accessor :price
def initialize p_category, p_currency, p_price
@category = p_category
@currency = p_currency
if p_price.is_a? String
@price = p_price.gsub(/,/, "").to_f
elsif p_p... | true |
19b39275bc69dc7dc887abebd63b46ff3da88a11 | Ruby | jwrobes/Yobs | /app/helpers/categories_helper.rb | UTF-8 | 362 | 2.53125 | 3 | [] | no_license | module CategoriesHelper
def get_short_desc(job)
@short = job.description.split[0..25].join(' ')
@short
end
def get_long_desc(job)
if job.description.length > @short.length
' ' + job.description.split[26..(job.description.length-1)].join(' ')
end
# @long = ' ' + job.description.split[26..(job.descriptio... | true |
1e257a234b02214587fd861e318c0487d9647dc0 | Ruby | sidoh/ha_gateway | /drivers/light/milight.rb | UTF-8 | 1,402 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'limitless_led'
require_relative 'light'
require_relative '../repeat_wrapper'
module HaGateway
class MilightDriver < Light
attr_reader :driver_params
def initialize(driver_params = {})
@driver_params = driver_params
end
def on
api.on
end
def off
api.off
end
... | true |
091ef3b555533412d61902b8f3842f8fb98c0c64 | Ruby | pelensky/the_well_grounded_rubyist | /chapter_03/inheretence.rb | UTF-8 | 559 | 3.6875 | 4 | [] | no_license | # class Publication
# attr_accessor :publisher
# end
# class Magazine < Publication
# attr_accessor :editor
# end
#
# mag = Magazine.new
# mag.publisher = "David A. Black"
# mag.editor = "Joe Smith"
# puts "Mag is publisehd by #{mag.publisher}, and edited by #{mag.editor}."
#
# class Ezine < Magazine
# end
# class... | true |
ad43da51aedeed89410016e8981588d64b850c36 | Ruby | jamaspy/sei31-homework | /warmups/week04/day04_nucleotide_count/nucleotides.rb | UTF-8 | 1,423 | 3.578125 | 4 | [] | no_license | # # Version 1
#
# def count_nucleotides(input)
# dna = []
#
# bases = {
# "A" => 0,
# "C" => 0,
# "T" => 0,
# "G" => 0
# }
#
# input.upcase.chars.each do |letter|
# # puts "Checking for letter: #{letter}"
#
# is_nucleotides = false
#
# bases.each do |key, value|
# # puts "the k... | true |
fb22d79fd660b419b71924cf271a5c91a4dc2e2c | Ruby | ovidiubite/highschoolassistant | /app/models/admission_result.rb | UTF-8 | 1,057 | 2.765625 | 3 | [] | no_license | # == Schema Information
#
# Table name: admission_results
#
# id :integer not null, primary key
# admission_rate :integer
# evaluation_rate :integer
# graduation_rate :integer
# grade_math :integer
# grade_romana :integer
# grade_native :integer
# assigned_school :string
# sec... | true |
c1b7eb005c9f303cf36e5e378840f6bb135f2bb4 | Ruby | satzcoal/elong_auto_search | /send_http.rb | UTF-8 | 537 | 3.171875 | 3 | [] | no_license | require 'socket'
# Service Object
# 发送Http请求
class SendHttp
# 类调用方法
def self.call(host, request, port=80)
self.new(host, request, port).call
end
# 构造器
# 参数:
# host
# request
# port
def initialize(host, request, port=80)
@host = host
@request = request
@port = port
end
# 主逻辑... | true |
367df8d54dfc4a00c67d6d5d58dcdd240f35d2e4 | Ruby | Koda-thp/ruby_exo | /ruby_exo/exo_09.rb | UTF-8 | 152 | 3.234375 | 3 | [] | no_license | puts "C'est quoi ton blaze ?"
prenom = gets.chomp
puts "M'enfou"
puts "Nom de famille ?"
famille = gets.chomp
print "Yo #{prenom}"
puts " #{famille} !"
| true |
a18d4bbff0cbd48a4164bcd3a3dd54af6a0af735 | Ruby | JonathanSR/CarWash | /test/truck_test.rb | UTF-8 | 1,293 | 2.921875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/truck'
class TruckTest < Minitest::Test
def test_it_creates_an_instance_of_truck
truck = Truck.new({type: 'truck', mud: 'no', bed:'down', plates:'1111111'})
assert_instance_of Truck, truck
end
def test_it_creates_a_truck_with_type_of_tr... | true |
93491128f80d53231782ef63c9b79074a4f5b797 | Ruby | saul23r/Works | /Reporte/app/pdfs/projects_pdf.rb | UTF-8 | 919 | 2.53125 | 3 | [] | no_license | require 'prawn/table'
class ProjectsPdf < Prawn::Document
def initialize(projects)
super()
@projects = Project.order("name DESC").all
project_id
end
def project_id
image "#{Rails.root}/app/assets/images/edi.jpg", height: 50
y_position = cursor + 50
bounding_box([200, y_position], :width... | true |
12b6084dc22dc681f6780073b261adb58da232dd | Ruby | milankubin/surus | /lib/surus/hstore/scope.rb | UTF-8 | 2,487 | 2.625 | 3 | [
"MIT"
] | permissive | module Surus
module Hstore
module Scope
# Adds a where condition that requires column to contain hash
#
# Example:
# User.hstore_has_pairs(:properties, "favorite_color" => "green")
def hstore_has_pairs(column, hash)
where("#{connection.quote_column_name(column)} @> ?", Seri... | true |
9e95eaed89bf67a9f7d87f1b26d69c955ec01215 | Ruby | ryoryo25/ProjectEuler | /libs/prime.rb | UTF-8 | 1,154 | 3.765625 | 4 | [] | no_license | def isPrime(n)
if n <= 1
return false
end
if n == 2
return true
end
if n % 2 == 0
return false
end
up = Math.sqrt(n).to_i
3.step(up, 2) do |i|
if n % i == 0
return false
end
end
return true
end
# get all primes < n
def sieve(n)
primes = []
a = Array.new(n, true)
2.step(Math.sqrt(n).to_i) ... | true |
2589d5c091014f5702d0d0f7924c319ca870308c | Ruby | lishulongVI/leetcode | /ruby/673.Number of Longest Increasing Subsequence(最长递增子序列的个数).rb | UTF-8 | 2,039 | 3.796875 | 4 | [
"MIT"
] | permissive | =begin
<p>
Given an unsorted array of integers, find the number of longest increasing subsequence.
</p>
<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> [1,3,5,4,7]
<b>Output:</b> 2
<b>Explanation:</b> The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3, 5, 7].
</pre>
</p>
<p><b>Example 2:</b><br />
<pre>... | true |
cc98d0a00c2cf0f6a2dc580ed04935db81518ca6 | Ruby | llby/candy--sql | /lib/candy--sql.rb | UTF-8 | 1,214 | 3.0625 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require 'candy--sql/version'
require 'candy--sql/interpreter'
require 'candy--sql/token'
require 'candy--sql/variable'
module CandySql
def make(filename)
mode = 0 #(0: 変数定義、1: SQL構文)
var = {}
res = []
open(filename) { |file|
while row = file.gets
# トークン分割
sr... | true |
2fb05083e4b2065eba7e56997219a4dda7f0f7ba | Ruby | broadinstitute/single_cell_portal_core | /test/lib/request_utils_test.rb | UTF-8 | 8,452 | 2.59375 | 3 | [] | permissive | require 'test_helper'
require 'api_test_helper'
require 'integration_test_helper'
require 'includes_helper'
class RequestUtilsTest < ActionDispatch::IntegrationTest
before(:all) do
@user = FactoryBot.create(:user, registered_for_firecloud: true, test_array: @@users_to_clean)
@public_study = FactoryBot.crea... | true |
cd2206b4524a2a8a4d94bfca89fb746aee5c386c | Ruby | thib123/TPJ | /Notes/Ruby/sample_code/ex0206.rb | UTF-8 | 140 | 3.296875 | 3 | [
"MIT"
] | permissive | # Sample code from Programing Ruby, page 85
class Test
def val=(val)
@val = val
return 99
end
end
t = Test.new
a = t.val = 2
a
| true |
e50c4332e5c2493c9cca976b9aeb1946a8ef86cc | Ruby | am52saif/Popping-Bottles | /pop_bottles.rb | UTF-8 | 2,129 | 3.96875 | 4 | [] | no_license | def recurse1(drinks)
popBottles = drinks
emptyBottles = popBottles/2
emptyCaps = popBottles/4
leftEmptyBottles = popBottles - (emptyBottles*2)
leftEmptyCaps = popBottles - (emptyCaps*4)
freePop = emptyCaps + emptyBottles
puts "<=========================================================================... | true |
8bc0139777c7fe463d081c87197e38f07f06f1d9 | Ruby | eebasadre20/Codewars-Kata-Solutions | /week-3/first-non-repeating-letter.rb | UTF-8 | 795 | 3.84375 | 4 | [] | no_license | # PROBLEM --> https://www.codewars.com/kata/first-non-repeating-letter
# Click the link for more information
# about the Kata problem.
def first_non_repeating_letter(s)
return s if s.empty?
puts s
str = s.split("").each_with_object(Hash.new(0)) do | word, count |
count[word] += 1
end
str.each do |k,... | true |
db01a1eb2ad91c1d7d6ddc5a4983ed5af8a9e11e | Ruby | carusocr/bcast | /scola_scrape/scola_scrape.rb | UTF-8 | 5,905 | 2.578125 | 3 | [] | no_license | #Author: Benjamin Bascom
#SCOLA Scraper v 0.0
#Date: 12/3/2012
#!/bin/ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'mysql'
require 'date'
require File.expand_path("../normalize", __FILE__)
require File.expand_path("../db/table", __FILE__)
require 'pp'
class Scraper
# Some utility methods ... | true |
85c864f02599a4151fb223205c03669717969acf | Ruby | brixen/pegarus | /lib/pegarus/ast/any_range.rb | UTF-8 | 194 | 2.65625 | 3 | [
"BSD-2-Clause"
] | permissive | module Pegarus
class AnyRange < Pattern
attr_accessor :range
def initialize(range)
@range = range
end
def visit(visitor)
visitor.any_range self
end
end
end
| true |
2d3633e0066a0664e7af43bffb8ea9fcd50a7b8f | Ruby | yamax2/yandex_client | /lib/yandex_client/dav.rb | UTF-8 | 2,950 | 2.703125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'digest'
require 'http'
require 'yandex_client/dav/prop_find_response'
module YandexClient
# https://tech.yandex.ru/disk/doc/dg/reference/put-docpage/
#
# Chainable client:
#
# YandexClient::Dav[access_token]
# .put('1.txt', '/a/b/c/1.txt')
# .put(File.open('1.t... | true |
d51a1a2858725badda4cb07392f37d958f15ff6d | Ruby | guslune/codezbin | /rails-tuts/6-ObjectOrientation/6.5-gpa_calculator-oo/src/GpaCalculator.rb | UTF-8 | 628 | 3.3125 | 3 | [] | no_license | class GpaCalculator
def initialize
@grade_sum = 0.0
@number_of_grades = 0
$gpa = 0.0
end
def does_user_say_no question
question == "stop"
end
def get_user_grade_and_add_all
user_input = ""
grade_counter = 0
until does_user_say_no user_input
user_input = gets.chomp
grade_processor =... | true |
0143a805c3bbaf75d591c50f06da2c2d685564fd | Ruby | cristianespindola/Obj3 | /metaprogramacion/src/prototyped.rb | UTF-8 | 2,286 | 3.140625 | 3 | [] | no_license | module Prototyped
attr_accessor :prototype, :listaDeBloquesYSelector
@listaDeBloquesYSelector = Array.new
def method_missing(sym, *args, &block)
if (prototype.nil?)
crear_Metodo_Si_El_Sym_Termina_Con_Igual(sym,*args)
else
if (prototype.methods.include?(sym))
bloque =... | true |
a364540836b743854d17113283bd2b9ca0cf06c8 | Ruby | souki1103/ruby_novice | /lib/yuri/1_1.rb | UTF-8 | 478 | 3.890625 | 4 | [
"MIT"
] | permissive | print("Helo, Ruby.\n")
print("Hello, \"RUBY\"\n")
puts "Hello, Ruby."
p "100"
p 100
print("あいうえお\n")
puts(20 + 8/2)
puts Math.sin(3.1415)
=begin
表面積と体積を
求める
=end
x=10 #横
y=20 #縦
z=30 #高さ
area=(x*y+y*z+z*x)*2
volume=x*y*z
print "表面積=", area, "\n"
print "体積=", volume, "\n"
puts "表面積=#{area}"
p(2==2)
p(1==2)
a=20
if a... | true |
6a0c0f1b5617fdb4e1cf055728a4c0a239c88d61 | Ruby | samarsingh748/ruby | /basic/userinp.rb | UTF-8 | 190 | 4 | 4 | [] | no_license | puts "Enter the number"
num=gets.chomp.to_i
puts "you have entered " + num.to_s
if num.to_i >= 10
puts "number is greater than or equal to 10"
else
puts "number is less than 10"
end
| true |
59dc849f480df49197d264fc6715cc97fdc91290 | Ruby | plenty-of-flicks/plenty_of_flicks_be | /app/models/movie.rb | UTF-8 | 2,356 | 2.515625 | 3 | [] | no_license | class Movie < ApplicationRecord
validates_presence_of :title, :tmdb_id
has_many :movie_availabilities
has_many :services, through: :movie_availabilities
has_many :movie_genres
has_many :genres, through: :movie_genres
has_many :swipes
has_many :users, through: :swipes
def self.needs_details
Movie.w... | true |
b2e09c517a6ac9548e307b81d93d958ee7caa249 | Ruby | stein328i/ruby_fundamentals2 | /exercise7.rb | UTF-8 | 229 | 3.46875 | 3 | [] | no_license | # ex 7
def wrap_text(word, wrap)
wrap + word + wrap
end
p wrap_text('hello', '===')
p wrap_text('goodbye', '---')
first = wrap_text("new message", "###") ###nice###
second = wrap_text(first,"===")
p wrap_text(second, "---")
| true |
3539ba75f2a4d5a4736bbfd221b073d4560ce83f | Ruby | DKyleTurner/tealeaf-precourse | /Loops-Iterators/ex1.rb | UTF-8 | 185 | 4.3125 | 4 | [] | no_license | # What does the following program return?
x = [1, 2, 3, 4, 5]
x.each do |a|
a + 1
end
# The 'each' iterator iterates through every element in the array and returns [1, 2, 3, 4, 5]
| true |
054070b020dc5ae25d31f74094e46b8125dc5338 | Ruby | kgofron/myPython | /Ruby/strings.rb | UTF-8 | 156 | 3.8125 | 4 | [] | no_license | # Iterating Through Strings with loops
def printChars(str)
i = 0
while i < str.length
puts str[i]
i += 1
end
end
printChars('cats') | true |
cfc6a3142c4eab005047af4617008bae70bfd3db | Ruby | MilliDevX/feedes | /spec/feedes/model/base_feed_spec.rb | UTF-8 | 1,437 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
RSpec.describe Feedes::Model::BaseFeed do
describe 'new' do
it 'should create new instance' do
meta = {title: 'Sample RDF Feed'}
items = [1,2,3]
m = Feedes::Model::BaseFeed.new(meta, items)
expect(m).to be_an_instance_of(Feedes::Model::BaseFeed)
expect(m.meta)... | true |
ee865b8055342cecb6abdde3f300d81c99318419 | Ruby | crsanders/hackarogue | /lib/room.rb | UTF-8 | 840 | 3.21875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
require 'curses'
include Curses
class Room
attr_reader :x_size,
:y_size,
:walls
def initialize x_size, y_size, x_pos, y_pos
@x_size = x_size
@y_size = y_size
@walls = nil
init_screen()
noecho
@win = Curses::Window.new( y_size, # height
... | true |
4a4721728a4e2f4cc0ab0cfe1603a4c00f1e941c | Ruby | Zane5/challenges | /robot/simulator_second_place.rb | UTF-8 | 1,243 | 3.859375 | 4 | [] | no_license | class Simulator
INSTRUCTIONS_DICT = { 'L' => :turn_left, 'R' => :turn_right, 'A' => :advance }
def instructions(instruction_code)
instruction_code.each_char.map { |char| INSTRUCTIONS_DICT[char] }
end
def place(robot, placement)
robot.at(placement[:x], placement[:y])
robot.orient(placement[:directi... | true |
ba0d59fe4212b7224004cf1b37c1f203e6ee1b0c | Ruby | nnakagaki/code-eval | /easy/query_board.rb | UTF-8 | 618 | 2.953125 | 3 | [] | no_license | board = Array.new(256)
board.length.times do |i|
board[i] = Array.new(256,0)
end
File.open(ARGV[0]).each_line do |line|
line.chomp!
split = line.split(" ")
if split[0] == "SetCol"
board.each do |row|
row[split[1].to_i] = split[2].to_i
end
elsif split[0] == "SetRow"
board[split[1].to_i].length.tim... | true |
ce8e5b94f1b4b65d06e490ccacd7f7d18fb96533 | Ruby | softscienceprojects/OO-Auto-Shop-london-web-080519 | /tools/console.rb | UTF-8 | 997 | 2.859375 | 3 | [] | no_license | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
# Mechanic.new(name, specialty)
mike = Mechanic.new("Mike", "Antique")
angie = Mechanic.new("Angie", "Exotic")
tommy = Mechanic.new("Tommy", "Clunker")
susie = Mechanic.new("Susie", "Antique")
# CarOwner.new(name)
billy = CarOw... | true |
9bcba3423c21468cb526cb03c11b7563610a733c | Ruby | juholgado/blogfolio | /vendor/plugins/friendly_identifier/test/friendly_identifier_test.rb | UTF-8 | 4,619 | 2.609375 | 3 | [] | no_license | require File.join(File.dirname(__FILE__), 'test_helper')
require File.join(File.dirname(__FILE__), 'fixtures/widget')
require File.join(File.dirname(__FILE__), 'fixtures/category')
require File.join(File.dirname(__FILE__), 'fixtures/gadget')
class FriendlyIdentifierTest < Test::Unit::TestCase
def test_create_vali... | true |
6b65463ebd62a26a32e32de3baa8dfe9b707492d | Ruby | anynines/cfoundry_helper | /lib/cfoundry_helper/helpers/organization_helper.rb | UTF-8 | 5,236 | 2.875 | 3 | [] | no_license | module CFoundryHelper::Helpers
module OrganizationHelper
# returns an array of all CFoundry::V2::Organizations
def self.get_organizations
self.cc_client.organizations
end
def self.exists?(org_name)
self.cc_client.organizations.each do |o|
return true... | true |
9791784152d6b6423870a906bfe23da70e0ba4be | Ruby | rahulk1000/campus_bite | /spec/models/food_item_spec.rb | UTF-8 | 11,238 | 2.734375 | 3 | [] | no_license | # == Schema Information
#
# Table name: food_items
#
# id :integer not null, primary key
# name :string(255)
# dining_common :string(255)
# category :string(255)
# subcategory :string(255)
# date :date
# meal_type :string(255)
# created_at :datetime no... | true |
5a0b57d802f87fcb3127b7928bcb36779a1ac427 | Ruby | mikowitz/RickRoller | /complex_roll_controller.rb | UTF-8 | 638 | 2.859375 | 3 | [] | no_license | class ComplexRollController
DICE_SIDE_OPTIONS = [4, 6, 8, 10, 20, 100]
attr_accessor :roll_button
attr_accessor :d4_dice_field, :d6_dice_field, :d8_dice_field, :d10_dice_field, :d20_dice_field, :d100_dice_field
attr_accessor :roller
attr_accessor :rr_controller
def roll(sender)
_dice = capture_dice
... | true |
d8c16815ec9da82f56df8f71c47ee8400e5c2d24 | Ruby | rgylling/ruby-music-library-cli-v-000 | /lib/song.rb | UTF-8 | 1,346 | 3.046875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
extend Concerns::Findable
attr_accessor :name
attr_reader :artist, :genre
@@all = []
def initialize(name,artist=nil,genre=nil)
@name = name
self.artist = artist if artist
self.genre = genre if genre
end
def self.all
@@all
end
def self.destroy_all
@@all.clear
end... | true |
06ca867e937fc24e4be39e2670beacb6cec71449 | Ruby | mark-cooper/reparent | /reparent.rb | UTF-8 | 3,106 | 2.59375 | 3 | [] | no_license | require 'digest'
require 'logger'
require 'sequel'
require 'yaml'
config = YAML.load_file(
File.join(__dir__, 'config.yml')
).transform_keys(&:to_sym)
DB = Sequel.connect({
adapter: :mysql2,
max_connections: 20,
logger: Logger.new(STDOUT)
}.merge(config[:db]))
def setup_new_parent_for(child, title, level, re... | true |
3a115559017ad236cc9bdb676b07726238ddfd64 | Ruby | marshalldanel/ar-exercises | /exercises/exercise_6.rb | UTF-8 | 1,059 | 2.859375 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
puts "Exercise 6"
puts "----------"
@store1.employees.create(first_name: "Khurram", last_name: "Virani", hourly_rate: 60)
@store1.... | true |
ac4e801f9370ba5de7b482496849ec5b63f2f4ea | Ruby | merecka/ttt-with-ai-project-online-web-pt-031119 | /lib/cli.rb | UTF-8 | 3,165 | 3.796875 | 4 | [] | no_license | class CommandLineInterface
attr_accessor :game, :game_type, :letter, :player_choice
def initialize
@game = []
end
def run
game_selection_menu
game.play
again_or_exit
end
def game_selection_menu
puts "Hello and Welcome to the CLI Tic Tac Toe game!"
puts "\n"
puts "Please choos... | true |
981114bdff75c6de2fd7206bdf80a198cfa72c87 | Ruby | marllons/xsunit-api | /app/controllers/api/survivors_api.rb | UTF-8 | 3,510 | 2.546875 | 3 | [] | no_license | module Api
class SurvivorsApi < SurvivorsController
def_param_group :survivors_get do
param :name, String, :desc => "Name of survivor"
param :birthday, Date, :desc => "Date of birth of survivor"
param :gender_id, ["1 = Male", "2 = Female", "3 = Undefined"], :desc => "Id gender of survivor"
... | true |
6f3ce29b1023e24339fb4614cebf6893d57cecc8 | Ruby | Arledis/Homework_w2_d2 | /river_class.rb | UTF-8 | 442 | 3.421875 | 3 | [] | no_license | class River
attr_reader :name
def initialize(name, fishes)
@name = name
@fishes = fishes
end
def fish_count
return @fishes.size()
end
# def add_fish_to_stomack(new_fish)
# @stomack.push(new_fish)
# end
#
# def find_by_name(name)
# for fish in @fishes
# if fish.name == name
# return fish
# end... | true |
bd6d1899256dcd171b4442d4e9563f8e417c11ab | Ruby | mrflip/poolparty | /lib/core/symbol.rb | UTF-8 | 627 | 3.09375 | 3 | [
"MIT"
] | permissive | class Symbol
# def >(num);"#{self} > #{num}";end
# def <(num);"#{self} < #{num}";end
# def >=(num);"#{self} >= #{num}";end
# def <=(num);"#{self} <= #{num}";end
# def ==(num);"#{self} > #{num}";end
def sanitize
self.to_s.sanitize
end
def <=>(b)
"#{self}" <=> "#{b}"
end
##
# @param o<Str... | true |
a63685da5a7e2e52eb30667be6a770d8b586030d | Ruby | clay-f/algorithms-practice | /Implement_queue_using_stack232.rb | UTF-8 | 1,330 | 4.3125 | 4 | [] | no_license | require 'pry'
# Implement the following operations of a queue using stacks.
# push(x) -- Push element x to the back of queue.
# pop() -- Removes the element from in front of queue.
# peek() -- Get the front element.
# empty() -- Return whether the queue is empty.
class Node
attr_accessor :item, :next
def initia... | true |
caed298f9ccf2325039197196a2b7ec56b01ad58 | Ruby | jsanchy/launch-school-exercises | /small_problems_ruby/medium1/fibonacci_numbers_procedural.rb | UTF-8 | 347 | 3.78125 | 4 | [] | no_license | def fibonacci(n)
return 1 if n == 1 || n == 2
prev = 1
nth_fib = 1
counter = 3
loop do
nth_fib, prev = nth_fib + prev, nth_fib
counter += 1
break if counter > n
end
nth_fib
end
p fibonacci(20) == 6765
p fibonacci(100) == 354224848179261915075
p fibonacci(100_001) # => 420269270... | true |
ed930ec0e6b697c7e034ee88fb79b0b5ad7305a3 | Ruby | mehowte/dotfiles | /bin/pow | UTF-8 | 2,339 | 2.828125 | 3 | [] | no_license | #! /usr/bin/ruby
# This script is based on the one found in the Powder gem,
# but without Thor dependency. I also removed install and
# uninstall commands, since they aren't part of the workflow.
# Check https://github.com/Rodreegez/powder/blob/master/bin/pow
# for the original script.
#
# ====== Installation ======
#... | true |
59e06ffd3b0584ec739972323c6705b0eb637f81 | Ruby | Pilafonta/learn_ruby | /01_temperature/temperature.rb | UTF-8 | 106 | 3.140625 | 3 | [] | no_license | #write your code here
def ftoc(fahr)
(fahr - 32) * (5.0/9.0)
end
def ctof(cent)
(cent*1.8) + 32
end
| true |
b710628f4a1bcd316cdc7189288f92b5b642d40a | Ruby | Kalimaha/event-stream-playground | /RabbitMQ/bin/rabbit | UTF-8 | 1,323 | 2.71875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
def print_help
help = <<-HELP
Available commands:
build...................Build the Docker image
start...................Run RabbitMQ on http://localhost:15672/
stop....................Stop RabbitMQ
status..................Verify the status of RabbitMQ server
add_user <USR> <PWD>....A... | true |
d31847b999864316a84f32e6d92591bf4372974b | Ruby | wvanbergen/scoped_search | /lib/scoped_search/query_language.rb | UTF-8 | 983 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module ScopedSearch::QueryLanguage
require 'scoped_search/query_language/ast'
require 'scoped_search/query_language/tokenizer'
require 'scoped_search/query_language/parser'
# The Compiler class can compile a query string into an Abstract Syntax Tree,
# which in turn is used to build the SQL query.
#
# T... | true |
7774c524ebf95bb71e8ea3a3bb92e08e82d956be | Ruby | zapidan/ruby-playground | /7-combining-objects-with-composition/3-making-parts-more-like-an-array.rb | UTF-8 | 2,024 | 3.921875 | 4 | [] | no_license | # Bicycle composed of parts, which is the new superclass
class Bicycle
attr_reader :size, :parts
def initialize(args={})
@size = args[:size]
@parts = args[:parts]
end
def spares
parts.spares
end
end
# Parts is now a wrapper around an array of Part objects
# Part objects are fr... | true |
c0d9e1f901b37449afed013265112217341ae608 | Ruby | patrickmontalto/odin | /basic_ruby/stock_picker/stock_picker.rb | UTF-8 | 269 | 3.1875 | 3 | [] | no_license | def stock_picker(arr=[])
difference = 0
for i in arr[0..-2]
for j in arr[arr.index(i)..-1]
diff = j - i
if diff > difference
difference = diff
buy = arr.index(i)
sell = arr.index(j)
end
end
end
[buy, sell]
end | true |
77165793382eebf9261faa037d1fa999791fa94a | Ruby | YogiZoli/studiogame-2015 | /try/designpatternsruby.rb | UTF-8 | 658 | 2.765625 | 3 | [] | no_license | # Ruby Design Patters / Template method
class Report
def make
header
footer
footer_double
body
end
def header
raise NoImplementedError
end
def footer_double
end
end
class HtmlReport < Report
def header
puts "html header"
end
... | true |
17a5069c8ed05dab61f6151bbc30ccb811d75ec0 | Ruby | Rutherther/university-scripts | /open_lecture.rb | UTF-8 | 648 | 2.546875 | 3 | [] | no_license | #!/bin/ruby
require_relative './common/courses.rb'
require_relative './common/rofi.rb'
courses = Courses.new(File.join(__dir__, './info.yaml'))
courses_rofi = courses.for_rofi(true)
courses_rofi = courses_rofi.select {|item| not item.data.lectures.empty?}
out = Rofi.new("Select course:", courses_rofi).show()
if ou... | true |
21aa90937485974a3ec509259f0f92dcd52421bb | Ruby | yejunsun/practise | /algorithms/quick-sort/quick-sort.rb | UTF-8 | 943 | 4.1875 | 4 | [] | no_license | def quick_sort(alist)
quick_sort_helper(alist, 0, alist.length - 1)
end
def quick_sort_helper(alist, first, last)
if first < last
pirot_point = partition(alist, first, last)
quick_sort_helper(alist, first, pirot_point - 1)
quick_sort_helper(alist, pirot_point + 1, last)
end
end
def partition(alist,... | true |
86456515cc6125e880688398d1960da85ca1da9c | Ruby | shjohnson/TotallyCoolArt | /spec/totally_cool_art_spec.rb | UTF-8 | 2,221 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require './lib/totally_cool_art/gallery.rb'
require './lib/totally_cool_art/ticket.rb'
describe TotallyCoolArt::Gallery do
describe '#list_of_galleries' do
it 'should return an array of galleries' do
html_data = double('return', parsed_response: 'gallery')
HTTParty.should_recei... | true |
a3a54d32d4bc3dd5f9512c359ec6d74141a8d698 | Ruby | djmaze/eye | /lib/eye/process/system.rb | UTF-8 | 1,761 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'timeout'
module Eye::Process::System
def load_pid_from_file
if File.exists?(self[:pid_file_ex])
_pid = File.read(self[:pid_file_ex]).to_i
_pid > 0 ? _pid : nil
end
end
def set_pid_from_file
self.pid = load_pid_from_file
end
def save_pid_to_file
if self.pid
F... | true |
b13aa2a2b7c0945606f84bc90a8d1ce1cefddbb1 | Ruby | Istanful/chess | /lib/chess/rook.rb | UTF-8 | 1,286 | 3.046875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "chess/piece"
module Chess
class Rook < Piece
def to_s
return '♖' if @color == :black
'♜'
end
def self.notation
'R'
end
def position
Vector.new(x, y)
end
def threatens?(board, point)
legal_destination?(board, point)
... | true |
5b7eea9e275c06219cafd171a81058655a0f8761 | Ruby | vikassanap/Ruby-Watir-Cucumber-Framework | /Automation/features/pages/login_page.rb | UTF-8 | 595 | 2.53125 | 3 | [] | no_license | class LoginPage
class << self
def email
$browser.text_field(:id,'Email')
end
def password
$browser.text_field(:id,'Passwd')
end
def signin
$browser.button(:id,'signIn')
end
def enter_email(value)
email.when_present.set value
end
def enter_password(value)
password.when_present.set ... | true |
96ec8a9541aa71949a448744bd1491d152cd4922 | Ruby | lmars/dotfiles | /home/.bin/randhex | UTF-8 | 367 | 3.25 | 3 | [] | no_license | #!/usr/bin/env ruby
# Print a random hex string
count = 32
require 'optparse'
OptionParser.new { |opts|
opts.on '-n', '--num COUNT', 'Number of characters (must be even)' do |c|
if c.to_i.odd?
$stderr.puts "ERROR: Count must be even"
exit 1
end
count = c.to_i
end
}.parse!(ARGV)
require '... | true |
85c8ea36a8e804383053cfd371bf41693e702e06 | Ruby | EmilFattakhov/WayHome | /WayHome/db/seeds.rb | UTF-8 | 2,447 | 2.71875 | 3 | [] | no_license | # 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 rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
25955aac7b0006167b35a5afa285b8afde14a385 | Ruby | pedrofernandezm/dockerization-example | /app/services/session_manager.rb | UTF-8 | 1,193 | 2.625 | 3 | [] | no_license | class SessionManager
attr_reader :auth_token
def initialize(auth_token)
@auth_token = auth_token
end
def valid?
valid_token? && session && not_expired_session?
end
def create!(params)
@email = params[:email]
authenticate_user!(params)
Session.create!(
expires_at: new_expires_at... | true |
284b157055cc17e7c84820d4c0c02305bae5e5ef | Ruby | japtar10101/game_jam_2010 | /controller/image.rb | UTF-8 | 919 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
require "rubygame"
# load the rest of the files
@root = File.dirname(__FILE__)
load @root + '/../model/image.rb'
load @root + '/../global.rb'
load @root + '/../layout.rb'
include Rubygame
include Rubygame::Events
include Rubygame::EventActions
include Rubygame::EventTriggers
# The Game class hel... | true |
051267a315e4ce6ac9458382d1cb28458c57c8a9 | Ruby | lishulongVI/leetcode | /ruby/419.Battleships in a Board(甲板上的战舰).rb | UTF-8 | 3,400 | 3.71875 | 4 | [
"MIT"
] | permissive | =begin
Given an 2D board, count how many battleships are in it. The battleships are represented with <code>'X'</code>s, empty slots are represented with <code>'.'</code>s. You may assume the following rules:
<ul>
<li>You receive a valid board, made of only battleships or empty slots.</li>
<li>Battleships can only be p... | true |
348f67b529c7e8617fbfcf062ad344749038ab8a | Ruby | philckwan/insight | /features/step_definitions/values.rb | UTF-8 | 2,963 | 2.765625 | 3 | [] | no_license | require 'watir'
require 'cucumber'
require 'test/unit'
require 'test-unit'
World(Test::Unit::Assertions)
Given(/^a Chrome web browser$/) do
#visit ValuesPage
#@WEBSITE = 'https://www.exercise1.com/values'
#@WEBSITE = 'C:/Users/Philip/RubymineProjects/insight/insight.html' # local html file for test spec
@WEBS... | true |
d8da57387c998aed24452eb5b8b0edb2dea856d2 | Ruby | onofricamila/TTPS-Ruby | /p2/p2e07.rb | UTF-8 | 1,067 | 3.671875 | 4 | [] | no_license | # 7. Modificá el código anterior para, acorde a tu análisis, corregir los problemas que pueda tener.
# Nota: asumí que el juego debe terminar al momento que el primer jugador supera la posición 40 en el tablero.
# Tira un dado virtual de 6 caras
def tirar_dado
rand 1..6
end
# Mueve la ficha de un jugador tantos casi... | true |
8dcaf702fb9e5b06ddec253a31d820a198d3635c | Ruby | lbrown528/minedmindskata | /tenones.rb | UTF-8 | 233 | 3.34375 | 3 | [] | no_license | #puts 1111111111
#10.times do |blueberrypie|
#blueberrypie += 1
#puts blueberrypie
#end
#1.upto(100) { |x| puts x }
#for x in 1..100 do
# puts x
#end
100.times do |n|
n +=1
if n == 5
puts "jerkchicken"
else
puts n
end
end
| true |
13d19f9eb6c2b836447817fba11e7339b04ec3f8 | Ruby | hitoyozake/shiritori | /kashiramozi.rb | UTF-8 | 221 | 3.46875 | 3 | [] | no_license |
#頭文字を得る
def get_head( word )
k = %w(あ か さ た な は ま や ら わ)
return k[ k.index{|i| i > word[0]}.to_i - 1 ]
end
#puts getkashira( "たまち") => た
#puts getkashira( "つむじ") => た
| true |
47b4b130d34129eb16edf733742322d3f73e6d28 | Ruby | isabella232/chalk-log | /test/functional/log.rb | UTF-8 | 8,209 | 2.59375 | 3 | [
"MIT"
] | permissive | require File.expand_path('../_lib', __FILE__)
require 'chalk-log'
module Critic::Functional
class LogTest < Test
def self.add_appender
unless @appender
@appender = ::Logging.appenders.string_io(
'test-stringio',
layout: Chalk::Log.layout
)
::Logging.logger.root.... | true |
52f9cdc1da7fcd54e9aec79602d1d1d53874b778 | Ruby | sinefunc/plcs | /vendor/dependencies/lib/dependencies/dep.rb | UTF-8 | 2,150 | 2.515625 | 3 | [
"MIT"
] | permissive | class Dep
class Dependency
attr :name
attr :version
attr :environment
attr :url
def initialize(name, version = nil, environment = nil, url = nil)
@name = name
@version = version if version && !version.empty?
@environment = environment ? environment.split(/\, ?/) : []
@url ... | true |
c03301d5eeeced61bfc37736632a5c1308c431b5 | Ruby | mefellows/linkedin2cv | /lib/linkedin2cv/renderer/latex_renderer.rb | UTF-8 | 1,676 | 2.9375 | 3 | [] | no_license | module Linkedin2CV
class LatexRenderer
# Public: Render a LaTeX document
#
#
def render(profile, options)
output = render_latex(profile, options)
output_filename = "#{options['output_file']}.latex"
render_pdf(output, output_filename)
end
# Public: Produce a Latex PDF
#
... | true |
07f6b487e12fe9121f302abd5d04d5ce33fbd177 | Ruby | cielavenir/procon | /hackerrank/find-hackerrank.rb | UTF-8 | 121 | 2.640625 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
gets.to_i.times{
s=gets.chomp
f=s=~/^hackerrank/
g=s=~/hackerrank$/
p f&&g ? 0 : f ? 1 : g ? 2 : -1
} | true |
c66e8e246315ce7c46d1804ca195426c973f64a9 | Ruby | tryphon/audiobank | /lib/ext_pathname.rb | UTF-8 | 422 | 3.03125 | 3 | [] | no_license | class Pathname
def include?(other)
absolute? == other.absolute? and other.to_s.start_with?(to_s)
end
def absolute_path_from(root)
unless absolute?
Pathname.new(root) + self
else
self
end
end
def absolute_path_from!(root)
absolute_path = absolute_path_from(root)
raise "#{a... | true |
4bfee4e0f25a8cd80dc3ca483b539e3793e39d9e | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/proverb/62580c253e4b47de8603ef5a95885af7.rb | UTF-8 | 707 | 3.296875 | 3 | [] | no_license | class Proverb
def initialize(*the_lost)
@the_lost = the_lost
@qualifier = extract_qualifier the_lost
end
def to_s
proverb = ''
(the_lost.size-1).times { |count| proverb += consequence count }
proverb += last_special_consequence
end
private
attr_reader :the_lost, :qualifier
def cons... | true |
493814ddbc2055274f11cfe51d1c54c01f109f5d | Ruby | DouglasAllen/code-Programming_Ruby_3rd_ed | /Part_IV--Ruby_Library_Reference/ch27_Built-in_Classes_and_Modules/Alphabetical_Listing/Exception/StandardError/NameError/NoMethodError/NoMethodError.rb | UTF-8 | 276 | 2.671875 | 3 | [] | no_license | NoMethodError.public_methods(false).sort.each do |method|
puts method
end
puts
NoMethodError.public_instance_methods(false).sort.each do |method|
puts method
end
puts
NoMethodError.constants.sort.each do |constant|
puts constant
end
puts
puts NoMethodError.superclass | true |
311598b8c03880b5335013e975943bdd0628acde | Ruby | Bundo101/cli_project | /lib/scraper.rb | UTF-8 | 2,041 | 2.859375 | 3 | [
"MIT"
] | permissive | #require_relative './movie.rb'
class Scraper
def scrape_list_page
doc = Nokogiri::HTML(open("https://www.businessinsider.com/worst-movies-all-time-according-to-critics-2017-8?r=US&IR=T"))
end
def scrape_movie_page(url)
doc = Nokogiri::HTML(open(url, 'User-Agent' => 'firefox'))
end
def create... | true |
4c46ee02cb16a783802ca258df4ba109c481b80e | Ruby | mildred/survie.mildred.fr | /lib/file_changes2.rb | UTF-8 | 857 | 2.53125 | 3 | [] | no_license |
def add_update_item_attributes
changes = MGutz::FileChanges.new
items.each do |item|
if item[:kind] == "article"
# filename might contain the created_at date
item[:created_at] ||= derive_created_at(item)
# sometimes nanoc3 stores created_at as Date instead of String causing a bunch of issue... | true |
fa2635d2f0aa88c71aa92abd34c29ec769b2a786 | Ruby | leninexe/aoc2018 | /19/19b.rb | UTF-8 | 170 | 3.03125 | 3 | [] | no_license | a = 0
d = 10551396
for b in 1..d
for f in 1..d
if b * f == d
print "#{b} * #{f} == #{d}\n"
a += b
end
break if b * f >= d
end
end
print "Result = #{a}\n" | true |
0cae381f3fce1062eee592f04885761332496b50 | Ruby | billwestfall/ruby | /lambda/chapt04/page067a.rb | UTF-8 | 284 | 2.953125 | 3 | [] | no_license | # MacBook-Air:lambda billw$ ruby page067a.rb
# You gobbled 4 apples
# You gobbled 3 apples
# You gobbled 2 apples
# You gobbled 1 apples
# MacBook-Air:lambda billw$
require 'rubygems'
require 'highline/import'
n = 4
while (n > 0 ) do
puts "You gobbled #{n} apples"
n = n - 1
end
| true |
f0ff56cf23fa5299e36dd32001f46c3fec6cde13 | Ruby | ian-garrett/ticTacToe | /app/controllers/games_controller.rb | UTF-8 | 3,296 | 2.546875 | 3 | [] | no_license | class GamesController < ApplicationController
respond_to :json
def show
respond_with Game.find(params[:id])
end
def create
# TODO: only allow a game between two _different_ players?
game = Game.new(game_params)
if game.save
render json: game, status: 201, location: [game]
else
... | true |
e34270a483fce7e4b12bbc6167f920984538a099 | Ruby | clodiap/CodeSignal | /lib/evenDigitsOnly.rb | UTF-8 | 292 | 3.90625 | 4 | [] | no_license | # Check if all digits of the given integer are even.
# Example
# For n = 248622, the output should be
# evenDigitsOnly(n) = true;
# For n = 642386, the output should be
# evenDigitsOnly(n) = false.
# my solution
def evenDigitsOnly(n)
n.digits.all? { |nb| nb.even? }
end
| true |
88b5f86c10fcd914f4721f61f99d59f398b0560d | Ruby | Seigo/Cuco | /app/models/pomodoro.rb | UTF-8 | 1,236 | 2.53125 | 3 | [] | no_license | class Pomodoro < ActiveRecord::Base
attr_accessible :user_id, :task_id, :init_time, :end_time, :comment, :i_interruption, :e_interruption
belongs_to :user
belongs_to :task
validates_presence_of :task_id, :user_id, :init_time, :end_time#, :percentage
# validate :check_dates, :check_ownage
#before_sa... | true |
b3013c7cdc2d0ced3ecdb8028fcae5bf165181d8 | Ruby | nogtk/design_pattern_on_ruby | /20_Flyweight/big_char.rb | UTF-8 | 402 | 2.859375 | 3 | [] | no_license | module FlyWeight
class BigChar
def initialize(char_name)
@char_name = char_name
@font_data = ""
File.open("font/big#{@char_name}.txt", 'r') do |f|
f.readlines.each do |line|
@font_data += "#{line}\n"
end
end
end
def print_font
print @font_data
... | true |
18361cb140be805411fdadd136766efc41ebc850 | Ruby | iafonov/chef-knockd | /libraries/default.rb | UTF-8 | 118 | 2.84375 | 3 | [
"MIT"
] | permissive | def generate_sequence(length)
result = []
length.to_i.times { result << 10000 + (rand * 10000).to_i }
result
end | true |
68ce561c5756b77b7d61720547248ee1174de8a9 | Ruby | kipFaceless/recipes | /db/seeds.rb | UTF-8 | 2,802 | 2.65625 | 3 | [] | no_license | # 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 rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
686050a086d4f5540f192c301208ea27d12d376e | Ruby | adamcrussell/perlweeklychallenge-club | /challenge-230/roger-bell-west/ruby/ch-2.rb | UTF-8 | 363 | 3.296875 | 3 | [] | no_license | #! /usr/bin/ruby
def prefixwords(s, p)
return s.count {|i| i.index(p) == 0}
end
require 'test/unit'
class TestPrefixwords < Test::Unit::TestCase
def test_ex1
assert_equal(2, prefixwords(['pay', 'attention', 'practice', 'attend'], 'at'))
end
def test_ex2
assert_equal(3, prefixwords(['janet', 'julia'... | true |
60df3dcf3c0e314ea1d5fca361abf639ce1ec378 | Ruby | vshaveyko/telegram_bot | /admin/app/quest_bot/user/update_location.rb | UTF-8 | 538 | 2.578125 | 3 | [] | no_license | # :nodoc:
class User::UpdateLocation
def initialize(user, message)
@user = user
@message = message
end
def call
save_user_location
invalidate_quest_cache
end
private
def save_user_location
@user.update!(
current_position: [long, lat],
latest_location_updated_a... | true |
8ef2e8b1dfcc9fca57eae4d2bc7119a69d419ce8 | Ruby | Gutylla/ctci-ruby | /regular_exp_match.rb | UTF-8 | 449 | 3.390625 | 3 | [] | no_license | # @param {String} s
# @param {String} p
# @return {Boolean}
def is_match(s, p)
i = 0
j = 0
while i < s.size
if s[i] == p[j] || p[j] == '.'
i += 1
j += 1
elsif p[j] == '*'
prev_char = p[j-1]
while i < s.size && (prev_char == s[i] || prev_char == '.')
i += 1
end
j... | true |
790550c91f8918c2ebd816a86e22bd3ce04d7980 | Ruby | kimoto/retry-handler | /lib/retry-handler.rb | UTF-8 | 1,528 | 3.171875 | 3 | [
"MIT"
] | permissive | require 'timeout'
require 'logger'
class RetryError < StandardError; end
class RetryOverError < RetryError; end
module RetryHandler
DEFAULT_MAX_RETRY = 3
DEFAULT_WAIT_TIME = 1
INFINITY_EXECUTE = nil
def self.retry_handler(options={}, &block)
max = options[:max] || DEFAULT_MAX_RETRY
wait = options[:wa... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.