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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b781e6ada01dddf2d8caaf18d027dc69eddf868f | Ruby | enowmbi/algorithms | /byte_by_byte/median_of_two_sorted_arrays.rb | UTF-8 | 927 | 4.28125 | 4 | [] | no_license | #Question 1 -- find the median of two sorted arrays arr1 = [1,3,5] and arr2 = [2,4,6] median = 3.5
# merge the two arrays, take the middle numbers and divide by 2 if resulting array is even else get the middle element if not even
def median(arr1,arr2)
result = []
return result if arr1 == nil && arr2 == nil
poi... | true |
0462cb770182e0be749f54626fb191cc738492df | Ruby | baweaver/advent_of_code_2020 | /05_binary_boarding.rb | UTF-8 | 904 | 3.890625 | 4 | [] | no_license | # I like naming things to make them clearer
FRONT = 'F'.freeze
BACK = 'B'.freeze
LEFT = 'L'.freeze
RIGHT = 'R'.freeze
# This is a fun little trick. The problem spec hinted at it pretty hard
# with "binary boarding", meaning each character is a bit switch. First half
# for off, last half for on, convert and `to_i(2)`... | true |
02d99630cc338f7874db92ea40fc97668f771c8f | Ruby | smthom05/enigma | /lib/offset.rb | UTF-8 | 469 | 3.140625 | 3 | [] | no_license | require 'date'
class Offset
attr_reader :offset_hash
def initialize
@offset_hash = {}
end
def generate_offset
offset = Date.today.strftime("%d%m%y")
end
def generate_offset_hash(date = generate_offset)
date_squared = date.to_i ** 2
offset_values = date_squared.to_s[-4,4]
@offset_has... | true |
a28b567c69154d42cfae7822a432aa456f0c404f | Ruby | cloudfoundry-attic/git_pipeline | /app/models/git_commit_collection_lazy.rb | UTF-8 | 651 | 2.890625 | 3 | [] | no_license | class GitCommitCollectionLazy
class NotAvailableError < StandardError; end
include Enumerable
# wtf enumerable?
alias_method :size, :count
def initialize(git_commit_fetcher)
@git_commit_fetcher = git_commit_fetcher
@commits = nil
@available = false
end
def available?
fetch_commits
... | true |
5a688e913aa7a51120d7154416f3530dfe783211 | Ruby | WhatOSS/Twiki | /couch_db.rb | UTF-8 | 4,319 | 2.53125 | 3 | [] | no_license | require 'v8'
require 'json'
require 'securerandom'
class Couch
def self.load_config
configs = YAML.load(File.read("#{Rails.root}/config/database.yml"))
config = configs[Rails.env]
@@host = config['host']
@@port = config['port'] || '5984'
@@username = config['username']
@@password = config['p... | true |
ced6b0175bda6192d8850c015715133d939deb61 | Ruby | benfloydsmith/basic_repo | /coding_dojo/Ruby/Rails/NinjaGoldGame/app/controllers/rpgs_controller.rb | UTF-8 | 1,091 | 2.546875 | 3 | [] | no_license | class RpgsController < ApplicationController
def index
if !session[:gold] then
session[:gold] = 0
end
if !session[:activity] then
session[:activity] = []
end
end
def farm
farm = rand(10..20)
session[:gold] += farm
session[:activity] << "Earned #{farm} gold from the farm! " + Time.now.strftime("%... | true |
416b1c1dbf2de8a6dd98a64232980ebff553c5d4 | Ruby | andrebnf/kmeans-slink-rb | /slink_v1.rb | UTF-8 | 1,601 | 2.84375 | 3 | [] | no_license | require_relative 'lib/point'
require_relative 'lib/file_reader'
require_relative 'lib/plotter'
require_relative 'slink_cluster_v1'
def insert_sorted arr, new_i
for i in 0..arr.size-1
if new_i < arr[i]
arr.insert(i, new_i)
return false
end
end
arr.push new_i
return false
end
if ARGV.size < ... | true |
debbe3795b83386f8baef9a1d1dfb679c236169e | Ruby | briankung/understanding-computation | /test/support/node_exec.rb | UTF-8 | 474 | 2.734375 | 3 | [] | no_license | require 'json'
require 'open3'
class NodeError < StandardError
def initialize(msg="Invalid JavaScript generated!")
super
end
end
def node_exec code, env={}
result, error = nil, nil
input = "console.log((#{code}).call(null, #{env.to_json}))"
Open3.popen3('node') do |stdin, stdout, stderr, thread|
st... | true |
adf5a4609ed077f5f0cf9eab67ad9e9282627e7b | Ruby | rutgerjmckenna/sql-crowdfunding-lab-nyc-web-080519 | /lib/sql_queries.rb | UTF-8 | 1,965 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your sql queries in this file in the appropriate method like the example below:
#
# def select_category_from_projects
# "SELECT category FROM projects;"
# end
# Make sure each ruby method returns a string containing a valid SQL statement.
def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabe... | true |
ce0c5b78ca5c2b4e6a731d4f6121a40e4028749a | Ruby | hlbtyne/badges-and-schedules-london-web-career-040119 | /conference_badges.rb | UTF-8 | 678 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
"Hello, my name is #{name}."
end
def batch_badge_creator(attendees)
badges = []
attendees.each do |name|
badges.push(badge_maker(name))
end
return badges
end
def assign_rooms(attendees)
room_assignments = []
room_number = 1
attendees.each do |attendee|
room_assignments.pu... | true |
514d9b8f9ff89b4f2de32b02971da3496dc0b0ff | Ruby | Liboul/martyr | /lib/martyr/runtime/query/metric_dependency_resolver.rb | UTF-8 | 5,960 | 2.5625 | 3 | [
"MIT"
] | permissive | module Martyr
module Runtime
class MetricDependencyResolver
attr_reader :cube
# @param cube [BaseCube] either virtual or regular cube
def initialize(cube)
@cube = cube
@metrics_by_cube = {}
@inferred_fact_grain_by_cube = {}
end
def to_hash
Hash[@metr... | true |
0847dfe1137401e7c47c7d8bb5b280b464126b26 | Ruby | jamiepaterson6715/HW-music_collection | /db/console.rb | UTF-8 | 344 | 2.671875 | 3 | [] | no_license | require("pry")
require_relative("../models/artists")
require_relative("../models/albums")
# Albums.delete_all
# Artists.delete_all()
artist1 = Artist.new({"name" => "AC/DC"})
artist1.save()
album1 = Albums.new({
"name" => "Who Made Who",
"genre" => "Hard Rock",
"artist_id" => artist1.id
})
album1.s... | true |
5cefd998e67923852f96a527196d558164fff143 | Ruby | stevecass/simple-ruby-crud | /app.rb | UTF-8 | 3,595 | 3.71875 | 4 | [] | no_license | require_relative 'parser'
require_relative 'person'
require 'colorize'
class App
def initialize
@people = {}
PeoplePersister.load_people.each { |person| @people[person.id] = person }
puts "Loaded #{@people.length} people"
until @quit_requested do
main_loop
end
end
def save_people
... | true |
49505e5b1629cddb98fa2dd2e6cdcc63633f838d | Ruby | deCadeh/wallarm-source-leak | /pkgs/wallarm_logger/wallarm_logger/logger_hub.rb | UTF-8 | 1,933 | 3 | 3 | [] | no_license | require_relative './json_logger'
require_relative './local_logger'
require_relative './standart_logger'
# Singletone container of all LoggerHub instances
# Use it to reopen all logs by signal
class ActiveLoggerHubs
@@hubs = []
class << self
def hubs
@@hubs
end
def clear
@@hubs = []
en... | true |
24cb3377cb4768f017f9ba45ebd120cc001e59e1 | Ruby | omitter/mobility | /lib/mobility/plugins/cache/translation_cacher.rb | UTF-8 | 1,181 | 2.65625 | 3 | [
"MIT"
] | permissive | module Mobility
module Plugins
module Cache
=begin
Creates a module to cache a given translation fetch method. The cacher defines
private methods +cache+ and +clear_cache+ to access and clear, respectively, a
translations hash.
This cacher is used to cache translation values in {Mobility::Plugins::Cache},
and a... | true |
dbded6bb696a091c7fe0c3f776d30e75641d0f56 | Ruby | kromoser/oxford-comma-v-000 | /lib/oxford_comma.rb | UTF-8 | 177 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def oxford_comma(array)
x = array.count
if x <= 2
array.join(" and ")
else
new_string = array[0..x-2].join(", ")
new_string << ", and #{array[x-1]}"
end
end | true |
04e3a3d812a92ba0ca4c9ee393a343b02918723f | Ruby | kamui/kanpachi | /examples/twitter.rb | UTF-8 | 5,030 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'roar/representer/json'
require 'roar/representer/feature/hypermedia'
module UserRepresenter
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia
property :first_name, type: String, required: true, doc: "it's the first name"
property :last_name, type: String, required: true, d... | true |
f8068d3aec2278d70093816f541b13cd79928d55 | Ruby | Samellenrider/learn-to-program | /chapter08/esmethodvar.rb | UTF-8 | 126 | 2.734375 | 3 | [] | no_license | def excitedsurfer excitementlevel
puts 'Hey mate, let\'s go surf !!!!! ' * excitementlevel
end
puts excitedsurfer 100
| true |
5d5b15ae22d49a17bf32ee1aa8e92a528cc52706 | Ruby | krivospitsky/SimpleShop | /app/models/delivery_method.rb | UTF-8 | 398 | 2.53125 | 3 | [] | no_license | class DeliveryMethod < ActiveRecord::Base
default_scope -> {order(sort_order: :asc)}
scope :enabled, -> { where(enabled: 't') }
has_and_belongs_to_many :payment_methods
def text
if price && price > 0
"#{name} (+#{price} руб.)"
else
name
end
end
def applicable?(price)
(min_price.to_i==... | true |
e5a47db9b49c8c3ad5c34dfd2c2c63dde3471b76 | Ruby | cdemyanovich/demyano_bst | /lib/demyano_bst/node.rb | UTF-8 | 1,630 | 3.28125 | 3 | [] | no_license | module DemyanoBst
class Node
attr_accessor :value, :parent, :left_child, :right_child
def initialize(value, parent = nil)
@value = value
@parent = parent
end
def disown(child)
self.left_child = nil if self.left_child && self.left_child.value == child.value
self.rig... | true |
49988e5980dacea6cff1bae82341341553f1e6d9 | Ruby | yuihyama/mre | /module/module_prepend.rb | UTF-8 | 291 | 3.15625 | 3 | [] | no_license | #!/usr/bin/env ruby
module MyModule
def hello_world
'hello, world'
end
end
class MyClass1
prepend MyModule
end
obj1 = MyClass1.new
p obj1.hello_world
puts obj1.hello_world
puts
class MyClass2
prepend MyModule
end
obj2 = MyClass2.new
p obj2.hello_world
puts obj2.hello_world
| true |
99a9f0d2321f632fbb08411343eb1154329ce365 | Ruby | lesniakania/twitter_analyser | /lib/sequences/prefix_span.rb | UTF-8 | 2,972 | 2.96875 | 3 | [] | no_license | require 'lib/models/sequence_part'
require 'lib/models/sequence_freq'
require 'lib/models/user'
require 'lib/models/twitt'
MinSequenceFreq = 10
class PrefixSpan
def initialize(twitts)
# 'log'
puts "Init started..."
SequencePart.delete
SequenceFreq.delete
vector_number = 0
twitts.each do |t... | true |
76ab244963a283fb78295cc21ae2d99bcbcea84f | Ruby | Middlebrooks314/sinatra-dynamic-routes-lab-chicago-web-062419 | /app.rb | UTF-8 | 230 | 2.578125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative 'config/environment'
class App < Sinatra::Base
# Write your code here!
get '/reversename/:name'
params[:name].reverse
end
get '/square/:number'
num = params[:number]
num.to_i **2
end
end | true |
3bd574c74fd58cc066715af97529138c3abbecdc | Ruby | rubythings/rubyd3 | /node.rb | UTF-8 | 1,093 | 3 | 3 | [] | no_license | class Node
attr_accessor :force_coulomb
attr_accessor :force_harmonic
attr_accessor :velocity
attr_accessor :id
attr_accessor :cc_number, :coordinate_x, :coordinate_y, :neighbour_ids, :movable, :name, :transition
def initialize(node_id, name, transition)
@name = name
@transition = transition
@id = node_... | true |
a9402cb1eb61e6c6eebdd8f207d9e414de8e9397 | Ruby | mikeyduece/vend | /spec/features/user_see_snack_info_spec.rb | UTF-8 | 1,708 | 2.765625 | 3 | [] | no_license | require 'rails_helper'
# When I visit a specific snack page
# I see the name of that snack
# I see the price for that snack
# I see a list of locations with vending machines that carry that snack
# I see the average price for snacks in those vending machines
# And I see a count of the different kinds of items in that v... | true |
c28b0e57983bd3f5d5207dd492f1513c5428fc11 | Ruby | gglin/project-euler | /ruby_all/124.rb | UTF-8 | 753 | 3.78125 | 4 | [] | no_license | # Problem 124: Ordered radicals
# http://projecteuler.net/problem=124
#
# The radical of n, rad(n), is the product of distinct prime factors of n. For example, 504 = 2^3× 3^2× 7, so rad(504) = 2 × 3 × 7 = 42.
# If we calculate rad(n) for 1 ≤n ≤ 10, then sort them on rad(n), and sorting on n if the radical values are ... | true |
0ed94579eba47c230604b6a34b9cd256e1cf39cb | Ruby | Baconthorpe/looping-loop-000 | /looping.rb | UTF-8 | 93 | 2.890625 | 3 | [] | no_license | def looping
#your code here
while (1 == 1)
end
end
#call your method here
looping() | true |
fc973bf6961a83b99b403a6cbff00aa6652fa96b | Ruby | mnutt/intranet | /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | UTF-8 | 2,226 | 2.734375 | 3 | [
"MIT"
] | permissive | module ActiveRecord
module ConnectionAdapters # :nodoc:
module Quoting
# Quotes the column value to help prevent
# {SQL injection attacks}[http://en.wikipedia.org/wiki/SQL_injection].
def quote(value, column = nil)
# records are quoted as their primary key
return value.quoted_id ... | true |
e4292a780a1ff03f57409d982b543f270c0365fa | Ruby | badr96/git-thp | /Vendredi/exo_13.rb | UTF-8 | 173 | 3.5 | 4 | [] | no_license | puts"hello buddy what was ur birt year: "
birth_year = gets.to_i
puts"\nyear that past: "
while birth_year != 2018+1
puts"#{birth_year}"
birth_year = birth_year + 1
end
| true |
85d664c036404212d718655f4e77ab8fba81548d | Ruby | mv/ynab-csv-scripts | /bin/sofisa-pdf.rb | UTF-8 | 2,245 | 2.84375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pp'
###
### file name
###
def usage()
puts <<-"USAGE"
Usage: #{$0} path-to-sofisa-pdf
USAGE
exit 1
end
usage if ARGV.empty?
pdf_name = ARGV[0]
file_name = pdf_name
base_name = File.basename(pdf_name, '.*')
dir_name = File.dirname( File.absolute_path( pdf_name ) )
csv_name =... | true |
b3a2fbef2ac913f6fe59b0fb1ae2befedac4e977 | Ruby | rahul26goyal/eventmachine-ruby | /1. sample.rb | UTF-8 | 846 | 2.921875 | 3 | [
"MIT"
] | permissive | $eventmachine_library = :pure_ruby
require 'eventmachine'
def register()
puts "register...."
i = 0
while i < 2
puts "i: #{i}"
i = i + 1
#sleep 1
end
end
def register2()
puts "register2...."
i = 0
while i < 2
puts "i: #{i}"
i = i + 1
sleep 1
end
end
def start()
#Process.daem... | true |
cdde7e8634d303cc4630c637119fe94063ac073f | Ruby | plasticine/simulacrum | /lib/simulacrum/cli/parser.rb | UTF-8 | 2,421 | 2.734375 | 3 | [] | no_license | # encoding: UTF-8
require 'optparse'
require 'ostruct'
require 'simulacrum'
module Simulacrum
module CLI
# Option parser for handling options passed into the Simulacrum CLI
#
# This class is mostly borrowed from Cane's Parser class. Thanks Xav! <3
class Parser
attr_reader :stdout
# Excep... | true |
c5da4db32cf57b0213172c612f6a0e6180c3e233 | Ruby | varyform/wufoo | /lib/wufoo/query.rb | UTF-8 | 1,097 | 2.515625 | 3 | [
"MIT"
] | permissive | module Wufoo
class Query
attr_accessor :client, :form, :params
def initialize(client, form, params={})
@client = client
@form = form
@params = {}.merge(params || {})
end
def add_params(new_params)
@params.merge!(new_params)
self
end
def process
Response.n... | true |
1d1575c83b7c31a91d874f9bbc90b37ff69b9a64 | Ruby | Clinton-dev/substrings | /.github/workflows/sub.rb | UTF-8 | 520 | 3.046875 | 3 | [] | no_license | dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]
puts "enter word(s)"
words = gets.chomp
def subString(word,arrOfSubs)
wordsArr = word.downcase.split(' ')
subStringFreq = Hash.new(0)
wordsArr.select do |word|
arrOfSubs.each do |char|
... | true |
4ef13655152825fa45062cc80a7cab1c18238648 | Ruby | NareshPS/ludak.me | /fbclient/Album.rb | UTF-8 | 315 | 3 | 3 | [] | no_license |
class Album < Array
attr_reader :id, :name, :description
def initialize(id, name, description)
@id = id
@name = name
@description = description
super()
end
def photos()
Array.new(self)
end
def to_s()
return "|Id: #{@id} Name: #{@name} Description: #{@description}"
end
end
| true |
1d16920a280ab62eac969f66c78a84c34fbbfd01 | Ruby | rdsoze/ignitte | /app/models/tweet.rb | UTF-8 | 780 | 2.671875 | 3 | [] | no_license | class Tweet < ActiveRecord::Base
belongs_to :user
attr_accessible :id, :tweet_date, :html
class << self
def check_for_new
@tweets = Tweet.get_tweets 10
@tweets.each do |tweet|
break unless Tweet.where(id:tweet.attrs['id']).empty?
user = User.get_user tweet
Tweet.add_tw... | true |
ff7c4c8186b1c360208c6aaf55577818c1f94972 | Ruby | gitKrystan/ruby-dealership | /spec/vehicle_spec.rb | UTF-8 | 1,737 | 3.203125 | 3 | [
"MIT"
] | permissive | require('rspec')
require('vehicle')
describe(Vehicle) do
before() do
Vehicle.clear()
end
describe('#make') do
it('returns the make of the vehicle') do
expect(toyota_prius_2000().make()).to(eq("Toyota"))
end
end
describe('#model') do
it('returns the model of the vehicle') do
expe... | true |
5589a33d005c14935691e7bbc0af7e814cfcc482 | Ruby | auslaendernola/tts-ruby | /activity_today.rb | UTF-8 | 1,037 | 3.984375 | 4 | [] | no_license | #decide an appropriate activity
def choose_activity
#Get temperature
puts "What is today's temperature in F"
temp = gets.chomp.to_i
if temp > 110 || temp < 20
puts "#{temp} isn't even a real temperature for N.O., that's just silly."
choose_activity
elsif temp >= 80
puts "It's #{temp}F degrees is p... | true |
f5183e0b98b32b77c31055d7e9885a80659b3898 | Ruby | ngoctoandhv/Ruby_Basic | /16. Ruby - Metaprogramming/02.Metaprogramming basic .rb | UTF-8 | 1,834 | 3.8125 | 4 | [] | no_license | #Metaprogramming basic
#“Metaprogramming is a programming technique in which computer programs have the ability to treat programs as their data” https://en.wikipedia.org/wiki/Metaprogramming
# Example code without metaprogramming
#send( ) is an instance method of the Object class
class Rubyist
def welcome(*a... | true |
171cfcc391f81c63c1e5e539efb35a6a952a8f2b | Ruby | lynneq/bootcamp | /shapes/cube.rb | UTF-8 | 171 | 2.765625 | 3 | [] | no_license | $LOAD_PATH << File.dirname(__FILE__)
require 'square'
class Cube
def initialize(square)
@square = square
end
def area
6 * @square.area
end
end | true |
97bfcfa3fb9f47e8ef90eb559599b8423554568a | Ruby | hoangdzung/OOP | /app/views/api/v1/customers/schedules/index.json.jbuilder | UTF-8 | 273 | 2.546875 | 3 | [] | no_license | json.code 1
json.message "Thành công"
json.data @schedules.each do |schedule|
json.merge! schedule.attributes
json.time_begin schedule.time_begin.strftime("%d/%m/%Y %H:%M") rescue nil
json.time_end schedule.time_end.strftime("%d/%m/%Y %H:%M") rescue nil
end
| true |
dcb33355ec9c79c9c872a8850001fceab03e4ff7 | Ruby | r7kamura/qchan-worker | /lib/qchan_worker/builder/executor.rb | UTF-8 | 1,446 | 2.625 | 3 | [] | no_license | require "mem"
require "open3"
require "qchan_worker/builder/publisher"
require "tempfile"
module QchanWorker
class Builder
class Executor
include Mem
def self.execute(*args)
new(*args).execute
end
def initialize(command)
@command = command
end
def execute
... | true |
0011ffee82d02bdc1ab40667ebd3c0df0c7871ab | Ruby | Gamua/Flox-Ruby | /test/test_flox.rb | UTF-8 | 4,884 | 2.8125 | 3 | [
"BSD-2-Clause",
"BSD-2-Clause-Views"
] | permissive | ## Author: Daniel Sperl
## Copyright: Copyright 2014 Gamua
## License: Simplified BSD
require 'flox'
require 'test/unit'
require 'mocha/setup'
class FloxTest < Test::Unit::TestCase
GAME_ID = "game_id"
GAME_KEY = "game_key"
BASE_URL = "http://url.com"
attr_reader :flox
def setup
@flox = Flox.new... | true |
c2c85cf31c0910a011a801065da8c0864f92c94f | Ruby | developwithpassion/fakes | /spec/specs/class_swaps_spec.rb | UTF-8 | 3,301 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
module SomeModule
module NestedModule
class AClassInANestedModule
end
end
class ClassInAModule
end
end
module Fakes
class SomeClass
def self.calculate
42
end
end
describe ClassSwaps do
class MySwap
attr_accessor :inititated, :was_reset
def init... | true |
e5765c6624780a4bf24b5be03c5e0d1fbfe25606 | Ruby | RavenB/playfulbent | /test/unit/gender_test.rb | UTF-8 | 1,781 | 2.734375 | 3 | [] | no_license | # == Schema Information
#
# Table name: genders
#
# id :integer(4) not null, primary key
# name :string(255)
#
require File.dirname(__FILE__) + '/../unit_test_helper'
class UserTest < Test::Unit::TestCase
def test_is_male
@gender = Gender.new
assert_equal false, @gender.is_male?
@gender.name =... | true |
cbab5e81c4c2f155b59784981d13946df6cb7c22 | Ruby | MRSTkz/greping | /lib/str.rb | UTF-8 | 211 | 3.5625 | 4 | [] | no_license | class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def green
colorize(32)
end
def yellow
colorize(33)
end
def blue
colorize(36)
end
end
| true |
021870729c394cbbb06209b362f580c87324c66e | Ruby | time4kids/time4kids-api | /spec/support/url_matcher.rb | UTF-8 | 416 | 2.703125 | 3 | [] | no_license | # Passes if result is a valid url, returns error "expected result to be url" if not.
# Matcher to see if a string is a URL or not.
# RSpec::Matchers.define :be_url do |expected|
# # The match method, returns true if valie, false if not.
# match do |actual|
# # Use the URI library to parse the string, returning... | true |
2079c4e710a3bc44d2e08a3431b871f22e9cd857 | Ruby | Rasit1/Exercices-Ruby | /exo_14.rb | UTF-8 | 119 | 3.3125 | 3 | [] | no_license | puts "Entrez un nombre"
print "-->"
nombre = gets.chomp
i=0
while i <= nombre.to_i do
puts nombre.to_i-i
i +=1
end
| true |
6186a1c13be31c197b37757c0804a2ac1e3eefc9 | Ruby | to93m/a_filter | /convo.rb | UTF-8 | 2,061 | 2.875 | 3 | [] | no_license | #ruby convo.rb input_file_name 畳み込むもの
#ruby convo.rb SpeechData.raw 16 impulse_response_file.raw mode output_file_name
require './plot'
base_wave ||= []
impulse_response ||= []
x_axis ||= []
def read_wave(file_name, mode)
wave ||= []
File.open("./data/"+ file_name) {|file|
if mode == "s"
binary = file.r... | true |
2db16f4b1f83541d362e8a6d432aa58a22c61f66 | Ruby | nerab/pwl | /lib/pwl/commands/base.rb | UTF-8 | 4,052 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Pwl
module Commands
EXIT_CODES = {
:success => Message.new('Success.'),
:aborted => Message.new('Aborted by user.', 1),
:passwords_dont_match => ErrorMessage.new('Passwords do not match.', 2),
:no_value_found => Message.new('No value found for <%=... | true |
24580598436a15faeb1467f86b7aae28b11920d3 | Ruby | TravisExline/collections_practice-online-web-ft-051319 | /collections_practice.rb | UTF-8 | 845 | 3.90625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(integer_array)
integer_array.sort do |a, b|
if a == b
0
elsif a < b
-1
elsif a > b
1
end
end
end
def sort_array_desc(array)
array.sort do |a, b|
if a == b
0
elsif a < b
1
elsif a > b
-1
end
end
end
def sort_array_char_count... | true |
529b4abac35cf286aa6959355df55bfef00a3021 | Ruby | pyrmont/taipo | /lib/taipo/type_element/constraints.rb | UTF-8 | 843 | 2.71875 | 3 | [
"Unlicense",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | module Taipo
class TypeElement
# A set of {Taipo::TypeElement::Constraint} objects
#
# @since 1.4.0
# @api private
class Constraints < Array
# Initialize a new set of {Taipo::TypeElement::Constraint}
#
# @param constraints [Array<Taipo::TypeElement::Constraint>] the
# c... | true |
b1747d0e755285b37806e75574e62f6630c39114 | Ruby | calo81/ruby-recommender | /spec/recommendations/similarity/neighborhood/nearest_n_user_neighborhood_spec.rb | UTF-8 | 1,020 | 2.65625 | 3 | [] | no_license | require_relative '../../../../spec/spec_helper'
require_relative '../../../../lib/recommendations'
describe Recommendations::Similarity::Neighborhood::NearestNUserNeighborhood do
it "should return the top N users similar to passed user" do
data_model = mock(:data_model)
similarity = mock(:similar... | true |
29256f6d8a1f38fa1b91d2e6cee30a5ad6049aaf | Ruby | GBSEcom/Ruby | /lib/openapi_client/models/additional_response_data.rb | UTF-8 | 12,956 | 2.609375 | 3 | [] | no_license | =begin
#Payment Gateway API Specification.
#The documentation here is designed to provide all of the technical guidance required to consume and integrate with our APIs for payment processing. To learn more about our APIs please visit https://docs.firstdata.com/org/gateway.
The version of the OpenAPI document: 21.5.0.... | true |
1d6d4c1e7a91bb5b60fffefb6b97036a4c2f3915 | Ruby | eudai/copycat | /copycat.rb | UTF-8 | 4,668 | 3.546875 | 4 | [] | no_license | require 'rumouse'
class CopyCat
def initialize
puts 'welcome to copycat.'
puts 'copycat will record your mouse locations, and play them back.'
help
terminal
puts 'goodbye.'
end
def record
events = []
input "press 'enter' to begin."
loop do... | true |
987a87cca7bf15b32beb9268a221d4152670aafc | Ruby | edem228/backend | /backend/octoly_email_finder.rb | UTF-8 | 1,148 | 3.046875 | 3 | [] | no_license | require "json"
class Octoly_email_finder
def initialize(file)
@file = file
@number_for_email = number_for_email
end
def read_file
File.read(@file)
end
def parsed_file
JSON.parse(read_file)
end
def counts_videos_by_id
most_viewed_topics = []
parsed_file.each do |video|
vid... | true |
791ad4ab9d6e196c321197d6ab27127f95797559 | Ruby | ksummerill/ttt-game-status-online-web-sp-000 | /lib/game_status.rb | UTF-8 | 1,427 | 4.09375 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require "pry"
# Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]
def won?(board)
winner = []
empty_board = board.... | true |
1976032ad459c5640c6cb645db3082d3b5de5cce | Ruby | zkbell91/zbell-linkedlist1 | /linked_list_1.rb | UTF-8 | 1,256 | 4 | 4 | [] | no_license | class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
class Stack
attr_reader :data
def initialize
@data = nil
end
def push(value)
@data = LinkedListNode.new(value, @data)
end
def pop
if @data... | true |
4490e31fce45ae7ac84c36f0dacd6676e29e03e8 | Ruby | pmatsinopoulos/hackerrank | /spec/find_median_spec.rb | UTF-8 | 392 | 2.84375 | 3 | [] | no_license | require 'spec_helper'
require_relative '../lib/find_median'
describe 'Find Median' do
[
[[0, 1, 2, 4, 6, 5, 3], 3],
[[], nil],
[[1], 1],
[[1, 2], 1],
[[1, 5, 8], 5],
[[8, 5, 1], 5],
[[1, 1, 1], 1]
].each do |input, expected|
it "finds the median for array #{input} to be #{expected}... | true |
cec071af4ed2fab70155e78f4ac08be760fee8e9 | Ruby | jtlai0921/PG20249_example | /PG20249_sample/Ruby268-SampleProgram-UTF8/Ch2/sample033-03.rb | UTF-8 | 116 | 2.859375 | 3 | [] | no_license | str = "3.14159265357919"
char_stat(str).each{|char, count|
puts "#{char.inspect}: #{count * 100 / str.length}%"
}
| true |
83f21a5f367822857f66267338e80c7715dc7451 | Ruby | kazuhirodk/mutation-test-introduction | /lib/tax_calculator.rb | UTF-8 | 130 | 2.84375 | 3 | [
"MIT"
] | permissive | class TaxCalculator
def calculate(product)
if product.price > 500
return product.price * 0.1
end
0
end
end
| true |
7711162b704d0371cbb6090f8244c0fbc2ff7cd5 | Ruby | Ortuna/bana_new | /lib/bana/builder.rb | UTF-8 | 828 | 2.53125 | 3 | [] | no_license | module Bana
class Builder
attr_reader :path, :manifest_file
def initialize(options = {})
configure_builder default_options.merge(options)
load_manifest
end
def create_pdf(output_path)
Bana::Converters::Md.new(manifest_files, output_path)
end
private
def load_manifest
... | true |
8e9069e3771ac2e3582a717c2f9dbfb445cabba7 | Ruby | RJ-Ponder/RB101 | /exercises/easy_5/05clean.rb | UTF-8 | 1,590 | 4.46875 | 4 | [] | no_license | # Problem
# Given a string that consists of some words (all lowercased) and an
# assortment of non-alphabetic characters, write a method that returns that
# string with all of the non-alphabetic characters replaced by spaces. If one or
# more non-alphabetic characters occur in a row, you should only have one ... | true |
ac57e2e60c2ac573e2adeb213769bac621ed9420 | Ruby | MAshrafM/The_Odin_Project | /08_Serialization/Hangman/example/example_game.rb | UTF-8 | 148 | 2.9375 | 3 | [
"MIT"
] | permissive | require_relative '../lib/Hangman.rb'
puts "Your name: "
name = gets.chomp
player = Hangman::Player.new({name: name})
Hangman::Game.new(player).play | true |
6a839127e3f4852feab621d75941e3ac0b5a547f | Ruby | Ootm/FIT4AF | /Ruby/Code/Block.rb | UTF-8 | 254 | 3.4375 | 3 | [] | no_license | # Block
3.times do |number|
puts number.to_s
end
3.times { |n| puts n.to_s }
numbers = (1..10).to_a
var = numbers.select do |n|
n.even?
end
evens, odds = numbers.partition do |n|
n.even?
end
puts evens
puts "------------------------"
puts odds | true |
afe2a8a98ee40e0ca4f442fff5f0ecda5a61f3c2 | Ruby | wasamasa/aoc | /2015/18.rb | UTF-8 | 5,432 | 3.90625 | 4 | [
"Unlicense"
] | permissive | require_relative 'util'
# --- Day 18: Like a GIF For Your Yard ---
# After the million lights incident, the fire code has gotten
# stricter: now, at most ten thousand lights are allowed. You arrange
# them in a 100x100 grid.
# Never one to let you down, Santa again mails you instructions on the
# ideal lighting conf... | true |
e218825de919f0acf6ed158026f98c9c89959168 | Ruby | hoshito/AtCoder | /M-SOLUTIONS プロコンオープン/main_c.rb | UTF-8 | 202 | 2.953125 | 3 | [] | no_license | q=gets.chomp.to_i
arr = []
q.times do |i|
arr << gets.chomp.split(" ").map(&:to_i)
end
arr.each do |(x, d, n)|
a = 1
n.times do |i|
a *= (x + i * d) % 1000003
end
puts a % 1000003
end
| true |
37a6296eb50dfa8889a6b23cb8abb3a95e97f19f | Ruby | jonatanklosko/wca_statistics | /core/statistic.rb | UTF-8 | 952 | 2.78125 | 3 | [
"MIT"
] | permissive | require "time"
require_relative "database"
class Statistic
attr_reader :title
def query
raise "Must implement #query"
end
def query_results
Database.client.query(query)
end
def transform(query_results)
query_results.each(as: :array)
end
def data
@data ||= transform(query_results)
... | true |
a57d74347eb08f85902e350a93b8c92f308d348d | Ruby | andycamp/orasaurus | /lib/orasaurus/cli.rb | UTF-8 | 2,783 | 2.78125 | 3 | [] | no_license | require 'highline'
require 'thor'
require 'orasaurus/version'
require 'orasaurus/application'
module Orasaurus
class CLI < Thor
include Thor::Actions
map "-v" => :version
map "-h" => :help
map "-g" => :generate
desc "generate [SCRIPT_TYPE]", "Generate scripts. SCRIPT_T... | true |
0cfadabb38597fefb2fbee9201339e5cb9ef2122 | Ruby | fishforward/read | /app/models/site.rb | UTF-8 | 2,647 | 2.75 | 3 | [] | no_license | # encoding: utf-8
require 'rss/2.0'
require 'nokogiri'
require 'open-uri'
class Site < ActiveRecord::Base
attr_accessible :auto_read, :content_tag, :name, :name_tag, :read_type, :status, :url, :read_url, :last_pub_date, :author
def self.read_site
sites = Site.find_all_by_auto_read("Y")
sites.each do |si... | true |
2e48026347d2c775e293d2ae86801334e4205be6 | Ruby | joshvarney/tic-tac-toe | /ttt.rb | UTF-8 | 10,176 | 3.5625 | 4 | [] | no_license | class Board
def initialize(move)
if move.class == Array
@board = move[0..8]
elsif
@board = Array.new(9)
counter = 0
@board.each do |cell|
@board[counter] = counter
counter += 1
end
end
@board_array = @board
@board = game_board
end
def game_board
grid = ""
@board.each... | true |
b9e9d906ea93e861030ca664dbe97c49ade4fa78 | Ruby | Sh1pley/nightwriter | /lib/translator.rb | UTF-8 | 1,515 | 3.65625 | 4 | [] | no_license | require_relative 'alphabet'
class Translator
attr_reader :alphabet
def initialize
@alphabet = Alphabet.new
end
def to_braille_line(string, index)
line = ""
numbers = false
string.each_char do|character|
if character == " "
numbers = false
end
if numbers
line <... | true |
c1d93a13c5f11e4a779d3d62d3fc00ab5cae2228 | Ruby | melhemm/black-jack | /user.rb | UTF-8 | 488 | 3.140625 | 3 | [] | no_license | require './bank'
require './hand'
class User < Hand
include Bank
attr_accessor :hand, :bank
attr_reader :name
def initialize(name)
@name = name
@hand = []
@bank = 100
end
def user_hand(_flag = false)
if name == 'Dealer'
"#{name} #{hand.map { '*' }.join} points **"
else
"#... | true |
cb610dd8900dace8c75a5dd4d600aedb004f033e | Ruby | PhilHuangSW/Leetcode | /first_missing_positive.rb | UTF-8 | 1,124 | 4.34375 | 4 | [] | no_license | #################### FIRST MISSING POSITIVE ####################
# Given an unsorted integer array, find the smallest missing positive integer.
# Example 1:
# Input: [1,2,0]
# Output: 3
# Example 2:
# Input: [3,4,-1,1]
# Output: 2
# Example 3:
# Input: [7,8,9,11,12]
# Output: 1
# Follow up:
# Your algorithm should... | true |
a724b319bb08ba9ecddde151192c817581ffb995 | Ruby | schoetlr/project_cli_connect_four_with_tests | /connect_four/spec/computer_spec.rb | UTF-8 | 570 | 3.015625 | 3 | [] | no_license | require 'computer'
describe Computer do
let(:computer){Computer.new("Computron","O")}
describe '#initialize' do
it "should take 2 arguments" do
expect{Computer.new("Computron")}.to raise_error(ArgumentError)
end
it "should create a name" do
expect(computer.name).to eq("Computron")
end... | true |
7067672c8fdcbd48d6667f791b9de331a101d15c | Ruby | hokto/Judge | /Python/answer_sources/Products/increase.rb | UTF-8 | 2,279 | 3.546875 | 4 | [] | no_license | #解法としては、現在の値段をciと表すと「もっとも値の小さいciを取り出してmから引くという操作を
#何回することができるか」という風に解釈できる。よって、PriorityQueueというアルゴリズムを用いて
#もっとも安い値段をqueueから取り出し、取り出した後にその値段にbiを加算し、またqueueに追加する
#という操作をmが0になるまで繰り返せばよく、PriorityQueueの計算量は、要素の追加、取り出し共に
#O(log N)なので、O(log N + M*log N)=O(M*log N)となり、間に合います。
def get_i() #空白区切の入力を数値(整数)の配列で返す
return gets.ch... | true |
b559f28d35d41e45fc6fee90504fab50e1ea87c0 | Ruby | klaviyo/ruby-klaviyo | /lib/klaviyo/apis/campaigns.rb | UTF-8 | 1,605 | 2.546875 | 3 | [] | no_license | module Klaviyo
class Campaigns < Client
CANCEL = 'cancel'
CAMPAIGN = 'campaign'
CAMPAIGNS = 'campaigns'
SEND = 'send'
# Retrieves all the campaigns from Klaviyo account
# @kwarg :api_key [String] private API key for this request
# @return [List] of JSON formatted campaing objects
d... | true |
b756ece986ccd482df099c225128abf19d3aa37e | Ruby | KelvinMutuma/nse_data | /app/models/forex.rb | UTF-8 | 1,870 | 2.546875 | 3 | [] | no_license | # == Schema Information
#
# Table name: forexes
#
# id :integer not null, primary key
# currency :string(255)
# buy :float
# sell :float
# mean :float
# created_at :datetime
# updated_at :datetime
# guid :string(255)
# published_at :datetime
#
class ... | true |
1cc86bf2dcc1080438fb5924fc9afc4c1d11bd6b | Ruby | asuc-octo/cao | /app/models/i18n_utils.rb | UTF-8 | 710 | 2.546875 | 3 | [
"MIT"
] | permissive | # I18n utilities.
module I18nUtils
# Mapping of locales to UI friendly names.
# Add more locales and names here as desired.
LOCALE_NAMES = {
en: 'English',
hi: 'हिन्दी'
}
# Available locales for the main application.
#
# Note that these *do not* supersede available locales set via
# `I18n.a... | true |
426a93209e172faaf4d09513232089262fd32127 | Ruby | shveikus/json_api | /db/seeds.rb | UTF-8 | 1,645 | 2.671875 | 3 | [] | no_license | require 'httparty'
require 'oj'
require 'faker'
require 'progress_bar'
require 'pry'
HEADERS = {
'Content-type' => 'application/json'
}.freeze
threads = []
logins = []
50.times do
logins << Faker::Internet.user_name
end
bar_posts = ProgressBar.new 200_000
puts 'Start creating via http endpoint 200k posts'
20.ti... | true |
ff2db0a64ba1a3a6600c2d1212f6f302bc7426b9 | Ruby | karanm645/fixer_upper_2108 | /spec/house_spec.rb | UTF-8 | 1,996 | 3.375 | 3 | [] | no_license | require './lib/room'
require './lib/house'
RSpec.describe House do
it "exists" do
house = House.new("$400000", "123 sugar lane")
expect(house).to be_an_instance_of(House)
end
it "returns a price" do
house = House.new("$400000", "123 sugar lane")
expect(house.price).to eq(400000)
end
it "r... | true |
5eaaf175fd94dc7d62a8bb7ff6647b9861f4be9f | Ruby | David-Roark/code_practice | /exercism/dominoes/dominoes.rb | UTF-8 | 974 | 3.78125 | 4 | [] | no_license | # OOP
class Dominoes
attr_accessor :head, :tail
def initialize(domi)
@head, @tail = domi
end
def self.chain?(ds)
return true if ds == []
return ds[0][0] == ds[0][1] if ds.size == 1
ds.permutation{ |d| return true if can_linked?(d) }
false
end
# if all dominoes can link,
# the last 'dom... | true |
eeb40541f55d2e9b02adfdbe5aa79f72ebb37dc6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/7809d7e3090e42239223415747e7b312.rb | UTF-8 | 444 | 3.484375 | 3 | [] | no_license | require 'prime'
class Raindrops
SOUNDS = { 3 => 'Pling', 5 => 'Plang', 7 => 'Plong' }
def initialize(number)
@number = number
end
def self.convert(number)
new(number).convert
end
def convert
sound.empty? ? @number.to_s : sound
end
private
def sound
@sound ||= prime_divisors.map {... | true |
c78d0b0498f3e5cc11a3c9a01963c096421bdb23 | Ruby | angelodlfrtr/ruby-cic-embeded-payment | /lib/cic_embeded_payment/payment_response.rb | UTF-8 | 5,728 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
module CicEmbededPayment
class PaymentResponse
attr_reader :original_response, :parsed_response
# Parse RestClient response to cic payment gateway
#
# @param response [Class] The RestClient response
def initialize response
@original_response, @parsed_response = response,... | true |
32b6f2e63e8d359b488abd36f430b09f2db42ae4 | Ruby | jianghaoyuan2007/pod-template-fastlane | /setup/TemplateConfigurator.rb | UTF-8 | 3,319 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'fileutils'
require 'colored2'
require 'find'
module Pod
class TemplateConfigurator
attr_reader :pod_name, :homepage, :git_source, :github_username, :github_repo_name
def initialize(pod_name)
@pod_name = pod_name
@message_bank = MessageBank.new(self)
end
def ask(question)
... | true |
e6ec8127db5690768665a2781b8b093ba19f6643 | Ruby | cpcsacggc/RubySchool.US | /arc/17/split_method5.rb | UTF-8 | 230 | 3.359375 | 3 | [] | no_license | input = File.open("income.txt", "r")
total = 0
x = 0
while x < 6
x+=1
line = input.gets
arr = line.split(",")
total += arr[1].to_i
puts "#{arr[0]} - $#{arr[1]}"
end
input.close
puts ""
puts "6 month's Total: #{total}" | true |
02b9cef267ec2e04b92d9b84cb727bc4f74b88f1 | Ruby | dalalsunil1986/algorithms_ruby | /others/group_open_hours.rb | UTF-8 | 3,286 | 3.6875 | 4 | [] | no_license | require 'RSpec'
require 'date'
def group_open_hours(open_hours)
# if all are empty, return all days nil hash
return [empty_day('Monday-Sunday')] if open_hours.empty?
output = []
count = 0
input = {}
# convert input array to hash with day as key
open_hours.each do |hash|
# change day key to days as... | true |
f1f183521c41ab7adc6259233c70f3eaf2886aee | Ruby | matthewmpalen/ruby-auction-house | /models/item.rb | UTF-8 | 331 | 2.890625 | 3 | [] | no_license | #########
# Models
#########
class Item
# Model which represents the concrete item for sale in an auction
attr_accessor :available
attr_reader :name, :description, :created_at
def initialize(name, description)
@name = name
@description = description
@available = true
@created_at = DateTime.new... | true |
8ade34a66dd72e005b1a24641a70d6e497621359 | Ruby | meliew/collections_practice-online-web-pt-051319 | /collections_practice.rb | UTF-8 | 860 | 3.8125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def sort_array_asc(integer_array)
integer_array.sort do |a, b|
a <=> b
end
end
def sort_array_desc(integer_array)
integer_array.sort do |a, b|
b <=> a
end
end
def sort_array_char_count(array)
array.sort do |a, b|
a.length <=> b.length
end
end
def swap_elements(array)
array[1], array[2] = array[2... | true |
c5683c7d7ae7429e70ddf72b441e3761d90f97a3 | Ruby | lauranjansen/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 582 | 3.84375 | 4 | [] | no_license | def echo(input)
input
end
def shout(input)
input.upcase
end
def repeat(input, num = 2)
output = input
for i in 2..num
output = output + " " + input
end
output
end
def start_of_word(input, num)
input[0,num]
end
def first_word(input)
input.split(" ")[0]
end
def titleize(input)
words = input.split(" ")
ou... | true |
7178e91c8871ad7bc52be1eff2da0f0ddbdcdfc2 | Ruby | ysk1180/refactoring-ruby-edition | /replace_abstract_superclass_with_module.rb | UTF-8 | 1,156 | 3.609375 | 4 | [] | no_license | # class Item
# def initialize(name, origin_country = nil)
# @name = name
# @origin_country = origin_country
# end
#
# def description
# puts "商品名:#{@name} / 補足:#{additional_description}"
# end
# end
#
# class DomesticItem < Item
# def additional_description
# '国内産です'
# end
# end
#
# class Im... | true |
1109ea4792204e2182e1d2e7424d93c5013cdf2b | Ruby | pyjac/mastermind | /lib/game_colours.rb | UTF-8 | 580 | 3.28125 | 3 | [] | no_license | class GameColours
attr_accessor :beginner_colours, :intermediate_colours, :advanced_colours
def self.beginner_colours
{"R" => "Red" , "Y" => "Yellow" , "B" => "Blue", "G" => "Green"}
end
def self.intermediate_colour
beginner_colours.merge( { "O" => "Orange"})
end
def self.advanced_colours
intermediate_... | true |
fa25f688c49f0a75128776cd0b36798462405bc3 | Ruby | match-and-snatch/web | /lib/elasticpal/response.rb | UTF-8 | 1,211 | 2.6875 | 3 | [] | no_license | module Elasticpal
class Response
def initialize(response, query = nil)
@plain_response = response
@query = query
@scope = @query.try(:model)
end
def records(scope = {})
results = relation(scope).to_a
ids.map do |id|
results.find { |x| x.id == id }
end.compact.s... | true |
1bfcb6645d825917b5515f478de04b3543486c7e | Ruby | pcloeter/BenchBnB | /app/models/user.rb | UTF-8 | 867 | 2.640625 | 3 | [] | no_license | class User < ApplicationRecord
validates :username, presence: true
validates :password, length: { minimum: 6, allow_nil: true }
after_initialize :ensure_token
attr_reader :password
def self.generate_token
SecureRandom.urlsafe_base64
end
def self.find_by_credentials(credentials)
user = User.find_... | true |
c4b6676841b308b50c8103892b543407e8880fd7 | Ruby | megamsys/megam_api | /lib/megam/core/organizations_collection.rb | UTF-8 | 3,133 | 3.109375 | 3 | [
"MIT"
] | permissive | module Megam
class OrganizationsCollection
include Enumerable
attr_reader :iterator
def initialize
@organizations = Array.new
@organizations_by_name = Hash.new
@insert_after_idx = nil
end
def all_organizations
@organizations
end
def [](index)
@organizations... | true |
0a1289d3a88355023e4929ff7f941caed0202c44 | Ruby | toddt67878/Building_a_Roll_Call_System_in_Ruby | /main.rb | UTF-8 | 3,583 | 3.328125 | 3 | [
"MIT"
] | permissive | require 'rspec'
require 'date'
class RollCallBooleanError < StandardError
def message
'Status needs to be either true or false'
end
end
class RollCallPercentError < StandardError
def message
'Grouping needs to be either present or absent'
end
end
class RollCall
attr_reader :roll
def initialize
... | true |
40bc442e2d85b520a0477621cde34441e658c3c0 | Ruby | oscos/launch_school | /rb101/lesson3/hard1/x02.rb | UTF-8 | 503 | 3.3125 | 3 | [] | no_license | =begin
Launch School: RB101 Programming Foundations - Lesson 3 - Practice Problems
ExerciseName: [Hard](https://launchschool.com/lessons/263069da/assignments/a3c602d1)
FileName: x02.rb
Answered On: 10/01/2020
=end
# require "pry"
# require "pp"
# What do you expect to happen when the greeting variable is referenced i... | true |
cb995f2492587cf02de368a0b5b081f59a0105b1 | Ruby | Waynexiee/My_leetcode | /4Sum2.rb | UTF-8 | 437 | 3.40625 | 3 | [] | no_license | def four_sum_count(a, b, c, d)
size = a.size
h = {}
sum = 0
0.upto(size - 1) do |i|
0.upto(size - 1) do |j|
h[a[i] + b[j]] = [] unless h[a[i] + b[j]]
h[a[i] + b[j]] << [a[i],b[j]]
end
end
0.upto(size - 1) do |i|
0.upto(size - 1) do |j|
sum += h[-(c[i] + d[j])].size if h[-(c[i]... | true |
f4c6c7e1b082a2ace32a99a06399d11f3a0aa90a | Ruby | teoucsb82/pokemongodb | /lib/pokemongodb/pokemon/seel.rb | UTF-8 | 1,402 | 2.78125 | 3 | [] | no_license | class Pokemongodb
class Pokemon
class Seel < Pokemon
def self.id
86
end
def self.base_attack
104
end
def self.base_defense
138
end
def self.base_stamina
130
end
def self.buddy_candy_distance
2
end
... | true |
89ee9ae0745f8a94bb6bc69bb868f4f55b560b2d | Ruby | everypolitician-scrapers/china-national-peoples-congress | /scraper.rb | UTF-8 | 1,262 | 2.53125 | 3 | [] | no_license | #!/bin/env ruby
# encoding: utf-8
# frozen_string_literal: true
require 'pry'
require 'scraped'
require 'scraperwiki'
def noko_for(url)
Nokogiri::HTML(open(url).read)
end
def scrape_list(url)
noko = noko_for(url)
section = noko.css('h2').find { |h2| h2.text.include? '选举单位' } or raise "Can't find section"
se... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.