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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
fa772d6fb6768cbc7c007c738d2af1c4548520cf | Ruby | kivanio/brcobranca | /lib/brcobranca/remessa/cnab400/banrisul.rb | UTF-8 | 9,828 | 2.53125 | 3 | [
"BSD-3-Clause",
"MIT"
] | permissive | # frozen_string_literal: true
module Brcobranca
module Remessa
module Cnab400
class Banrisul < Brcobranca::Remessa::Cnab400::Base
attr_accessor :convenio
validates_presence_of :agencia, :convenio, :sequencial_remessa, message: 'não pode estar em branco.'
validates_length_of :agenci... | true |
7fe2bfd6f3877c7666b070946d58fbe3fef25484 | Ruby | gllluch/speller | /lib/speller.rb | UTF-8 | 654 | 2.6875 | 3 | [] | no_license |
require_relative 'speller\HTTPClient'
require_relative 'speller\spell'
require 'JSON'
module Speller
URL = 'http://speller.yandex.net/services/spellservice.json/checkText?text='
def self.do text
@text = text
@respons = HTTPClient.new.get(URL, text)
Spell.new(@text, @respons)
end
end
tex... | true |
d6b2fdbb4e4efcdd9f89ed30300925d64c834400 | Ruby | bonzouti/Ruby | /exo_09.rb | UTF-8 | 173 | 3.328125 | 3 | [] | no_license | puts "Quel votre prénom ?"
print ">"
user_name = gets.chomp
puts "Quel est votre nom ?"
print ">"
familly_name = gets.chomp
puts " Bonjour, #{user_name},#{familly_name }!"
| true |
3787f5606700d72e77ff520753bb4d2428fac91a | Ruby | brandoshmando/OOP | /people.rb | UTF-8 | 710 | 4.34375 | 4 | [] | no_license | class Person
def initialize(name)
@name = name
end
def greeting
puts "Hello, my name is #{@name}!"
end
end
class Student < Person
def learn
puts "I get it!"
end
end
class Instructor < Person
def teach
puts "Everything in Ruby is an object!"
end
end
instructor = Instructor.new("Chris")
instructor... | true |
20bbbe1b2ab61b5f9f3f78254853647d7c59413b | Ruby | ManageIQ/manageiq-smartstate | /lib/metadata/util/event_log_filter.rb | UTF-8 | 2,102 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | module EventLogFilter
def self.prepare_filter!(filter)
raise ArgumentError, "filter must be a Hash" unless filter.kind_of?(Hash)
filter[:rec_count] = 0 if filter[:rec_count].nil?
filter[:num_days] = 0 if filter[:num_days].nil?
filter[:generated] = (Time.now.utc - filter[:num_days] * 86400).iso8601 u... | true |
d17c155057640b8c7be93af95cc6166a23b8f8c6 | Ruby | DCR430/programming-univbasics-4-crud-lab-nyc01-seng-ft-051120 | /lib/array_crud.rb | UTF-8 | 833 | 3.65625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def create_an_empty_array
array=[]
end
def create_an_array
array=["oliver","gloria","daniel","platty"]
end
def add_element_to_end_of_array(array, element)
array << ("arrays!")
end
def add_element_to_start_of_array(array, element)
array.unshift ("wow")
end
def remove_element_from_end_of_array(array)
arrays_arra... | true |
75c6cd0af55e7893472d1b3914bbccd631143574 | Ruby | waffle-iron/mysore_city_bus | /scrap.rb | UTF-8 | 956 | 2.65625 | 3 | [] | no_license | require 'net/http'
require 'open-uri'
require 'nokogiri'
require 'pry'
require 'json'
require 'active_support/all'
require 'active_support/core_ext/hash/conversions'
# uri = URI.parse('http://mitra.ksrtc.in/MysoreMBus/rtemap.jsp')
# uri = fetch("http://www.somewebsite.com/hahaha/")
uri = "http://mitra.ksrtc.in/MysoreM... | true |
b2d493b5c9fd97a2a394f0481fea0c496d5fb4a3 | Ruby | Jstuff36/InterviewPractice | /AppAcademySkypeInterviewRuby/is_prime?.rb | UTF-8 | 212 | 3.5 | 4 | [] | no_license | def is_prime?(num)
return false if num < 2 #only numbers greater than 1 can be prime
return true if num == 2 #only even prime
(2...num).each do |i|
return false if num % i == 0
end
true
end
p is_prime?(4) | true |
86f1c314cfaccb54605a9dd8fe95a6cf809a0adc | Ruby | taylorthurlow/rubygame | /entities/tile_collider.rb | UTF-8 | 1,078 | 3.078125 | 3 | [] | no_license | class TileCollider < Collider
attr_accessor :tile
def initialize(x, y, width, height, tile = nil)
super(width, height)
@x = x
@y = y
@tile = tile
end
def pos_x
box[0]
end
def pos_y
box[1]
end
def center
[@tile.pos_x + @x + @width / 2, @tile.pos_y + @y + @height / 2]
end... | true |
023653300c60f195811a04b133d184c7f59bacf9 | Ruby | kaxla/portfolio | /test/features/posts/edit_post_test.rb | UTF-8 | 2,377 | 2.53125 | 3 | [
"MIT"
] | permissive | require "test_helper"
feature "Edit a Post" do
#--------------INDEX PAGE------------------
scenario "editor can edit a post from index page" do
sign_in(:editor)
visit posts_path
page.find("tbody tr:last").click_on "Edit"
fill_in "Body", with: posts(:unpublished).body
click_button "Update Post"
... | true |
67e826b0ae7c5312bb972ef20a0ab8714d6ebf48 | Ruby | estherkimyunjung/ruby-oo-fundamentals-instance-variables-lab-hou01-seng-ft-042020 | /lib/dog.rb | UTF-8 | 163 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog
def name=(dog_name)
@this_dogs_name = dog_name
end
def name
@this_dogs_name
end
end
lassis = Dog.new
lassis.name = "Lassie"
lassis.name
| true |
e21b9db267131df8db1b74821b3f48ba523f085f | Ruby | madking55/LS-IntroToProgrammingWithRuby | /Basics/3.rb | UTF-8 | 110 | 3.078125 | 3 | [] | no_license | movies = {First: 1975, Second: 2014, Third: 2005}
puts movies[:First]
puts movies[:Second]
puts movies[:Third] | true |
c416475f66a586a1fd40d25ab932d9ae8156b946 | Ruby | benatkin/hurl | /app/helpers/pretty_printing.rb | UTF-8 | 1,586 | 2.671875 | 3 | [
"MIT"
] | permissive | module Hurl
module Helpers
# Pretty printing of content types for the response div.
module PrettyPrinting
def pretty_print(type, content)
type = type.to_s
if type =~ /json|javascript/
pretty_print_json(content)
elsif type == 'js'
pretty_print_js(content)
... | true |
434685198caf845eb55f6ffca43ef0670d122d4c | Ruby | dayatroman79/raaws | /spec/request_spec.rb | UTF-8 | 3,350 | 2.53125 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/spec_helper.rb'
describe RAAWS::Request do
describe "PARAMS workflow" do
before(:each) { @request = RAAWS::Request.new }
it "adds new values to params" do
@request.params = {:title => "Modern Times"}
@request.params[:title].should == "Modern Times"
... | true |
41a0271059fcd1ae4cb69029767989815ffb5931 | Ruby | quentin6440/QS2J3_dossier | /lib/01_pyramids.rb | UTF-8 | 580 | 3.65625 | 4 | [] | no_license |
def ask_storeys
puts "Yo ! Like pyramids huh, How many storeys you want bru ? Only odd numbers accepted"
print ">"
str_nb = gets.chomp.to_i
if str_nb%2 !=0
return str_nb
else puts "Un nombre impair on te dit !!"
end
end
def wtf_pyramid (str_nb)
str_h = str_nb / 2
... | true |
957faa4f72f02bfe6538aa8a0823aae1dfaccd0a | Ruby | qbl/insinyur-online-replit-lab | /ruby-series/episode-2/dynamic_fizz_buzz.rb | UTF-8 | 670 | 3.734375 | 4 | [] | no_license | # 1.upto(100) do |i|
# if (i % 3 == 0 && i % 4 == 0 && i % 5 == 0)
# puts 'FizzSussBuzz'
# elsif (i % 3 == 0 && i % 4 == 0)
# puts 'FizzSuss'
# elsif (i % 4 == 0 && i % 5 == 0)
# puts 'SussBuzz'
# elsif (i % 3 == 0)
# puts 'Fizz'
# elsif (i % 4 == 0)
# puts 'Suss'
# elsif (i % 5 == 0)
# ... | true |
22b7b651204b2b80306f43ee98039b214e753a98 | Ruby | SFEley/acts_as_icontact | /lib/acts_as_icontact/readonly.rb | UTF-8 | 649 | 2.71875 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0"
] | permissive | module ActsAsIcontact
# Overrides methods to make a resource class read-only. Replaces property assignments and save methods with exceptions.
module ReadOnly
# Properties of this class are read-only.
def method_missing(method, *params)
raise ActsAsIcontact::ReadOnlyError, "#{self.class.readab... | true |
2a3ee76309dbfcc8f4541e1d57e8e4f97e923e61 | Ruby | anpaez/devops-bootcamp-backend-app | /app/controllers/api/v1/ping_controller.rb | UTF-8 | 805 | 2.625 | 3 | [] | no_license | require 'net/http'
class Api::V1::PingController < ApplicationController
# GET Ping
def index
@name = params[:name]
@time = params[:time].to_i
puts "Me ha llamado #{@name}, cuenta atrás: #{@time}"
if @time > 0
@time -= 1
@uri = URI('http://localhost:3000/... | true |
b559dfea51bb38c1619a735b015c50e6e6b8f44a | Ruby | Automatic365/enigma | /lib/key.rb | UTF-8 | 118 | 2.765625 | 3 | [] | no_license | require "pry"
class Key
attr_reader :key
def initialize(key = nil)
@key = rand(10000..99999).to_s
end
end
| true |
99d3ce589b5b1511916fc2f3942c3512b7627465 | Ruby | BJSummerfield/Projecteuler | /problem19.rb | UTF-8 | 1,373 | 3.515625 | 4 | [] | no_license | year = 1900
months = [
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
]
week_day = [
1,
2,
3,
4,
5,
6,
7
]
@sundays = []
def sunday_check(year, months, week_day)
date = set_start(year, months, week_day)
parse_years(date, year, months, week_day)
puts @sundays
puts @sunda... | true |
6a2d2153bd354a7e2357fb1966aa86c22da4610a | Ruby | omardelarosa/ruby_euler_lab | /002_even_fibonacci/even_fib_george.rb | UTF-8 | 1,073 | 3.96875 | 4 | [] | no_license | require './../lib/mathy.rb'
def fib_george(max)
#initializers
i = 2
n = 0
n_minus_1 = 1
n_minus_2 = 0
# n = n_minus_1 + n_minus_2
while i < max
# bubble = [n-2, n-1, n]
#set current value to the sum of the two previous
n = n_minus_1 + n_minus_2
#shift ... | true |
ee1446715ccfaa6125db53f80b6ce35ec03d1007 | Ruby | shadabahmed/leetcode-problems | /0110-balanced-binary-tree.rb | UTF-8 | 698 | 3.8125 | 4 | [] | no_license | # Definition for a binary tree node.
class TreeNode
attr_accessor :val, :left, :right
def initialize(val)
@val = val
@left, @right = nil, nil
end
end
# @param {TreeNode} root
# @return {Boolean}
def is_balanced(root)
max_depth(root) >= 0
end
def max_depth(root)
return 0 if root.nil?
left_depth = ... | true |
d336e6c638401da1dbac781bd33e3c9af0a8ce67 | Ruby | kaudyac/backend_mod_1_prework | /ex34.rb | UTF-8 | 2,712 | 4.625 | 5 | [] | no_license | animals = ['bear', 'ruby', 'peacock', 'kangaroo', 'whale', 'platypus']
# 1.
puts 'The second animal is at 1 and is a ruby.'
puts 'The animal at 1 is the second animal and is a ruby.'
puts animals[1]
# 2.
puts 'The third animal is at 2 and is a peacock.'
puts 'The animal at 2 is the third animal and is a peacock.'
puts... | true |
9409ac1ff1a5b8f7f14b1298a6136df98c576ca4 | Ruby | chadbrewbaker/brewlib | /graph.rb | UTF-8 | 3,636 | 2.875 | 3 | [] | no_license |
require 'pp'
class Graph
attr_reader :verts, :rep
attr_accessor :no_edge_val
#Must have these methods defined in child classes
#graph.edge(i,j)
#graph.set_edge(i,j,value)
#graph.set_dir_edge(i,j,value)
#graph.reorder(permutation)
#graph.resize(i)
def edge?(i,j)
if(edge(i,j) != @no_edge_val)
return true... | true |
624cccabbff37660eb631abb208c8184a4297e93 | Ruby | emk/rdf-agraph | /lib/rdf/allegro_graph/parser.rb | UTF-8 | 951 | 2.703125 | 3 | [
"Unlicense"
] | permissive | module RDF::AllegroGraph
# A module containg the URL parser of AllegroGraph objects such as :
# - servers
# - catalogs
# - repositories
module Parser
# Parse a full URI and extract the server/catalog and the repository ID.
#
# The parsing uses the default AllegroGraph URI schema :
# http://se... | true |
f295b460cb21e80366b871e7b50adb543f4fbc21 | Ruby | brycematsuda/ytcms-lite | /test/models/season_test.rb | UTF-8 | 1,665 | 2.640625 | 3 | [] | no_license | require 'test_helper'
class SeasonTest < ActiveSupport::TestCase
test "season name must not be empty" do
season = Season.new
assert season.invalid?
assert season.errors[:name].any?
end
test "season permalink must not be empty" do
season = Season.new(:name => "No permalink!")
assert season.in... | true |
226680a132eedac5edbd8a910eac2a9bdf7b88fc | Ruby | EDalSanto/LaunchSchool | /courses/test_prep/fake_array.rb | UTF-8 | 296 | 3.71875 | 4 | [] | no_license | class FakeArray
def initialize(array)
@elements = array
end
def []=(index, element)
@elements[index] = element
end
def [](index)
@elements[index]
end
end
array = FakeArray.new([])
array[0] = 23
array.[]=(1, 42)
#puts "0th element: #{array[0]} 1st element: #{array[1]}"
| true |
b78c2dc3e3e122b42296c67651f94c8c4a0dc75a | Ruby | jstirk/ludum-dare-28 | /src/yogo/structure/iron_mine.rb | UTF-8 | 579 | 2.734375 | 3 | [] | no_license | require 'yogo/structure/base'
module YOGO
module Structure
class IronMine < Base
def self.name
"Iron Mine"
end
def self.description
"+5 iron"
end
def self.setup_cost
33
end
def self.running_cost
10
end
def self.valid_tile?... | true |
ea04b4579a9ae5984a3d2f6ed2fb9f3c57266ade | Ruby | AJFaraday/slow_time_strategy | /app/models/walker.rb | UTF-8 | 935 | 3.09375 | 3 | [
"MIT"
] | permissive | class Walker < Token
attr_accessor :health
def initialize(x, y, owner, grid = nil)
super(x, y, owner, grid)
@health = 1
end
def calculate_movement
target_x, target_y = next_step
initial_health = @health
if @grid.in_range?(target_x, target_y)
-> do
target = @grid.token_at(tar... | true |
b2acef2b2112231958452fa2f9cf9ee327dd8687 | Ruby | StephenAjayi/epicodus_to_do | /spec/lister_spec.rb | UTF-8 | 774 | 2.84375 | 3 | [] | no_license | require('rspec')
require('lister')
describe(Task) do
before() do
Task.clear()
end
describe('#description') do
it('returns the description of a task') do
test_task = Task.new("wash the car")
expect(test_task.description()).to(eq("wash the car"))
end
end
describe('#save') do
it('s... | true |
4e725a8005408de6f95570c0be9bd572a0cc3ff0 | Ruby | armagh-dev/armagh | /lib/armagh/utils/interruptible_sleep.rb | UTF-8 | 1,223 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | # Copyright 2018 Noragh Analytics, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in... | true |
4ffadfdcb03a240c8f3d954ac796c3f938a65b12 | Ruby | leblanc119/omnicalc_params | /app/controllers/calculations_controller.rb | UTF-8 | 2,484 | 2.703125 | 3 | [] | no_license | class CalculationsController < ApplicationController
def flex_square
# params = {"the_number"=>"17"}
@user_number = params["the_number"].to_f
@squared_number = @user_number**2
render("calculations/flex_square.html.erb")
end
def flex_square_root
# params = {"the_number"=>"17"}
@user_numbe... | true |
c7e319e280f668a1f7df5d8f443645c2627ec7bd | Ruby | rohitreddyjd/oraview | /tools/send.rb | UTF-8 | 314 | 2.703125 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding :utf-8
require "bunny"
#Connect to RabbitMQ server
conn = Bunny.new
conn.start
#Create a channel
ch = conn.create_channel
#declare a queue
q = ch.queue("hello")
ch.default_exchange.publish("Hello World!", :routing_key => q.name)
puts " [x] Sent 'Hello World!'"
conn.close
| true |
1626f16c9c145bc3ec2390fdf3cfa88ad05ed8d8 | Ruby | robobluebird/simple_maps | /middlewares/ws.rb | UTF-8 | 1,054 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'faye/websocket'
require 'json'
module Rack
class Lint
def call(env = nil)
@app.call(env)
end
end
end
class Rack::Lint::HijackWrapper
def to_int
@io.to_i
end
end
class Ws
def initialize(app)
@app = app
@clients = []
end
def call(env)
if Faye::WebSocket.websock... | true |
7a195a2509fd792f2d90c36486ee8e46a7bacaab | Ruby | Emanao/school-domain-v-000 | /lib/school.rb | UTF-8 | 393 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # code here
class School
def initialize(name)
@name=name
@roster={}
end
def roster
@roster
end
def add_student(student, grade)
@roster[grade] = [] if !@roster.include?(grade)
@roster[grade]<<student
end
def grade(grade)
@roster[grade]
end
def sort
@roster.collect do|grade,... | true |
a2072e0b72431db0375c7764dfd151ba82dfb974 | Ruby | justinyiwang/ICS-Course | /ch13/die.rb | UTF-8 | 367 | 3.484375 | 3 | [] | no_license | class Die
def initialize
# I'll just roll the die, though we could do something else
# if we wanted to, such as setting the die to have 6 showing.
roll
end
def roll
@number_showing = 1 + rand(6)
end
def showing
@number_showing
end
def cheat num
if !num.between?(1,6)
roll
else... | true |
09fad2e6e33fa88578424cad7e99c2f955958a66 | Ruby | dallashall/what-if-game | /WhatIf/app/models/team.rb | UTF-8 | 1,375 | 2.828125 | 3 | [] | no_license | class Team < ApplicationRecord
has_many :questions
has_many :answers, through: :questions
has_many :users
after_initialize :set_team_code!
def set_team_code!
self.code ||= generate_team_code
end
def team_code
SecureRandom::urlsafe_base64(3).upcase
end
def generate_team_code
code = team... | true |
9358c5a72a4ea578f909cccb488c696a61a38937 | Ruby | highnotes/eardrums | /app/models/level.rb | UTF-8 | 602 | 2.625 | 3 | [] | no_license | class Level < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :description
validates_presence_of :index
validates_numericality_of :index, only_integer: true
validates_uniqueness_of :index
has_many :courses
def self.beginner_levels
Level.where(index: [1,2,3,4]).collect {|l... | true |
7b4346253a19219cee6203d067abe2317348c6ef | Ruby | catks/djin | /lib/djin/root_cli_parser.rb | UTF-8 | 1,506 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Djin
## This class is responsible to handle options that must be evaluated
# before the load of tasks in djin file(eg: djin.yml)
class RootCliParser
class << self
def parse!(args = ARGV)
options = {}
# TODO: Find a better way to handle -f/--file op... | true |
9b821762bced34466787369e4e347f2c1e90ab8e | Ruby | lupinthe14th/codewars | /lib/html_special_chars.rb | UTF-8 | 117 | 2.71875 | 3 | [
"MIT"
] | permissive | def html_special_chars(str)
str.gsub(/<|>|"|&/, '<' => '<', '>' => '>', '"' => '"', '&' => '&')
end
| true |
e417a468994dec4129c4cb544f466740fc06d0bb | Ruby | Vizzuality/trase | /app/services/api/v3/refresh_dependencies.rb | UTF-8 | 4,133 | 2.515625 | 3 | [
"MIT"
] | permissive | module Api
module V3
class RefreshDependencies
include Singleton
def initialize
query =<<~SQL
SELECT table_name, column_name, dependent_name, dependent_type
FROM maintenance.refresh_dependencies
SQL
begin
result = Api::V3::YellowTable.connection.... | true |
c5abe5fc93901f2064272af0b3578872afd860bd | Ruby | peter-leonov-dh/screen-diff | /rgb.rb | UTF-8 | 1,224 | 3.015625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'rmagick'
def img_to_rgb file_src, io_dst
img = Magick::Image.read(file_src).first
w = img.columns
h = img.rows
io_dst.puts "RGB"
io_dst.puts "#{w} #{h}"
h.times do |y|
# x, y, columns, rows -> array
io_dst.puts img.export_pixels(0, y, w, 1, 'RGB').join(' ')
end
end
d... | true |
b30a6a8b7ed997b6fb1d282bbb8dc3a2f53b15f9 | Ruby | LuizFernandoCabral/DevSoft2014-01 | /aula03/ex3.3.rb | UTF-8 | 266 | 3.3125 | 3 | [] | no_license | def ordena(array)
return array if array.size <= 1
pivot = array[0]
return ordena(array.select { |y| y < pivot }) +
array.select { |y| y == pivot } +
ordena(array.select { |y| y > pivot })
end
a=[20,0,50,30,34,33,35,22,1]
print ordena(a)
| true |
a7871aa6564fe986823123d10578c0475341700d | Ruby | amadeusM/Ruby-Projects | /app_academy_select_exercise.rb | UTF-8 | 207 | 3.515625 | 4 | [] | no_license | # This method returns a list of perfect squares smaller than num.
def perfect_squares(num)
array = []
i = 1
while i*i < num
array << i
i += 1
end
array.map{|i| i*i}
end
| true |
0271abb15151df4271ff14cd896afbac4bb8d49d | Ruby | Marvinsky/pollApp | /db/seeds.rb | UTF-8 | 1,175 | 2.546875 | 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
101de55d67863e8b4c492966dbb115be1a613f31 | Ruby | Adzz/challenges | /spec/list_recursion/all_challenges_spec.rb | UTF-8 | 9,090 | 3.34375 | 3 | [
"MIT"
] | permissive | require 'list_recursion'
require 'spec_helper'
RSpec.describe 'list recursion' do
# This gives the tests a method named `nil_node`,
# whose value is what's in the block.
# It is different from normal methods in that
# it only runs the code the first time,
# so that successive invocations of `nil_node` from w... | true |
3188909dd46dc53ee892440ac12056b0cfa6bc9f | Ruby | kaize/deadline_camp | /lib/member_collection_convertor.rb | UTF-8 | 1,632 | 2.53125 | 3 | [] | no_license | class MemberCollectionConvertor
def initialize(*args)
custom_options = args.extract_options!
@new_options = default_options.merge custom_options.symbolize_keys
@collection = args[0]
end
def to_xls(options = {})
merged_options = options.merge @new_options
if @collection.first.present?
m... | true |
1f7ec2af66f14042dfc5a8cc16ad15676354a82e | Ruby | hailinzeng/simple_crm | /lib/crypt.rb | UTF-8 | 1,232 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'openssl' unless defined?(::OpenSSL::Cipher::Cipher)
module SimpleCrm
module Admin
##
# Common utility methods used within the admin application.
#
module Utils
##
# This Util it's used for encrypt/decrypt password.
# We want password decryptable because generally for our si... | true |
ad1aa1df001d54398061a0201dd940715b52adcf | Ruby | coreyhellwege/Ruby-Fundamentals | /week3/day12.rb | UTF-8 | 547 | 4.375 | 4 | [] | no_license | # Ternary
# will puts either the first or second string dependant on whether what's before the ? is true or false
puts true ? "it is true" : "it is false"
x = 10 < 5 ? "it is true" : "it is false"
def method1
return "elephants"
end
def method2
return "hello world"
end
# instead of writing this:
# if fa... | true |
decd05b2894cac1f3b5c2983bb1771058ab5f29a | Ruby | kmcphillips/vocabulizer.com | /test/unit/term_test.rb | UTF-8 | 5,401 | 2.828125 | 3 | [] | no_license | require 'test_helper'
class TermTest < ActiveSupport::TestCase
def valid_term
FactoryGirl.create(:term)
end
def valid_term_with_details
term = FactoryGirl.create(:term)
term.details << FactoryGirl.create(:term_detail)
term
end
test "#populate_details should just return false if there are ... | true |
52702fe3d22682e2361210bd97df4f08ef31dbef | Ruby | huffman442/Projects | /UnitConverter/unit_converter.rb | UTF-8 | 975 | 3.796875 | 4 | [
"MIT"
] | permissive | class Mass
def intake
puts "Would you to convert to l)bs or to k)g?"
l_or_k = gets.chomp
puts "How much mass would you like to convert?"
mass = gets.chomp
if l_or_k == "l"
metric_to_english(mass)
elsif l_or_k == "k"
english_to_metric(mass)
... | true |
bbedefc1c84d2f39110fa5cc2fdd20a56304e4af | Ruby | pcrunn/learning-ruby | /classes/person/Person_Test.rb | UTF-8 | 134 | 3.484375 | 3 | [] | no_license | require './Person'
alex = Person.new("Alexander", "P", 14)
alex.welcome
if alex.getAge < 15
puts "Wow, such a young developer."
end | true |
6094e14be4092522b8ed37bc515e13b719d8f875 | Ruby | madelinecr/xkcd_scraper | /xkcd_scraper.rb | UTF-8 | 728 | 2.71875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
@uri = "http://www.xkcd.com/"
@comics = Array.new
doc = Nokogiri::HTML(open("#{@uri}/archive"))
doc.xpath('//div[@id="middleContainer"]/a').each do |link|
@comics << URI(link['href'])
end
@comics.each do |link|
doc = Nokogiri::HTML(open("#{@uri}#{link}")... | true |
099bce7ec442522c91341b570713c31acac07538 | Ruby | bebbs/takeaway-challenge | /lib/order_interface.rb | UTF-8 | 1,728 | 3.78125 | 4 | [] | no_license | require_relative 'phone'
class OrderInterface
include Phone
def initialize(restaurant)
@order = Order.new(restaurant)
@menu = order.menu
option_menu
end
attr_reader :order, :menu
def option_menu
loop do
print_options_list
handle(input)
end
end
def input
print "Inp... | true |
96924793d76c88c4c2accec3d922bb4ba5252a6d | Ruby | kaspth/activemodel-aggregator | /lib/active_model/aggregator/aggregation.rb | UTF-8 | 994 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'set'
module ActiveModel
module Aggregation
extend ActiveSupport::Concern
class_methods do
def aggregate(name, required: nil)
unless aggregates.include? name
aggregates << name
define_accessors(name, model_class_for(name))
validate_required_attributes(name... | true |
2a375dbb50c86e015f7ec24860a28fed992fdbfb | Ruby | codystair/lc_book | /two_sum.rb | UTF-8 | 496 | 3.625 | 4 | [] | no_license | # Brute Force
# def two_sum(nums, target)
# (0...nums.size).each do |i|
# ((i + 1)...nums.size).each do |j|
# if nums[i] + nums[j] == target
# return [i + 1, j + 1]
# end
# end
# end
# end
def two_sum(nums, target)
map = {}
(0...nums.size).each do |i|
current_value = nums[i]
... | true |
bf084ea1ad4a6c3777a9419020560621fc2a9b3f | Ruby | teekenl/dailycodechallenge | /arithmeticTree.rb | UTF-8 | 369 | 3.828125 | 4 | [] | no_license | class Node
attr_accessor :val, :left, :right
end
def solve_arithmetic(node)
return node.val.to_f if is_numeric?(node.val)
return eval("#{solve_arithmetic(node.left)} #{node.val} #{solve_arithmetic(node.right)}")
end
def is_numeric?(string)
true if Float(string) rescue false
end
# node = [*, +, +, 3, 4, 5, 6]... | true |
e83f90824c04f0fc56c8d30ec04f14b8853afe0d | Ruby | brentd/nstance | /lib/nstance/drivers/docker_api/excon/socket_hijack.rb | UTF-8 | 1,214 | 2.53125 | 3 | [
"MIT"
] | permissive | module Nstance
module Drivers
module DockerAPI
module Excon
# This middleware allows us to hijack a HTTP request's socket so we can
# read and write to it directly.
class SocketHijack < ::Excon::Middleware::Base
def response_call(datum)
return @stack.response_ca... | true |
6434c8c91e42b16de700101470778a39a01c4f48 | Ruby | xeviknal/iot-control-plane | /user.rb | UTF-8 | 481 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | class User
attr_accessor :id, :rides_count, :first_ride_at, :last_ride_at, :current_ride_start_at, :current_ride_end_at
def initialize(id)
self.id = id
self.rides_count = 0
end
def start_ride
self.first_ride_at = Time.now unless self.first_ride_at?
self.last_ride_at = Time.now
self.current... | true |
045e7d068cbccaeb3c82d05d61cec511aa0aad9a | Ruby | octonion/volleyball-m | /ncaa_pbp/scrapers_tsv/ncaa_play_by_play.rb | UTF-8 | 3,189 | 2.546875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'csv'
require 'mechanize'
require 'nokogiri'
require 'open-uri'
require 'cgi'
base_sleep = 0
sleep_increment = 3
retries = 4
agent = Mechanize.new{ |agent| agent.history.max_size=0 }
agent.user_agent = 'Mozilla/5.0'
base = "http://stats.ncaa.org/game/play_by_play"
periods = CSV.open("t... | true |
35b9c47e8bfec204015a6c1740e6ef2295a8bfa9 | Ruby | ahorner/advent-of-code | /spec/2016/09_spec.rb | UTF-8 | 1,077 | 2.640625 | 3 | [] | no_license | require "spec_helper"
RSpec.describe "Day 9: Explosives in Cyberspace" do
let(:runner) { Runner.new("2016/09") }
describe "Part One" do
it "computes decompressed string lengths" do
expect(runner.execute!("ADVENT", part: 1)).to eq(6)
expect(runner.execute!("A(1x5)BC", part: 1)).to eq(7)
expec... | true |
5f71751df07567d7f6f6c1f9daae5ebcc399451b | Ruby | alisonlutz28/tts_programs | /rails/quizapp/app/helpers/application_helper.rb | UTF-8 | 386 | 2.640625 | 3 | [] | no_license | module ApplicationHelper
def check_answer(answer)
citylist = ["Atlanta", "Asheville", "Charlotte", "Raleigh"]
correct = false
citylist.each do |c|
if answer == c
correct = true
end
end
return correct
end
def check_for_dup(answer,database)
is_dup = false
database.each do |d|
if answer ==... | true |
a5054e5e29d99164d8367b6810af0a87b0b7c4c3 | Ruby | twill14/launchschool-OOP-Lessons | /OOP-Lesson-3-Excercises/variable_scopre.rb | UTF-8 | 1,279 | 3.8125 | 4 | [] | no_license | # class Person
# def initialize(n)
# @name = n
# end
# def get_name
# @name
# end
# end
# bob = Person.new('bob')
# bob.get_name
# class Person
# @@total_peeps = 0
# def self.total_peeps
# @@total_peeps
# end
# def intitialize
# @@total_peeps += 1
# end
# def total_peeps
# ... | true |
91e05e4249276ba7164c23eea790bfbad96d87b8 | Ruby | Lyanov/lb7 | /Part2/lr7_2.rb | UTF-8 | 295 | 3.359375 | 3 | [] | no_license | # Word class
class Word
def initialize(arg)
@word = arg
end
def length
@word.length
end
def str
@word
end
end
# Word2 class
class Word2 < Word
def initialize(arg)
@word = arg
@length = @word.length
end
attr_reader :length
def str
@word
end
end
| true |
dbb1a437393a5b61d639ccd2e60492f7f3d207ad | Ruby | solyarisoftware/blomming_api | /examples/endpoints/buy/items_search.rb | UTF-8 | 818 | 2.796875 | 3 | [
"MIT"
] | permissive | #!/bin/env ruby
# encoding: utf-8
require 'blomming_api'
if ARGV[0].nil? || ARGV[1].nil?
puts " goal: test endpoint: items_search"
puts " usage: #{$0} <config_file.yml> <keyword>"
puts "example: ruby #{$0} $CONFIG \"ambient music FLAC\""
exit
end
config_file, keyword = ARGV
c = BlommingApi::... | true |
bd4ec9ffb1049ffabb9e23cfe3c836f72bfc39da | Ruby | akxcv/qonfig | /lib/qonfig/command_set.rb | UTF-8 | 1,357 | 2.671875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Qonfig
# @api private
# @since 0.1.0
class CommandSet
# @return [Array<Qonfig::Commands::Base>]
#
# @api private
# @since 0.1.0
attr_reader :commands
# @api private
# @since 0.1.0
def initialize
@commands = []
@access_lock = Mutex.... | true |
f4318a09f034e0f0e8feb53cc8f0e970a4de25e8 | Ruby | JT1989/ruby-exercises | /exercises/find_even.rb | UTF-8 | 2,035 | 4.53125 | 5 | [
"MIT"
] | permissive | # Method name: find_even
# Inputs: An array of integers
# Returns: An array of all the even integers appearing from the input array
# If NO even integers are found, return an empty array
# Prints: Nothing
# For example,
#
# find_even([1,2,3,4,5,6]) == [2,4,6]
# find_even([10,10,10,11,11,11... | true |
a8f1a13bde21bbdef0b8051c7e6ab0737efcf27f | Ruby | IuliiaKot/Checkers | /piece.rb | UTF-8 | 2,549 | 3.59375 | 4 | [] | no_license | class Piece
LEGAL_MOVE = [[-1, 1],[-1, -1],[1, 1],[1, -1]]
attr_accessor :board, :pos, :color
def initialize(board, color, pos, king = false)
@board = board
@color = color
@pos = pos
@king = king
end
def perform_slide(to_pos)
current_x = pos[0]
current_y = pos[1]
return false u... | true |
0b27629eafe61618a8c2a6e7407005f45d6e14ec | Ruby | yiivan/Quiz-1 | /Q10.rb | UTF-8 | 392 | 3.375 | 3 | [] | no_license | module HelperMethods
def testing(class_name)
puts "Yeah! This works for #{class_name}!"
end
end
class MyInclude
include HelperMethods
end
class MyExtend
extend HelperMethods
end
#These will work:
inc = MyInclude.new
inc.testing("MyInclude")
MyExtend.testing("MyExtend")
# These will not work:
# MyInclud... | true |
f2d4b7bb8735c107249c43574f247a85fde0c8ec | Ruby | EmilZacharczuk/Week_01_weekend_homework | /pet_shop.rb | UTF-8 | 2,264 | 3.4375 | 3 | [] | no_license | def pet_shop_name(shop)
return shop[:name]
end
def total_cash(shop)
return shop[:admin][:total_cash]
end
def add_or_remove_cash(shop, amount)
return shop[:admin][:total_cash] += amount
return shop[:admin][:total_cash] -= amount
end
def pets_sold(shop)
return shop[:admin][:pets_sold]
end
def increase_pets_... | true |
7a8cfb33bcf90b96af5312a8263db9b978b459ff | Ruby | zmoazeni/sqew | /spec/support/jobs.rb | UTF-8 | 330 | 2.578125 | 3 | [
"MIT"
] | permissive | class TestJob
@testing = 0
class << self
def perform(arg)
@testing = arg
end
def testing
@testing
end
def reset
@testing = 0
end
end
end
class FailJob
def self.perform(*)
raise "failed in FailJob"
end
end
class SlowJob
def self.perform(secs)
sleep secs
... | true |
d28b6bef2906096676e156fef92bdd9bb56a462b | Ruby | fraser/pivotal-db | /lib/pivotal_db/cli.rb | UTF-8 | 1,678 | 2.609375 | 3 | [] | no_license | require 'thor'
module PivotalDb
class CLI < Thor
desc "stats", "stats"
def stats
tracker = Tracker.new(Settings[Settings[:project]])
puts "Projects: #{Project.all.count}"
puts "Stories: #{Story.all.count}"
puts "Notes: #{Note.all.count}"
end
desc "pull", "pull all stories fr... | true |
83fcc89c46fa09f25353422a9276f3d2c8a7cc77 | Ruby | counterbeing/mars-rover-challenge | /specs/plateau_spec.rb | UTF-8 | 713 | 3.375 | 3 | [] | no_license | require './classes/plateau.rb'
describe Plateau do
let(:plateau) { Plateau.new("5 5") }
it "can be initialized" do
expect(plateau.x).to eq(5)
expect(plateau.y).to eq(5)
end
describe "checks for solid ground" do
it "returns false when the point is not on the plateau" do
ground = plateau.che... | true |
badabaf310df4620ced49ad223a7f68ec293e5ef | Ruby | icbd/focus_actor | /spec/user.rb | UTF-8 | 350 | 2.90625 | 3 | [
"MIT"
] | permissive | require_relative '../lib/focus_actor/async'
require_relative '../lib/focus_actor/future'
class User
include FocusActor::Async
include FocusActor::Future
attr_reader :name, :age
def initialize(name)
@name = name
@age = 0
end
def grow(cost = 0.1)
sleep cost
@age += 1
end
end
CASE_TIMES ... | true |
0bdc9fadcbc10a83d35ce45fe9391685f32f7b23 | Ruby | arunthampi/rdiff_match_patch | /spec/match/include_spec.rb | UTF-8 | 613 | 2.53125 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/../spec_helper.rb'
describe "Including the RDiffMatchPatch module as part of a class" do
before(:each) do
class String
include RDiffMatchPatch::Match
end
end
it "should add fuzzy_match as an instance method of that class" do
String.new.methods.include?('fuz... | true |
5766e489becd56c8cef05e0ddbf1eb31f45c5e01 | Ruby | Josephtsessions/mixtapes | /models/song.rb | UTF-8 | 379 | 2.609375 | 3 | [] | no_license | require_relative './application_model'
class Song < ApplicationModel
attr_reader :id, :artist, :title
def initialize(attributes)
@id = attributes["id"]
@artist = attributes["artist"]
@title = attributes["title"]
end
def to_json(options = {})
{id: id, artist: artist, title: title}
end
... | true |
f3a7d2f50c480033bad4d927139f66b5fc4f9ffc | Ruby | code4tots/aa | /sql/UrlShortener/app/models/shortened_url.rb | UTF-8 | 1,262 | 2.59375 | 3 | [] | no_license | class ShortenedUrl < ActiveRecord::Base
validates :long_url, presence: true, uniqueness: true
validates :short_url, presence: true, uniqueness: true
validates :submitter_id, presence: true
belongs_to(:submitter,
foreign_key: :submitter_id,
class_name: 'User')
has_many(:visits,
foreign_key: :... | true |
702d8ffc44cb9f024b782a996002b4d99624b9d8 | Ruby | axenictech/ruby-programming | /purva/foreach/for.rb | UTF-8 | 36 | 2.765625 | 3 | [] | no_license | a=[1,2,3,4,5]
for i in a
puts i
end | true |
b587ed123d40036cbb5e8d4f9efad6259447ee23 | Ruby | sinatra/sinatra | /test/result_test.rb | UTF-8 | 2,085 | 2.734375 | 3 | [
"MIT"
] | permissive | require_relative 'test_helper'
class ThirdPartyError < RuntimeError
def http_status; 400 end
end
class ResultTest < Minitest::Test
it "sets response.body when result is a String" do
mock_app { get('/') { 'Hello World' } }
get '/'
assert ok?
assert_equal 'Hello World', body
end
it "sets respo... | true |
14c87c40e4cfcb195d6731be52df9b59a5c28769 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/1130/source/6769.rb | UTF-8 | 398 | 4.03125 | 4 | [] | no_license | #Part 3: anagrams
def combine_anagrams(words)
results = Hash.new{|h, k| h[k] = []}
words.each do |word|
results[word.downcase.chars.sort(&:casecmp).join] << word
end
return results.values.sort
end
puts combine_anagrams(['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams', 'scream']).to_s
puts com... | true |
f45c85617de23166d249c3099fcb0026703eccf0 | Ruby | chaoshades/rmvx-ebjb-core | /src/User Controls/UCIcon.rb | UTF-8 | 2,999 | 2.765625 | 3 | [
"MIT"
] | permissive | #==============================================================================
# ** UCIcon
#------------------------------------------------------------------------------
# Represents an Icon user control on a window
#==============================================================================
class UCIcon < UserC... | true |
8df3c8fdd910d93bed3a9da2d9e31dcb41e5a90e | Ruby | mrlhumphreys/just_shogi | /test/just_shogi/square_test.rb | UTF-8 | 1,799 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require 'minitest/spec'
require 'just_shogi/square'
require 'just_shogi/pieces/fuhyou'
describe JustShogi::Square do
describe '#initialize' do
it 'initializes the attributes' do
square = JustShogi::Square.new(id: '55', x: 4, y: 4, piece: { id: 1, player_number: 2, type: 'fuhyou' ... | true |
4add3795bf86e433a1e105443c3b451d3074c3c0 | Ruby | D3nX/space_race | /rectangle.rb | UTF-8 | 650 | 3.203125 | 3 | [] | no_license | class Rectangle
attr_accessor :x, :y, :width, :height
def initialize(x, y, width, height)
@x = x
@y = y
@width = width
@height = height
end
def draw
Gosu.draw_rect(
@x,
@y,
@width,
@height,
Color::WHITE,
500
)
end
def collides?(rectang... | true |
1a2cee5c301c78e071c2e437c9d82917d4d3c75a | Ruby | weyewe/goguard | /app/models/lead.rb | UTF-8 | 2,117 | 2.90625 | 3 | [] | no_license | require 'telegram/bot'
class Lead < ActiveRecord::Base
validate :phone_must_be_present , :valid_selected_product
def phone_must_be_present
if not phone_number.present?
self.errors.add(:phone_number, "Nomor telpon harus ada")
return self
end
end
def val... | true |
25600230c0b88cf8f9e7c0db2f386f42cc127d0f | Ruby | Dm1trySt/viselitsa | /viselitsa.rb | UTF-8 | 1,200 | 2.59375 | 3 | [] | no_license | #(c) goodprogrammer.ru
# Проверяем на какой ОС работаем, если windows - задаем кодировки
if (Gem.win_platform?)
Encoding.default_external = Encoding.find(Encoding.locale_charmap)
Encoding.default_internal = __ENCODING__
[STDIN, STDOUT].each do
io.set_encoding(Encoding.default_external, Encoding.default_inte... | true |
2ceb3de07970250b0fa392cca455b2a6066ef9b9 | Ruby | Soulou/aoc-2020 | /20201204/main-1.rb | UTF-8 | 1,409 | 2.984375 | 3 | [] | no_license | #!/usr/bin/env ruby
# byr (Birth Year)
# iyr (Issue Year)
# eyr (Expiration Year)
# hgt (Height)
# hcl (Hair Color)
# ecl (Eye Color)
# pid (Passport ID)
# cid (Country ID)
validations = {
"byr" => lambda do |v| v && v.to_i >= 1920 && v.to_i <= 2002 end,
"iyr" => lambda do |v| v && v.to_i >= 2010 && v.to_i <= 2020... | true |
add21249561c74f9ce20853aa5a4a18184c92b59 | Ruby | HunterMeyer/Servitron | /lib/status_transition.rb | UTF-8 | 526 | 2.578125 | 3 | [] | no_license | module StatusTransition
module Status
ACTIVE = 'Active'.freeze
DISABLED = 'Disabled'.freeze
ERASED = 'Erased'.freeze
end
def self.settings_for(*statuses)
return settings unless statuses.present?
settings.select { |status, _| statuses.include? status }
end
def self.settings
{
... | true |
884d385d7269006f61c00a58e6a272e7b6390b4e | Ruby | rsamp/app-academy-exercises-and-projects | /Week 1/Minesweeper/tile.rb | UTF-8 | 1,474 | 3.5625 | 4 | [] | no_license | require 'byebug'
require_relative 'board'
class Tile
attr_reader :pos, :board
attr_accessor :value, :revealed
POTENTIAL_NEIGHBORS_DIFF = [[0,1],
[0,-1],
[-1,0],
[1,0],
[1,1],
... | true |
87235e74d1a529ae88aa569d1197291ef387ee47 | Ruby | Andrewsh86/exercism | /ruby/sieve/sieve.rb | UTF-8 | 326 | 3.484375 | 3 | [] | no_license | class Sieve
def initialize num
@num = num
end
def primes
return [] if @num < 2
list = (2..@num).to_a
prime_arr = []
until list.empty? do
prime_arr << list.shift
list.map! do |x|
(x % prime_arr.last).zero? ? nil : x
end
list.compact!
end
prime_arr
end... | true |
77ace3902abede2c0f6980a051a4f962093a3505 | Ruby | flying-sphinx/plextail | /lib/plextail/line.rb | UTF-8 | 1,266 | 2.828125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
class Plextail::Line
DEFAULTS = {
:version => '<134>1',
:hostname => `hostname`.strip,
:message_id => '- -'
}
attr_accessor :file, :raw, :token, :version, :timestamp, :hostname,
:process_id, :message_id, :message
def initialize(file, raw, &block)
@file, @raw = file, ... | true |
ab4e3883f888fce5719c590bf7e45ff1b1555cfb | Ruby | taw/rlisp | /tests/test_tokenizer.rb | UTF-8 | 2,057 | 2.90625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require "minitest/autorun"
require 'rlisp'
class Test_Tokenizer < Minitest::Test
def test_tokenizer
code = '2.3 4 , ,@ ` ( ) [ ] foo bar x-y u19 #t #f bah "foo" "bar #{ 3 }" "#{1}" [] []= "#{a} #{b} #{c}"'
rg = RLispGrammar.new(code)
assert_equal([:expr, 2.3, 1, 0], rg.get_token)
... | true |
058ee31fee426d50c577b2814dd16373357d6c18 | Ruby | AtmaVichara/ruby_blockchain | /lib/transaction.rb | UTF-8 | 893 | 3.203125 | 3 | [] | no_license | require 'digest'
class Transaction
attr_reader :from, :to, :amount
def initialize(from, to, amount, priv_key)
@from = from # is a public key
@to = to # is a public key
@amount = amount
@signature = PKI.sign(message, priv_key) # provide the signature to verify that you are who you are with you... | true |
efb5c7e416d59414d3922cf7ed6b2c291b44d6d4 | Ruby | ianfleeton/zmey | /lib/ip_address.rb | UTF-8 | 612 | 3.109375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class IPAddress
attr_reader :value
def initialize(value)
@value = value
end
def to_s
@value
end
# Returns a new IP Address that has been anonymized by setting the latter
# portion to zero.
def anonymize
ipv4 = (m = value.match(/\d+\.\d+\.\d+\.\d+$/)) ? m[0] ... | true |
342477406b81635a5df2999516c2c86151cc037f | Ruby | ranle/itunes_search | /lib/itunes_search/client.rb | UTF-8 | 859 | 2.59375 | 3 | [
"MIT"
] | permissive | module ItunesSearch
class Client
MAX_TRIES = 5
def initialize(proxies = nil, username = nil, password = nil)
@proxies = proxies
@username = username
@password = password
end
def get_html(url)
response = nil
tries = 0
begin
if @proxies
proxy = "h... | true |
e3d601c82bc9ce6abcb1670d94e4b822f6c4fc39 | Ruby | nrice95/aA-homeworks | /W2D5/lru_cache.rb | UTF-8 | 615 | 3.484375 | 3 | [] | no_license | class LRUCache
attr_reader :size
attr_accessor :cache
def initialize(size)
@size = size
@cache = []
end
def count
# returns number of elements currently in cache
self.cache.count
end
def add(el)
idx = self.cache.index(el)
unless idx.nil?
self.ca... | true |
4a09c14e25867397ba1de91c00340073e7cd0ad3 | Ruby | lorrocha/senshi-sim | /lib/gameplay.rb | UTF-8 | 460 | 3.265625 | 3 | [] | no_license | class Gameplay
attr_accessor :usa
def initialize(player)
@usa = player
@place = Locations.new
end
def randomizer
rand(11)
end
def all_stats
@usa.all_stats
end
def stat_check(stat, goal)
@usa.send(stat.to_sym) + randomizer >= goal
end
def update_stat(stat, num)
val = @usa.send("#{stat}") + num... | true |
9ff8a3d56b0ecd552da957853cd4765cf3134525 | Ruby | Rsaphra/badges-and-schedules-nyc-web-051319 | /conference_badges.rb | UTF-8 | 701 | 4 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
"Hello, my name is #{name}."
end
def room_maker(name, counter)
"Hello, #{name}! You'll be assigned to room #{counter}!"
end
def assign_rooms(names)
room_list = []
counter = 1
names.each do |name|
room_list.push(room_maker(name, counter))
counter += 1
... | true |
49c3dab9101064d0e5974beaadf06e53e7746329 | Ruby | shostakovich/Todo-Void | /features/step-definitions/status_changes_steps.rb | UTF-8 | 1,195 | 2.546875 | 3 | [
"MIT"
] | permissive | When /^I provide the option "(.*?)" plus the hash of a todo$/ do |option|
TodoVoid.new([option, "cab959"]).execute
end
When /^I provide the opion "(.*?)" plus the partial hash of a todo$/ do |option|
TodoVoid.new([option, "ca"]).execute
end
When /I provide the option "(.*?)" and a conflicting partial hash/ do |op... | true |
586b5511b3449f61ac399269e2db4c0df60634e1 | Ruby | mlyubarskyy/leetcode | /350_intersection_of_two_array2.rb | UTF-8 | 321 | 3.296875 | 3 | [] | no_license | # @param {Integer[]} nums1
# @param {Integer[]} nums2
# @return {Integer[]}
def intersect(nums1, nums2)
map = {}
(0...nums1.size).each do |i|
map[nums1[i]] ||= 0
map[nums1[i]] += 1
end
res = []
nums2.each do |el|
if map[el] && map[el] > 0
res << el
map[el] -= 1
end
end
res
end... | true |
cbc7a12c089730c2eee58a1d331d1a8eba933f25 | Ruby | sanzstv/tcbot | /twitterbot.rb | UTF-8 | 1,083 | 2.515625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'Twitter'
require_relative 'queries'
require_relative 'cache'
#` this bot (still in progress) is meant to monitor crime/mystery related topics on The Twitter
# caccepts optional list of queries as command line argument in the format:
# ruby twitterbot.rb "query 1" "query 2" ...
# if n... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.