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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5716446cfe517a27c8851c17342507741842d304 | Ruby | penta8/ltp | /10_chapter/4_99_bottles_of_beer.rb | UTF-8 | 664 | 4.4375 | 4 | [] | no_license | # Integer -> String
def bottles_of_beer(bottles)
if bottles.zero?
'No more bottles of beer on the wall, no more bottles of beer.\n' \
'Go to the store and buy some more, 99 bottles of beer on the wall.'
else
message(bottles) + "\n\n" + bottles_of_beer(bottles - 1)
end
end
def message(bottles)
no... | true |
8f4479a66a294a273ec6770fe353a469ff50b93e | Ruby | radioactive001/Caesar-cipher | /cipher.rb | UTF-8 | 477 | 3.40625 | 3 | [] | no_license | require 'sinatra'
get '/' do
str=params["str"].to_s
num=params["num"].to_i
message=cipher(str,num)
erb :index, :locals => {:message => message}
end
def cipher(str,num)
text=""
str.each_byte{
|x|
if (65..90)===x
if x+num>=90
x=((x+num)-90)+64
else
x=x+num
end
els... | true |
e91ab4a88d9e9bcdb9fd4e750a72522d26987039 | Ruby | keisuke713/original_code | /house_wife/washing_machine.rb | UTF-8 | 151 | 2.6875 | 3 | [] | no_license | class WashingMachine
def washing
wash
dry
'finish!'
end
def wash
'washing now!!!'
end
def dry
'drying now!!'
end
end
| true |
2fadf1554bacc829735e0d2720f617be92102681 | Ruby | Fukkatsuso/AtCoder | /BegginersSelection/Ruby/ABC083B.rb | UTF-8 | 408 | 3.984375 | 4 | [] | no_license | def sum_digit(i, a, b)
# 各桁の総和
sum = 0
while(i > 0) do
sum += i % 10
i /= 10
end
if a <= sum && sum <= b
return true
else
return false
end
end
line = gets.chomp.split(" ").map(&:to_i)
n = line[0]
a = line[1]
b = line[2]
ans = 0
(1..n).ea... | true |
d33c5503766f4fd11b67d7b41d1a15fa34423878 | Ruby | solarkennedy/project-euler-solutions | /6/6_redux.rb | UTF-8 | 140 | 3.078125 | 3 | [] | no_license | #!/usr/bin/env ruby
# Square of sums - Sum of squares
puts ((1..100).inject(:+))**2 - ((1..100).inject { |sum, x| sum + x*x })
| true |
f4c69bfb033568ba0d25f9fc80c5d1861bb5a7cd | Ruby | smoriwaki/jpmobile | /lib/jpmobile/util.rb | UTF-8 | 2,139 | 2.75 | 3 | [
"MIT"
] | permissive | require 'tempfile'
module Jpmobile
module Util
module_function
def deep_apply(obj, &proc)
case obj
when Hash
obj.each_pair do |key, value|
obj[key] = deep_apply(value, &proc)
end
when Array
obj.collect!{|value| deep_apply(value, &proc)}
when NilClass, ... | true |
0b7b9eb694ae63c954a578d6c50bfea8b55497d2 | Ruby | h4hany/yeet-the-leet | /algorithms/Medium/324.wiggle-sort-ii.rb | UTF-8 | 839 | 3.53125 | 4 | [] | no_license | #
# @lc app=leetcode id=324 lang=ruby
#
# [324] Wiggle Sort II
#
# https://leetcode.com/problems/wiggle-sort-ii/description/
#
# algorithms
# Medium (30.00%)
# Total Accepted: 85.4K
# Total Submissions: 284.7K
# Testcase Example: '[1,5,1,1,6,4]'
#
# Given an unsorted array nums, reorder it such that nums[0] < nums[... | true |
d1db35d1cca166eb0426ad7aca107ac586483aa5 | Ruby | jasontseli/cs198-hw1 | /foobar.rb | UTF-8 | 317 | 3.5 | 4 | [] | no_license | ##Jason Li September 20, 2016
class Foobar
def self.baz(a)
# Class method
# Call with `Foobar.baz`
b = Array.new
result = 0
for x in a
x_i = x.to_i + 2
if x_i % 2 == 0 && x_i <= 10 && !b.include?(x_i)
b.push(x_i)
result += x_i
end
end
return result
end
end
| true |
7faedd8f8aa7c44bf407f4394b350d6dd1f01626 | Ruby | gabrie30/RubyLearning | /1_week/2c_convert_challenge.rb | UTF-8 | 2,288 | 4.15625 | 4 | [] | no_license | # doctest: if ask_user returns a converting_to should equal Fahrenheit...etc
# >> %w(a b c d e).collect { |code| conversion_selector(code) }
# => ["Fahrenheit", "Celsius", "Kelvin", "Rankine", false]
def conversion_selector(code_letter)
case code_letter
when 'a'
'Fahrenheit'
when 'b'
'Celsius'
when 'c'
... | true |
7b37bc57debd53adb2bdfa4fde61186906dd7b7d | Ruby | TheDevelopment/hacknight_codewars | /q1_prime.rb | UTF-8 | 675 | 3.875 | 4 | [] | no_license | #!/usr/bin/ruby
require "rubygems"
require "inline"
#Stolen from http://on-ruby.blogspot.com/2006/07/rubyinline-making-making-things-faster.html
class Primes
inline do |builder|
builder.c '
int prime(int num) {
int x;
for (x = 2; x < (num - 1) ; x++) {
if (num == 2) {
return ... | true |
48df0c19b2fc8e553b364fbb7c6089c713255d95 | Ruby | Rodrigo33024/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 537 | 3.890625 | 4 | [] | no_license | def echo(say)
say
end
def shout(say)
say.upcase
end
def repeat(say, default = 2)
([say] * default).join ' '
end
def start_of_word(word, chars)
word.slice(0, chars)
end
def first_word(paragraph)
paragraph.split(' ')[0]
end
def titleize(words)
finalCase = []
reserverWords = ['of', 'over', 'of', 'and',... | true |
e510198bad42ebbe1ee43d30561438af0f84424c | Ruby | gortron/heros-journey | /lib/journey.rb | UTF-8 | 1,680 | 3.234375 | 3 | [
"MIT"
] | permissive | class Journey < ActiveRecord::Base
include Display
include Generators
belongs_to :hero
belongs_to :monster
# Starts a journey and joins a Monster to a Hero
def self.start(hero)
monster = Monster.all.sample
hero.monsters << monster
end
# Logic that handles when a player chooses Fight
def figh... | true |
126f5bf566f554d74e296a3606b012baaa263993 | Ruby | ipmsteven/ae_page_objects | /lib/ae_page_objects/element_proxy.rb | UTF-8 | 1,507 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'timeout'
module AePageObjects
class ElementProxy
# Remove all instance methods so even things like class()
# get handled by method_missing(). <lifted from activerecord>
instance_methods.each do |m|
unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to/
undef_method... | true |
10cd8af056ad196c6a05bdd771de81da67461e7d | Ruby | slbccfl/Ironhack | /Week 1/Chess validator/lib/knight.rb | UTF-8 | 297 | 3.6875 | 4 | [] | no_license | #knight.rb
class Knight
def initialize(x,y,color)
@x = x
@y = y
@color = color
end
def can_move?(final_x, final_y)
delta_x = (final_x - @x).abs
delta_y = (final_y - @y).abs
if (delta_x == 2 && delta_y == 1 ) || (delta_y == 2 && delta_x == 1 )
"yes"
else
"no"
end
end
end | true |
e71c96adf1cdf5b1bac1840e79212cd952fa56cb | Ruby | JackDanger/silent_voices | /ruby/lib/silent_voices/compiler.rb | UTF-8 | 3,241 | 2.765625 | 3 | [] | no_license | module SilentVoices
class Compiler
def initialize source, level
@source = source
@level = level
set_feminizing_forms
end
def process *media
@compiled = compile
write_layout media
end
protected
def run_books?
%{books fast}.include? @level
end
... | true |
a719793c678999b0787ea802e06f3ca9716ffc34 | Ruby | leslieyi/postwork-data-structures-and-algorithms | /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/ruby/queue.rb | UTF-8 | 907 | 3.1875 | 3 | [] | no_license | class Queue
attr_reader :limit
def initialize
@queue = []
# this is an arbitrary value to make testing easier
# 1,024 would be way too high to test!
@limit = 10
end
# add item to rear of queue if not full
# if full, throw error
def enqueue(item)
end
# remove item from front of queue a... | true |
efa782680792295402135d677099a2d9c1d63115 | Ruby | darreneid/w1 | /d1/Player.rb | UTF-8 | 472 | 4.0625 | 4 | [] | no_license | class Player
def initialize(name)
@name = name
@losses = 0
@game_name = "GHOST"
@game_status = ""
end
def losses(x = @losses)
@losses = x
@losses
end
def ghost(x = @ghost)
@ghost = x
@ghost
end
def name
@name
end
def... | true |
beddb57e71933dae7d793d5d795249114073a29f | Ruby | rike422/understanding_computation | /chapter_two/2_3_1_1_2_2.rb | UTF-8 | 271 | 2.71875 | 3 | [] | no_license | require './2_3_1_1_2.rb'
Multiply.new(
Number.new(1),
Multiply.new(
Add.new(Number.new(2), Number.new(3)),
Number.new(4)
)
).to_s
expression =
Add.new(
Multiply.new(Number.new(1), Number.new(2)),
Multiply.new(Number.new(3), Number.new(4)),
)
| true |
92cce8be305fd9981eddfce0a49b188977ac3200 | Ruby | cemeng/tiny-shopping-cart | /ruby/lib/products_repository.rb | UTF-8 | 410 | 2.734375 | 3 | [] | no_license | class ProductsRepository
RULES = [
{ code: 'ult_small', name: 'Unlimited 1GB', price: 24.9 },
{ code: 'ult_medium', name: 'Unlimited 2GB', price: 29.9 },
{ code: 'ult_large', name: 'Unlimited 5GB', price: 44.9 },
{ code: '1gb', name: '1 GB Data-pack', price: 9.90 }
]
def self.find_by_pro... | true |
b0d8bf30dc40a726d9d5a6f91f819b389fbd8bdc | Ruby | markyv18/shelter | /spec/models/direction_spec.rb | UTF-8 | 1,177 | 2.90625 | 3 | [] | no_license | require "rails_helper"
describe Direction do
it "successfuly initializes with valid attrs" do
steps = [
{:distance=>{text: "0.1 mi"},
:duration=>{text: "1 min"},
:html_instructions=>
"Head <b>southeast</b> on <b>17th St</b> toward <b>Larimer St</b>"},
... | true |
8f630547712d4519f958b68b00e096a2e0dec553 | Ruby | ZeusPerez/checkout_ruby_challenge | /spec/item_catalog_spec.rb | UTF-8 | 781 | 2.765625 | 3 | [] | no_license | require_relative '../lib/item_catalog'
describe ItemCatalog do
describe "#get_price_of" do
it "extracts the price of a item from the JSON prices file" do
price = ItemCatalog.get_price_of("MUG")
expect(price).to eq(7.5)
end
it "raises error if the item is not in the catalog" do
expect {... | true |
6929fc835bf70d742594856d86a9c7e7d3c669c7 | Ruby | fvfdesign/Bootcamp_Ironhack | /SEMANA01/day01/citiesreduce.rb | UTF-8 | 439 | 3.5 | 4 | [] | no_license | cities = ["miami", "madrid", "barcelona"]
sum = cities.reduce(0.0) {|sum, city| sum + city.length}
puts average
puts sum / cities.length
# dos ceros para dejarlo fluir y que no se atasque
sum = cities.reduce (0.0) do |sum, city|
sum + city.length
end
puts sum / cities.length
# ESTO NO FUNCIONARIA:
# # cities = ... | true |
943212d77ddcdb5112bb38f09bd4bcd87f9618dc | Ruby | SciRuby/mdarray | /test/mdarray/test_views.rb | UTF-8 | 14,044 | 3.171875 | 3 | [
"NetCDF",
"BSD-2-Clause"
] | permissive | # -*- coding: utf-8 -*-
##########################################################################################
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
# and distribute this software and its documentation, without fee and without a signed
# licensing agreement, i... | true |
f382222b54e0cca47c67d8ec35e38e6fd1d1825a | Ruby | nctruong/ruby_advanced | /rubyblock.rb | UTF-8 | 543 | 4.34375 | 4 | [] | no_license | # using yield, no argument
def speak
puts yield
end
speak { "Hello There"}
# block with arguments
def block_with_argument(first, second)
yield(first, second)
end
block_with_argument("first", "second") { |f,s|
puts f
puts s
}
def read_number(number)
case number
when 1
mes = "one"
when 2
m... | true |
1a8022719acc30ea07355e630745e7bfa1486e80 | Ruby | trrr/fd | /app/workers/posts_fetcher.rb | UTF-8 | 1,118 | 2.6875 | 3 | [] | no_license | class PostsFetcher
@queue = :fetcher_queue
def self.perform(id)
fetch_and_save_author_posts(Author.find(id))
end
def self.fetch_and_save_author_posts(author)
raw_posts = fetch_posts(author)
posts = serialize_posts(raw_posts)
check_for_dublications_and_save_posts(posts, author)
end
def sel... | true |
c4866fed15d4968599f906e95d324b692e4f7d05 | Ruby | timlkelly/phase-0 | /week-5/die-class/my_solution.rb | UTF-8 | 2,447 | 4.34375 | 4 | [
"MIT"
] | permissive | # Die Class 1: Numeric
# I worked on this challenge [by myself]
# I spent [] hours on this challenge.
# 0. Pseudocode
# Input: die with a number of sides
# Output: a random number
# Steps:
# -create die class
# -allow it to roll a random number based on the number of sides
# 1. Initial Solution
# class Die
# ... | true |
aa2393021774300c91ad97b14db1f0fba05b3234 | Ruby | amirharis/Workplace | /ruby/rand2.rb | UTF-8 | 248 | 3.1875 | 3 | [] | no_license | alphanumerics = [('0'..'9'),('A'..'Z'),('a'..'z')].map {|range| range.to_a}.flatten
a = (0...7).map { alphanumerics[Kernel.rand(alphanumerics.size)] }.join
b = (0...7).collect { alphanumerics[Kernel.rand(alphanumerics.length)] }.join
puts a
puts b
| true |
ccb5533f200537db0efdee764572aba1b310e28f | Ruby | bhardin/Android-Netrunner-tournament | /spec/match_spec.rb | UTF-8 | 3,443 | 2.59375 | 3 | [] | no_license | require './spec/spec_helper'
describe Match do
let(:player1) { FactoryGirl.build(:player)}
let(:player2) { FactoryGirl.build(:player)}
before :each do
@match = Match.new(player1, player2)
end
describe "initialize" do
it "sets player_one" do
@match.player_one.should be
end
it "sets player_two" do
... | true |
2bde081ff332c1c0d5e75df6c671a6ae01dfab77 | Ruby | niwatolli3/niwa_textream | /lib/niwa_textream/pages/thread/thread_page.rb | UTF-8 | 1,865 | 2.75 | 3 | [
"MIT"
] | permissive | require 'niwa_textream/pages/main/main_page.rb'
require 'niwa_textream/models/thread'
require 'niwa_textream/pages/message/message_page'
module NiwaTextream
# thread list
class ThreadPage < MainPage
@@url = "http://textream.yahoo.co.jp/thread/%{category_id}"
@threads = nil
@next_page_elem
@prev_pag... | true |
4f34a6862467f466c897a0cdd7746bcebaa69065 | Ruby | bullfight/knmi | /lib/knmi/parameters.rb | UTF-8 | 3,384 | 3.046875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module KNMI
class Parameters
class << self
attr_writer :keys_file
# Retrieve Parameter Object by named parameter
#
# @param period [String] - "daily" or "hourly"
# @param parameter [Array, String] - Array of strings or string of parameter name
# @return [Array<KNMI::Para... | true |
c11f6d1be431115ccd0fc0982fd22b3a59f6e83a | Ruby | nomadium/beryl | /spec/beryl/parser_spec.rb | UTF-8 | 540 | 2.515625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "spec_helper"
RSpec.describe Beryl::Parser do
subject(:parser) { described_class.new }
describe "#parse" do
context "when valid syntax is provided" do
it "parses integers" do
code = "42"
ast = parser.parse(code)
expect(ast.value).to eq(code.... | true |
deab2827eef00307579538e62ad9d2d0dfef2da8 | Ruby | inrazhtet/PineRoRExercises | /chapternine/ch9prac.rb | UTF-8 | 2,504 | 3.921875 | 4 | [] | no_license | #Writng your own methods
#momo method
def say_moo
puts 'mooooooooooo...'
end
say_moo
say_moo
puts 'coin-coin'
say_moo
say_moo
#Method parameters
def say_moo number_of_moos
puts 'moooooooo.......' * number_of_moos
end
say_moo 3
puts 'oink-oink'
#Local Variables
def double_this num
num_times_2 = num*2
puts num.... | true |
4b49f0e362cb7cbcd9c010132d439aae246be334 | Ruby | franccesco/tmg | /lib/tmg/cli/wiki.rb | UTF-8 | 425 | 2.515625 | 3 | [
"MIT"
] | permissive | module Tmg
class CLI < Thor
desc 'wiki', 'Open browser to gem\'s wiki'
# Open browser and navigates to gem's wiki
def wiki(gem)
wiki_uri = Gems.info(gem)['wiki_uri']
if wiki_uri.nil? || wiki_uri.empty?
puts "No wiki page for ".red.bold + gem.yellow.bold
exit(1)
else
... | true |
234bb5c881eda9ac751b6a0cc40389c6485f863c | Ruby | joonty/torkify | /lib/torkify/conductor.rb | UTF-8 | 1,076 | 2.796875 | 3 | [
"MIT"
] | permissive | require_relative 'event/basic_event'
require_relative 'event/parser'
require_relative 'event/dispatcher'
require_relative 'log/parser'
module Torkify
# Connect the socket reader and observers, and dispatch events.
class Conductor
# Create with a set of observers.
def initialize(observers)
@dispatche... | true |
c3a2d3af72a967b0751a0288b76a99e82cba7d54 | Ruby | Elinpf/baidu_fanyi | /llwd_klass.rb | UTF-8 | 2,737 | 2.734375 | 3 | [] | no_license | #!/usr/bin/env ruby
require "digest/md5"
require "net/http"
require "uri"
require "json"
require "./config"
module Baidu
class Trans
attr_reader :http, :md5, :encode, :myurl
attr_accessor :appid, :secret_key, :from, :to
attr_accessor :q, :salt, :sign
def initialize
@http = Net::HTTP.new("api.fanyi.baidu.... | true |
d482029751731122e3b8f325dd6087473ed14eac | Ruby | rainly/pjeip | /lib/core_extensions/string.rb | UTF-8 | 371 | 2.578125 | 3 | [] | no_license | module CoreExtensions::String
def self.included(base)
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
end
module ClassMethods
end
module InstanceMethods
#字符串转换布尔
def to_bool
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(self)
end
end
end
String.se... | true |
1a2f06b21c79a8c85d0a6b3aa9e5f9d7ee5a7800 | Ruby | micahmosley/programming-univbasics-4-square-array-atx01-seng-ft-071320 | /lib/square_array.rb | UTF-8 | 136 | 3.28125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
counter=0
while counter<array.length
array[counter]=array[counter]**2
counter+=1
end
array
end | true |
822c64bbdcc4539967b2cea6f7beac3e77493bec | Ruby | caiogouveia/bearclaws | /lib/bearclaws/group.rb | UTF-8 | 944 | 3.21875 | 3 | [
"MIT"
] | permissive | module Bearclaws
# A grouped representation of AWS charges
#
# @attr name [String] The tag by which the charges are grouped
# @attr charges [Array] An array of Bearclaws::Charge objects
class Group
attr_accessor :name
attr_accessor :charges
# @param name [String] The tag by which the charges are... | true |
856ef649d9b45c3a2b53758d6ea05b04f37718ce | Ruby | PacerPRO/saxinator | /lib/saxinator/result_hash.rb | UTF-8 | 1,259 | 3 | 3 | [
"MIT"
] | permissive | # TODO: comment this file ...
module Saxinator
# ...
class ResultHash
attr_reader :inner_value
# ...
def initialize(base_value)
@inner_value =
case base_value
when nil
{ values: [] }
when Array
{ values: base_value }
when Hash
{ values... | true |
72f57dafb0658ccfd4e9b414eae9b9ec6402b514 | Ruby | IkukoS/phase-0-tracks | /ruby/list/todo_list.rb | UTF-8 | 297 | 3.453125 | 3 | [] | no_license | class TodoList
def initialize(task_array)
@list = task_array
end
def add_item(new_task)
@list << new_task
end
def delete_item(completed_task)
@list.delete(completed_task)
end
def get_item(index_number)
@list[index_number]
end
def get_items
@list
end
end | true |
7ac166fbdae24ea5a319e42f47f12433a26713c3 | Ruby | 1campbellj/project_euler | /pe33.rb | UTF-8 | 546 | 3.234375 | 3 | [] | no_license | result_num = 1
result_denom = 1
(10..99).each do |num|
(num+1..99).each do |denom|
next if num >= denom || num%10 + denom%10 == 0
ns = num.to_s
ds = denom.to_s
ns.split("").each do |i|
new_ds = ds.gsub(i, "")
if new_ds != ds
new_ns = ns.gsub(i, "")
next if new_ds.to_i == 0... | true |
2fd5915f45a68fd978697d5b1e10c5a97aadfd5a | Ruby | MagneticRegulus/101-Programming-Foundations | /lesson_4/additional_practice/practice_9.rb | UTF-8 | 428 | 4.53125 | 5 | [] | no_license | # This method in Ruby on Rails creates a string that has each word capitalized as
# it would be in a title. For example, the string:
words = "the flintstones rock"
# would be:
# words = "The Flintstones Rock"
# Write your own version of the rails titleize implementation.
def titleize(string)
string.split(' ').map ... | true |
6916dc3128016eff21d08c135a46997724630bbb | Ruby | orbanbotond/ruby_exercise | /spec/algorythms/alg_dynamic_programming_lesson_spec.rb | UTF-8 | 1,139 | 3.046875 | 3 | [] | no_license | require 'spec_helper'
describe 'dynamic programming' do
def solution_frog_jump(jumping_distances, distance)
n = jumping_distances.size - 1
dp=[1]+[0]*distance
1.upto(distance) do |j|
jumping_distances.each do |distance|
if distance <= j
dp[j] += dp[j - distance]
end
... | true |
047ea63ae192e1390554c2b8fe49752f74ec52f4 | Ruby | cotarg/FarMar | /sandbox/lib/farmar_sale.rb | UTF-8 | 2,341 | 3.34375 | 3 | [] | no_license | class FarMar::Sale
attr_reader :id, :amount, :purchase_time, :vendor_id, :product_id
def initialize(sale_hash)
# ID - (Fixnum) uniquely identifies the product
# Amount - (Fixnum) the amount of the transaction, in cents (i.e., 150 would be $1.50)
# Purchase_time - (Datetime) when the sale was completed
... | true |
d7bb9b703cb8854e94f0d507c2bfd6efbbeefb0c | Ruby | yoshi3315/cherry_book | /sample/chapter_5/2.rb | UTF-8 | 200 | 3.21875 | 3 | [] | no_license | # 5.2.2
correncies = { japan: 'yen', us: 'dollar', india: 'rupee'}
correncies.each do |key, value|
puts "#{key}: #{value}"
end
correncies.each do |key_value|
p key_value
end
p correncies.size
| true |
2504608320158782e936bf50b2ba183fd18243a8 | Ruby | iijijii/pazzles | /ex2-2.rb | UTF-8 | 142 | 3 | 3 | [] | no_license | n = 4
(1..n * 2).each do |k|
empty_str = ' ' * (n - k).abs
sharp = '#' * (n - (n - k).abs) * 2
puts "#{empty_str}#{sharp}#{empty_str}"
end
| true |
744b996662b006d401f2409b41e48aed3939d189 | Ruby | Eden-Eltume/101 | /101_Exercises/Small_Problems/Easy_1/ex7.rb | UTF-8 | 309 | 3.671875 | 4 | [] | no_license | def stringy(int)
bits = ['1','0']
bits_array = []
int.times do |time|
if time.odd?
bits_array << bits[1]
else
bits_array << bits[0]
end
end
bits_array.join
end
puts stringy(6) == '101010'
puts stringy(9) == '101010101'
puts stringy(4) == '1010'
puts stringy(7) == '1010101'
| true |
207066293d7077202f213aee39aee6db3277113f | Ruby | junwen29/Splurge-rails | /app/services/device_service.rb | UTF-8 | 312 | 2.671875 | 3 | [] | no_license |
class DeviceService
module ClassMethods
def tokens_by_user(user_id)
tokens = []
user = User.find(user_id)
devices = user.devices
devices.each { |device|
tokens << device.token
}
return tokens
end
end
class << self
include ClassMethods
end
end | true |
fb8a1ae1289d6c727576b2b3dd6c34504a5d02da | Ruby | shaulp/dex2 | /app/models/date_property.rb | UTF-8 | 477 | 2.828125 | 3 | [] | no_license | class DateProperty < Property
ApplicableConditions = [
Conditions::Mandatory, Conditions::Unique, Conditions::GreaterThan,
Conditions::LessThan, Conditions::GreaterOrEqual, Conditions::LessOrEqual,
Conditions::List, Conditions::Referrence
]
def self.applicable_condition?(c)
ApplicableConditions.member? c.... | true |
08a9cc5d8a459ed80c49a20e74bfae36f6c68c30 | Ruby | CADBOT/sea-c21-ruby | /lib/class3/exercise1.rb | UTF-8 | 1,663 | 4.28125 | 4 | [
"MIT"
] | permissive | # 5 points
#
# Write a program that displays the lyrics to the beloved nursery rhyme
# "3 Bottles of Beer on the Wall".
#
# Here's how the program must work:
#
# $ ruby exercise1.rb
# 3 bottles of beer on the wall, 3 bottles of beer!
# Take one down, pass it around, 2 bottles of beer on the wall!
# 2 bottles of... | true |
91d9fb3afd722e9e1d111b92cde36a4d01a36703 | Ruby | HYUNMIN-HWANG/opentutorial_python_ruby | /12.function/3.1_input.rb | UTF-8 | 51 | 2.984375 | 3 | [] | no_license | def a(num)
return 'a'*num
end
puts(a(100))
| true |
57ed86827c824070282d632e0aa6c3db25a78070 | Ruby | komald4/programming-univbasics-4-array-simple-array-manipulations-nyc04-seng-ft-012720 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 1,170 | 3.546875 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_push(array, elements)
colors_in_the_rainbow = ["red", "orange", "yellow", "green", "blue", "indigo"]
next_color = "violet"
colors_in_the_rainbow.push(next_color)
end
def using_unshift(array, elements)
bouroughs_in_nyc = ["Brooklyn", "Queens", "Manhattan", "Bronx"]
new_neighborhood = "Staten Island"... | true |
2c1b4cdaa5ee4c838f5ed50a952b1bfc6b0a132a | Ruby | JBelta/enigma | /test/key_test.rb | UTF-8 | 359 | 2.53125 | 3 | [] | no_license | require_relative 'test_helper'
require './lib/key'
require 'minitest/autorun'
require 'minitest/pride'
require 'pry'
class KeyTest < Minitest::Test
def test_it_exists
key = Key.new
assert_instance_of Key, key
end
def test_it_has_attributes
key = Key.new
assert_instance_of Array, key.numbers
asser... | true |
5aab28064598e24880be2a3192d5c618d895f3b2 | Ruby | sarahemm/ruby-zwave | /lib/zwave.rb | UTF-8 | 9,270 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'serialport'
require 'zwave/constants.rb'
module ZWave
class SerialAPI
attr_reader :interface_node_id, :home_id
RETRY_DELAY = 500
def initialize(port, speed = 115200, debug = false, protocol_debug = false)
@debug = debug
@protocol_debug = protocol_debug
... | true |
5d4c3d6f616e2fcb81a670bf4946d6787cbb1e0e | Ruby | proiel/proiel | /lib/proiel/sentence.rb | UTF-8 | 8,231 | 2.796875 | 3 | [
"MIT"
] | permissive | #--
# Copyright (c) 2015-2016 Marius L. Jøhndal
#
# See LICENSE in the top-level source directory for licensing terms.
#++
module PROIEL
# A sentence object in a treebank.
class Sentence < TreebankObject
extend Memoist
# @return [Fixnum] ID of the sentence
attr_reader :id
# @return [Div] parent di... | true |
984724830be2fd1fa398a58d1e5603c2f9076824 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/fb002840dd27427c9c3f20bc23d16b37.rb | UTF-8 | 302 | 4.21875 | 4 | [] | no_license | puts 'Hi, I\'m Bob.'
while(1) do
print 'What do you want to say to Bob: '
response = gets.chomp
if response.size == 0
puts 'Fine. Be that way!'
elsif response[-1] == '?'
puts 'Sure.'
elsif response.upcase == response
puts 'Woah, chill out!'
else
puts 'Whatever.'
end
end
| true |
e289ea4032b7e3c5b77a4bbe5202fd7c0ec42961 | Ruby | TheOdinProject/theodinproject | /app/models/point.rb | UTF-8 | 319 | 2.515625 | 3 | [
"MIT"
] | permissive | class Point < ApplicationRecord
LOWEST_ALLOWED_INCREMENT = 1
MAX_ALLOWED_INCREMENT = 5
validates :discord_id, presence: true, uniqueness: true
def increment_points_by(value)
return unless value.between?(LOWEST_ALLOWED_INCREMENT, MAX_ALLOWED_INCREMENT)
update!(points: self.points += value)
end
end
| true |
388bc0426408e9850980b26bedf0d4d3ac3eba9f | Ruby | langlk/word_definer | /spec/word_spec.rb | UTF-8 | 2,551 | 3.203125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'rspec'
require 'word'
describe('WordDefiner::Word') do
before() do
WordDefiner::Word.clear_all
end
it "stores a word inputted by a user" do
palindrome = WordDefiner::Word.new({:term => "Palindrome"})
expect(palindrome.term).to(eq("Palindrome"))
end
it "stores a wor... | true |
87a51b9ebbb937165a4af854d8ad5930ac4727ce | Ruby | tmerrr/bank-tech-test | /lib/bank_account.rb | UTF-8 | 1,087 | 3.3125 | 3 | [] | no_license | require_relative 'transaction_log'
require_relative 'balance'
require_relative 'printer'
# Bank Account Class
class BankAccount
def initialize(
starting_balance = 0,
balance_class = Balance,
transaction_log_class = TransactionLog,
printer_class = Printer
)
@balance ... | true |
fc01f27d87a6695ffb40248cc730af445fa817eb | Ruby | satishkunisi/ruby_binary_tree | /tests/node_test.rb | UTF-8 | 1,041 | 2.71875 | 3 | [] | no_license | require 'minitest/autorun'
require_relative '../node'
class TestNode < MiniTest::Unit::TestCase
def setup
@node = Node.new
end
def parent
@parent = Node.new
end
def test_responds_to_parent
assert @node.respond_to?(:value)
end
def test_responds_to_parent
assert @node.respond_to?(:pare... | true |
4082f6f7fd8602a0d53e48444f0ad57380d7f64d | Ruby | Isikapowers/enigma | /spec/rotation_spec.rb | UTF-8 | 3,055 | 3.484375 | 3 | [] | no_license | require "simplecov"
SimpleCov.start
require "date"
require "./lib/rotation"
require "./lib/shift"
RSpec.describe Rotation do
context "States" do
rotation = Rotation.new("hello world")
it "exists and has attributes" do
expect(rotation).to be_a(Rotation)
expect(rotation.message).to eq("hello worl... | true |
adefe2840e6e9967cb01fce9b1604b22afe36d9a | Ruby | zederson/chain_control | /lib/chain_control/function.rb | UTF-8 | 1,118 | 2.890625 | 3 | [
"MIT"
] | permissive | module ChainControl
class Function
attr_reader :target, :validation, :operation, :options, :successor
def initialize(target, validation, operation, options = {})
@target = target
@validation = validation
@operation = operation
@options = options
end
def applicable?
exec... | true |
2c1f6721e71de15119bde11ce9511b7e6f86faab | Ruby | nicleemart/pokedexProject | /tests/unit/pokedex_test.rb | UTF-8 | 6,481 | 2.953125 | 3 | [] | no_license | # require 'test_helper'
# class PokedexTest < Minitest::Test
# def setup
# super
# require 'csv'
# file = 'tests/unit/pokedex.csv'
# new_pokemon = ["ZCharmander,5,2,male,35,30,on,Charmander,Charmeleon,Charizard,fire", "BCharmander,5,2,male,35,30,on,Charmander,Charmeleon,Charizard,fire","Charmander,5,2,male,... | true |
6c1c9565b467172cb59c061e602d663420ce6cde | Ruby | christeiro/pre-course | /companion-workbook/easy/quiz-3/quiz3.rb | UTF-8 | 215 | 3.859375 | 4 | [] | no_license | # quiz3.rb
# How can we add multiple items to our array? (Dino and Hoppy)
flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
flintstones.push("Dino").push("Hoppy")
# Solution
flintstones.concat(%w(Dino Hoppy)) | true |
5b0c2ac9b9e1977b94287ca204ff779874e2ee5c | Ruby | frodsan/ruter | /lib/ruter/core/response.rb | UTF-8 | 4,683 | 2.921875 | 3 | [
"MIT"
] | permissive | class Ruter
module Core
# Public: It provides convenience methods to construct a Rack response.
#
# Examples
#
# res = Ruter::Core::Response.new
#
# res.status = 200
# res["Content-Type"] = "text/html"
# res.write("foo")
#
# res.finish
# # => [200, { "Conten... | true |
2e60803619ce0d0b2afdf57d68ee9a7287b6eaf0 | Ruby | shanik1986/LS-Course101 | /Lesson4/select_fruit.rb | UTF-8 | 514 | 3.734375 | 4 | [] | no_license | require 'pry'
def select_fruit(hsh)
items = hsh.keys
counter = 0
only_fruit = {}
loop do
break if counter >= items.size
current_key = items[counter]
current_value = hsh[current_key]
if current_value == 'Fruit'
only_fruit[current_key] = current_value
end
counter += 1
end
onl... | true |
2a62982322d48823f8e27e1ab03a8fe7d07a5b75 | Ruby | akicho8/ruby_design_pattern | /old/read_write_lock.rb | UTF-8 | 1,361 | 2.90625 | 3 | [] | no_license | # Read-Write Lock - read中はwrite禁止
require "sync"
class Buffer
def initialize
@sync = Sync.new
@str = ""
end
def write(_str)
@sync.synchronize(:EX) do
_str.chars.with_index do |c, i|
sleep(0.0001)
@str[i] = c
end
end
end
def read
@sync.synchronize(:SH) do
... | true |
4ac9ae5d3ee194af25cb9a9babc767c318e32707 | Ruby | ChristopherTulip/pineapple-repairs | /app/modules/wizard.rb | UTF-8 | 1,176 | 2.71875 | 3 | [] | no_license | module Wizard
extend ActiveSupport::Concern
included do
attr_writer :current_step
end
def next_state back
if ( back.present? && !step?(0) )
previous_step
elsif last_step?
if all_valid?
self.current_step = nil
self.save!
end
elsif valid?
next_step
... | true |
f625e623ed99b4bfd4c110f55e7768506394a64b | Ruby | thetinahang/ttt-with-ai-project-v-000 | /lib/board.rb | UTF-8 | 1,164 | 4.25 | 4 | [] | no_license | class Board # represents the data and logic of a TTT game board
attr_accessor :cells
def initialize # has property cells
self.reset!
end
def reset! # back to an "empty" array
@cells = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
end
def display # uses @cells to display board
puts " #{@cells[0]} | #{@... | true |
c5d3dffe4b899c7fd5800365fa4cae1d9cf9fd0a | Ruby | leahwho/media-ranker | /test/models/vote_test.rb | UTF-8 | 3,412 | 2.515625 | 3 | [] | no_license | require "test_helper"
describe Vote do
before do
@user = users(:leah)
@work = works(:moonstruck)
@vote = Vote.create(user_id: @user.id, work_id: @work.id)
end
it 'can be instantiated' do
expect(@vote.valid?).must_equal true
end
it 'has required fields' do
[:work_id, :user_id].each ... | true |
8682f64e1a342c6dea60485b96aa5883f58b6a37 | Ruby | Hackinfinity/intrigue-core | /lib/tasks/aws_s3_bruteforce_buckets.rb | UTF-8 | 3,885 | 2.578125 | 3 | [
"BSD-3-Clause"
] | permissive | module Intrigue
module Task
class AwsS3Brute < BaseTask
include Intrigue::Task::Web
def self.metadata
{
name: 'aws_s3_bruteforce_buckets',
pretty_name: 'AWS S3 Bruteforce Buckets',
authors: ['jcran', 'maxim'],
description: 'This task takes any keywords ... | true |
93e2aeabf092ce150f8b9b7959719fff549288dc | Ruby | anaalta/Bank_account_tech_test | /lib/account.rb | UTF-8 | 703 | 3.65625 | 4 | [] | no_license | require 'date'
class Account
attr_reader :balance, :history
def initialize(balance = 0)
@balance = balance
@history = []
end
def deposit(sum)
@balance = @balance + sum
@date = Date.today
@history << {{@date => +sum} => @balance}
end
def withdraw(sum)
@balance = @balance - su... | true |
a506ca41575284ec01090f3dd7488115fb0e28cd | Ruby | dylanconnolly/enigma | /lib/encrypt.rb | UTF-8 | 420 | 3.0625 | 3 | [] | no_license | require './lib/enigma'
require './lib/key_generator'
require './lib/offset_generator'
require './lib/shift'
file = File.open(ARGV[0], "r")
message = file.read.chomp
file.close
enigma = Enigma.new
encryption = enigma.encrypt(message)
new_file = File.open(ARGV[1], "w")
new_file.write(encryption[:encryption])
new_file... | true |
a0a5491b13b0d0194fa212c8652a9abfdd773089 | Ruby | nabu1615/ruby-intro | /challenges/ruby/23-file-system/clases/argv.rb | UTF-8 | 280 | 3.109375 | 3 | [] | no_license | if ARGV.index("--user") && ARGV.index("--greeting")
name_index = ARGV.index("--user") + 1
name_value = ARGV[name_index]
greeting_index = ARGV.index("--greeting") + 1
greeting_value = ARGV[greeting_index]
p "Hola #{name_value} #{greeting_value}"
else
p 'Algo salio mal'
end
| true |
7e6694d85a4cc4ccc1a489a52c1eaa3ef3e6aaa0 | Ruby | dzl84/threeban | /lib/CSGS_parser.rb | UTF-8 | 3,301 | 2.65625 | 3 | [] | no_license | # encoding: UTF-8
require_relative "http_helper"
require "nokogiri"
require "json"
require "time"
require_relative "models"
require_relative "broker"
require_relative "utils"
module Parser
class TopUserParser
def initialize(config_file = nil)
@deals = {}
@broker = Broker.new
@run_times_after_t... | true |
1f6feb89a3c5b22e95f0210f3915428eb69e909f | Ruby | nvnogomes/peuler | /029.rb | UTF-8 | 402 | 3.46875 | 3 | [] | no_license |
# How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
# 9183
class Euler29
@min
@a_max
@b_max
def initialize(a=100,b=100,min=2)
@a_max = a
@b_max = b
@min = 2
end
def solve
values = Array.new
2.upto(@a_max) do |a|
2.upto(@b_max) do |b|
values.push(... | true |
33276ae115abd2355e679615dc9237066ee5fbe0 | Ruby | sousk/gaevctl | /gaevctl.rb | UTF-8 | 2,533 | 2.921875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
Usage =<<"__HERE__"
gaevctl helps you to dealing with GAE version management.
It list, delete versions squeezed by time based queries.
Usage:
gaevctl.rb <command> <sort> <num>
List versions:
gaevctl.rb list older 20
gaevctl.rb list newer 20
Delete versions:
gaevctl.rb delete o... | true |
8cabdf3e6c187c82cff7173fedb85fed1662d7ea | Ruby | minams/MediaRanker | /test/models/work_test.rb | UTF-8 | 870 | 2.96875 | 3 | [] | no_license | require "test_helper"
require "pry"
describe Work do
let(:work) { Work.new }
it "must be valid" do
value(work).must_be :valid?
end
describe "top_ten" do
it "must return an array of 10 and be an instance of Work class" do
works = Work.top_ten("album")
expect(works.length).must_equal 10
... | true |
be67bb1f2a2cf1a5fb368173e7573854fd7962b7 | Ruby | zhang4952/sul_pub | /lib/bibtex/bibtex_identifiers.rb | UTF-8 | 2,775 | 2.859375 | 3 | [
"Apache-2.0"
] | permissive | # Note: there is no 'Bibtex' module in sul_pub to avoid any conflicts with other gems
require 'bibtex'
require 'forwardable'
# An immutable Hash of BibTeX identifiers
class BibtexIdentifiers
extend Forwardable
include Enumerable
# Delegate enumerable methods to the Hash.
# This is just a convenience.
delega... | true |
35f3834e00c6bff1dfbe920a473c7ffd1516cf69 | Ruby | mwagner19446/wdi_work | /w03/d03/Jessica/superhero/superhero.rb | UTF-8 | 2,936 | 3.234375 | 3 | [] | no_license | require 'pg'
c = PG.connect(:dbname => "superheros_db")
# f = File.open("superheroes.csv", "a+")
# f.each do |line|
# player = line.split(",")
# name = player[0].gsub("'","")
# alter_ego = player[1]
# cape = player[2]
# power = player[3]
# arch_nemesis = player[4]
# sql = "INSERT... | true |
98d7079625e125ab7eb24eb1b458ac7554d445ce | Ruby | marrsale/utabot | /spec/lib/tracks_collection_spec.rb | UTF-8 | 5,647 | 2.625 | 3 | [] | no_license | require 'spec_helper'
require './lib/tracks_collection'
def soundcloud_response collection, next_href=''
double 'SoundcloudResponse', collection: collection, next_href: next_href
end
RSpec.describe TracksCollection do
let(:soundcloud_client) { double 'SoundcloudClient' }
let(:max_request_size) { described_clas... | true |
21984af7aa1f5e3ee4e458dc8c01b36fc6f79f61 | Ruby | corya0687/countdown-to-midnight-v-000 | /countdown.rb | UTF-8 | 220 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def countdown_with_sleep(wait_time)
sleep(wait_time)
end
def countdown(time_left)
while time_left > 0
puts "#{time_left} SECOND(S)!"
countdown_with_sleep(1)
time_left -= 1
end
"HAPPY NEW YEAR!"
end
| true |
a107c57328870ffa018fdf769a099ac253873fb5 | Ruby | piketa/ruby_excercise | /012.rb | UTF-8 | 365 | 3.234375 | 3 | [] | no_license | members = [
{:name => "鈴木 一郎", :age => 34, :address => "東京都"},
{:name => "山田 花子", :age => 25, :address => "千葉県"},
{:name => "田中 次郎", :age => 19, :address => "埼玉県"}
]
def search(members, key, query)
members.each do |member|
if query =~ member[key]
return member
end
end
end
p search(members, :na... | true |
a77d36fdb79a2665a23c451816235d1829aae66f | Ruby | FujiiMountain/Computer-system-theory-and-implementation | /compiler/jacktokenizer.rb | UTF-8 | 2,961 | 3.4375 | 3 | [] | no_license | class Tokenizer
attr_reader :dataS, :dataA, :counter
#今回は字句解析のため行毎ではなく単語毎にしなくてはならない ⇒ 難しい?
def initialize(name)
@counter = 0
bp = 0
@dataA = []
@data = File.open(name, 'r')
@dataS = @data.read.to_s
#コメントアウトの除去、APIドキュメント用のコメント除去?格納?
i = 0
size = @dataS.length
#puts "dataS #{data... | true |
1900732a5a1575c80903651c106884ff77ed6f4f | Ruby | hikarine3/programming_language_comparison | /examples/file/MkdirChmodRmdir/MkdirChmodRmdir.rb | UTF-8 | 408 | 2.65625 | 3 | [] | no_license | require 'fileutils'
class MkdirChmodRmdir
def initialize(opt = {})
@dir = "ruby_dir"
end
def run
if not Dir.exist?(@dir)
puts("mkdir")
FileUtils.mkdir_p(@dir)
end
if Dir.exist?(@dir)
puts("chmod")
FileUtils.chmod(0o777, @dir)
puts("rmdir")
FileUtils.rmdir(... | true |
7752d5f97674b525afc2dfd1086e505511d7b745 | Ruby | SergioFigueroaG/RubyOnRail-1 | /picis.rb | UTF-8 | 231 | 3.6875 | 4 | [] | no_license | puts "Escriba su dia de nacimiento"
dia = gets.chomp.to_i
puts "Escriba su mes de nacimiento"
mes = gets.chomp.to_i
unless (dia>=19 and mes==2) or (dia<=20 and mes==3)
puts "No es piscis"
else
puts "Si eres piscis"
end | true |
8e1a1df619b1509d9390f6bcda734223e6763f45 | Ruby | MasahiroKawahara/ProjectEuler | /src/003.rb | UTF-8 | 279 | 3.703125 | 4 | [] | no_license | # -*- coding: utf-8 -*-
# 13195 の素因数は 5, 7, 13, 29 である.
# 600851475143 の素因数のうち最大のものを求めよ.
n = 600851475143
div = 3
facts = []
while n > 1
if n%div == 0
n /= div
facts << div
else
div += 2
end
end
puts facts.max
| true |
ac4222da756e36c72d2a5d850cfb49e6c7d07de2 | Ruby | Mendel-Chodaton/shopify-cli | /lib/project_types/theme/messages/messages.rb | UTF-8 | 8,193 | 2.546875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Theme
module Messages
MESSAGES = {
theme: {
help: <<~HELP,
Suite of commands for developing Shopify themes. See {{command:%1$s theme <command> --help}} for usage of each command.
Usage: {{command:%1$s theme [ %2$s ]}}
HELP
i... | true |
0050c4330c5883b8bd81577380711acfce1317b3 | Ruby | trevjnels/WGruby | /chap1and2/c2fin.rb | UTF-8 | 222 | 3.78125 | 4 | [] | no_license | puts "Reading Celsius temperature value from data file..."
num = File.read("temp.dat")
celsius = num.to_i
fahrenheit = (celsius * 9/5) + 32
puts "The input number was #{num}"
puts "The temp in Fahrenheit is #{fahrenheit}"
| true |
e69edd49ff890ec30ed665868af54244530d219d | Ruby | tarvit/incollage | /app/adapters/activerecord/base_repository.rb | UTF-8 | 1,589 | 2.625 | 3 | [] | no_license | class ActiveRecordBaseRepository
def save(entity)
entity.validate!
record = from_entity(entity)
record.save!
entity.id = record.id
entity
rescue ActiveRecord::RecordInvalid => ex
raise Incollage::Validateable::BusinessObjectIsInvalidError.new(ex.message)
end
def delete_all
active_r... | true |
227116022bd4df0f4278ed40009e65d317d24e43 | Ruby | krismacfarlane/godot | /w09/d04/instructor/apis_app/app/models/omdb_api.rb | UTF-8 | 450 | 2.796875 | 3 | [] | no_license | require 'httparty'
module OmdbApi
def self.search(title)
binding.pry
url = "http://www.omdbapi.com/?s=#{title}&r=json"
response = HTTParty.get(url)
JSON.parse(response.body)["Search"]
end
def self.info(imdb_id)
# construct the url
url = "http://www.omdbapi.com/?i=#{imdb_id}&r=json"
#... | true |
2d5b39ab8afd17e8770296753af797cda867bcfd | Ruby | broughten/globalquiver | /app/metal/autocomplete.rb | UTF-8 | 398 | 2.71875 | 3 | [] | no_license | require 'sinatra/base'
class Autocomplete < Sinatra::Application
get '/autocomplete/style/name' do
find_options = {
:conditions => [ "LOWER(name) LIKE ?", '%' + params[:q].downcase + '%' ],
:limit => 10 }
# the .collect(&:name) puts the names of the styles into the @items array
@items = ... | true |
faf82ed782b5bb1fa3c56eea3151e516d969d564 | Ruby | jayvan/advent | /2015/21.rb | UTF-8 | 1,353 | 3.390625 | 3 | [] | no_license | #!/usr/bin/env ruby
def player_wins(boss_hp, boss_dmg, boss_armor, player_dmg, player_armor)
player_turns = (boss_hp.to_f / [player_dmg - boss_armor, 1].max).ceil
boss_turns = (100.0 / [boss_dmg - player_armor, 1].max).ceil
player_turns <= boss_turns
end
boss_hp, boss_dmg, boss_def = ARGF.readlines.map { |line... | true |
53b674031b539f7c5c1716669ca04d9548136a7f | Ruby | Naumych/Part1 | /right_triangle.rb | UTF-8 | 835 | 3.734375 | 4 | [] | no_license | # frozen_string_literal: true
def right_triangle_check
triangle_sides = fetch_triangle_sides
triangle_sides.sort!
triangle_sides = triangle_sides.map { |item| item**2 }
return puts "It's not a triangle" if triangle?(triangle_sides)
puts 'right triangle' if right_triangle?(triangle_sides)
puts 'isosceles ... | true |
0f008934ae1e7fe874fb7af095cfc47494abdc99 | Ruby | joshmun/javascript-racer-game | /app/controllers/games_controller.rb | UTF-8 | 741 | 2.5625 | 3 | [] | no_license | get '/games/new' do
erb :'games/new'
end
get '/games/:id' do
@game = Game.find(params[:id])
if @game.done == false
erb :'games/show/play'
else
erb :'games/show/done'
end
end
post '/games' do
@player1 = Player.find_or_create_by(name: params[:player1])
@player2 = Player.find_or_create_by(name: par... | true |
045c2281cb3217b11f965b74033ab0ff4c24bb65 | Ruby | BostonREB/exercises | /rb_rps2.rb | UTF-8 | 1,823 | 3.484375 | 3 | [] | no_license | game_play = {rock: {scissors: "crushes", lizard: "crushes"}, paper: {spock: "disproves", rock: "covers"}, scissors: {paper: "cuts", lizard: "decapitates"}, lizard: {paper: "eats", spock: "poisons"}, spock: {scissors: "smashes", rock: "vaporizes"}}
human_wins = 0
computer_wins = 0
ties = 0
game_count = 0
while true
p... | true |
6457c592ee1e1f15b8f95e30c70cb9bba7094128 | Ruby | Hackinfinity/intrigue-core | /lib/tasks/helpers/socket.rb | UTF-8 | 1,739 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | module Intrigue
module Task
module Socket
## Source: Metasploit
##
## Changes bit ordering of the provided value, using the provided size
##
## @param addr [String] Value to be changed
## @param sizer [Numeric] the number of bits to adjust at a given time
def change_endianness(value, size = 4)
con... | true |
08a5c82407225b34f382a4ba98b4469c118c82a8 | Ruby | fosterv2/programming-univbasics-4-array-concept-review-lab-seattle-web-030920 | /lib/array_methods.rb | UTF-8 | 574 | 3.703125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def find_element_index(array, value_to_find)
# Add your solution here
index_to_find = nil
array.length.times do |index|
if array[index] == value_to_find
index_to_find = index
end
end
index_to_find
end
def find_max_value(array)
# Add your solution here
max = 0
array.length.times do |index|... | true |
6cd62513e1fa1bf046cae6cef1d6a97539c8e7a0 | Ruby | yan0va/boris_bikes | /spec/garage_spec.rb | UTF-8 | 413 | 2.703125 | 3 | [] | no_license | require "garage"
describe Garage do
let(:bike) {Bike.new}
let(:broken_bike) do
bike = Bike.new
bike.break
bike
end
let(:garage) { Garage.new(:capacity => 123) }
it "should allow setting default capacity on initialising" do
expect(garage.capacity).to eq(123)
end
it "fixes the bike on... | true |
dae82e174e7d85301773b90753d45e9c3d289eaf | Ruby | MastersAcademy/ruby-course-2018 | /db_dsl_active_record/vlad.vovk/run.rb | UTF-8 | 1,139 | 2.625 | 3 | [] | no_license | require './config/initializers/database'
require 'pry'
Profession.create(doctor: true)
Profession.create(dishwasher: true)
Profession.create(lawyer: true)
Nationality.create(russian: true)
Nationality.create(ukrainian: true)
Nationality.create(american: true)
User.create(first_name: 'Vlad', last_... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.