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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
d18f8130f703f88faf84e6e5da25abf89bfc12c1 | Ruby | codyloyd/cli_chess | /game/Player.rb | UTF-8 | 552 | 3.859375 | 4 | [] | no_license | require "./game/GameBoard"
class Player
attr_accessor :name, :color
def initialize(name, color)
@name = name
@color = color
end
def input_to_array(input_string)
#this method will convert the user's string (example a1,b3)
#into an appropriate input for GameBoard.move_piece ([0,1],[1,3])
array = input_str... | true |
2570419e1e4c6a16b0246869b5234a0e69fecade | Ruby | zeisler/attr_permit | /lib/attr_permit.rb | UTF-8 | 5,092 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'active_support/core_ext/big_decimal'
class AttrPermit
class << self
def permissible_methods
@permissible_methods ||= []
end
def mapped_methods
@mapped_methods ||= []
end
def attr_permit(*permissible_methods)
self.permissible_methods.concat [*permissible_methods, *ge... | true |
838d0afdbe160a519381c9e28d6ef566a6ce35a6 | Ruby | seishingithub/api_spike | /weather_data.rb | UTF-8 | 1,415 | 3.640625 | 4 | [] | no_license | require 'faraday'
require 'json'
require 'pp'
require 'date'
require 'pry'
response = Faraday.get 'http://api.openweathermap.org/data/2.5/weather?q=Boulder,%20co'
response2 = Faraday.get 'http://api.openweathermap.org/data/2.5/forecast/daily?q=Boulder,%20co&units=imperial'
JSON.parse(response.body)
JSON.parse(respons... | true |
b2fe5427707362df1156dd32010aa37f01f3840a | Ruby | MiriamGomez2/ejerciciosRuby | /Persona.rb | UTF-8 | 865 | 3.484375 | 3 | [] | no_license | #Miriam Gomez
class Persona
def initialize (nombre,genero,edad)
@miNombre = nombre
@miGenero = genero
@miEdad = edad
end
def setNombre(nombre)
@miNombre = nombre
end
def getNombre
return @miNombre
end
def setGenero(genero)
@miGenero = genero
end
... | true |
8a00e6338e4b99fbd909a7a90a82765da0ae451a | Ruby | leifg/riese | /test/test_riese.rb | UTF-8 | 4,094 | 3.3125 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require 'riese'
require 'turn'
class TestRiese < MiniTest::Unit::TestCase
# #initialize
def test_that_assignment_is_stored_correctly
subject = Riese::Fraction.new 1, 2
assert_equal 1, subject.numerator
assert_equal 2, subject.denominator
end
def test_that_fraction_is_r... | true |
53abb9aedff2e81c3c001331f1537f74aec9612d | Ruby | lizamcpherson/Liza.McPherson.lizamcpherson01 | /exercises/d3/recipes.rb | UTF-8 | 832 | 3.203125 | 3 | [] | no_license | hash =
{
pancakes:
{
description: "like toast but better",
ingredients: ["flour", "eggs", "butter"],
steps: ["add mix", "stir", "cook"]
},
omelettes:
{
description: "eggs with yummy stuff",
ingredients: ["eggs", "bacon", "cheese"],
steps: ["mix eggs", "add ingredients", "cook"]
},
fruit_smoot... | true |
2db74a86c484491f6927d0dc08a6c584bf2795de | Ruby | Clearcover/rdkafka-ruby | /lib/rdkafka/producer/delivery_handle.rb | UTF-8 | 2,110 | 2.765625 | 3 | [
"MIT"
] | permissive | module Rdkafka
class Producer
# Handle to wait for a delivery report which is returned when
# producing a message.
class DeliveryHandle < FFI::Struct
layout :pending, :bool,
:response, :int,
:partition, :int,
:offset, :int64
REGISTRY = {}
def self... | true |
956de84b2f55066263852df9f3077aa83636e9cd | Ruby | alanrubin/top-parsers-WCFG-MySQL | /src/probability_normalizer.rb | UTF-8 | 145 | 2.515625 | 3 | [] | no_license | class ProbabilityNormalizer
def normalize(weight)
weight == 0.0 ? -9.223372036854776E18 : -(Math.log(weight)*10).round.to_i
end
end | true |
10694b4f09a04a9a4abe86e118cf93b2e5ed489b | Ruby | maximkoo/ruby-repo | /Noko/readnoko.rb | UTF-8 | 798 | 2.65625 | 3 | [] | no_license | #
# http://www.nokogiri.org/tutorials/parsing_an_html_xml_document.html
#
require 'nokogiri'
#Создаем XML-ресурс для Nokogiri
a=''
a<<File.open('1.xml').read;
b=Nokogiri::XML(a)
#или вот так
doc = File.open("1.xml") { |f| Nokogiri::XML(f) }
puts b.xpath('//value') #вроде оператора extract в PLSQL, возвр... | true |
7aed5ec90444591d998bafeef48713bc0293b7c7 | Ruby | jasoares/euro2012_score_simulator | /app/models/team.rb | UTF-8 | 2,192 | 2.734375 | 3 | [] | no_license | class Team < ActiveRecord::Base
belongs_to :group
has_many :home_scores,
:class_name => "Score",
:foreign_key => "home_team_id"
has_many :away_scores,
:class_name => "Score",
:foreign_key => "away_team_id"
attr_accessible :name, :group
UEFA_RANKING = [
"England... | true |
25fa5956b9b9c85284a8fc34f9fcd713e0a2c6eb | Ruby | rorymckinley/rubyfuza2013 | /test_threads.rb | UTF-8 | 347 | 2.8125 | 3 | [] | no_license | require 'net/http'
require 'uri'
t = Time.now
uri = URI.parse("http://google.com/")
Net::HTTP.get_response(uri)
puts "Test: #{Time.now - t}"
80.times do |i|
Thread.new {response = Net::HTTP.get_response(uri); print "Thread no #{i} got #{response.code}\n" }
end
Thread.list.each { |t| t.join unless t == Thread.cu... | true |
5f88c404d8e306b7274c0a21620f2541bfc3a543 | Ruby | ValentinaPanic/square_array-onl01-seng-pt-050420 | /square_array.rb | UTF-8 | 189 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(arrays)
new_numbers = []
arrays.each do |x|
new_numbers.push (x * x)
end
new_numbers
end
#def square_array(new_numbers)
# new_numbers. do {|x| x * x }
# end
#end
| true |
2a865fc97e4bc62ec8e59c01d4505d96c1d6473c | Ruby | astrails/debitcredit | /app/models/debitcredit/item.rb | UTF-8 | 576 | 2.578125 | 3 | [
"MIT"
] | permissive | module Debitcredit
class Item < ApplicationRecord
belongs_to :entry
belongs_to :account
validates :entry, :account, presence: true
validates :amount, numericality: {greater_than_or_equal_to: 0}
scope :debit, ->{where(debit: true)}
scope :credit, ->{where(debit: false)}
def credit?
... | true |
fe03f2a15bca1e9b8f71c3e3f5ed3c437939e488 | Ruby | sauloperez/sensors-app | /db/seeds.rb | UTF-8 | 648 | 2.625 | 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 |
96ee8d27acd7a92bc8d87054cf813bc0ceedf29b | Ruby | Eskat0n/GraduationWork | /code/lib/extensibility/components_base/test_runner_component.rb | UTF-8 | 686 | 2.796875 | 3 | [
"Unlicense",
"MIT"
] | permissive | require_relative 'component.rb'
class TestRunnerComponent < Component
def self.base_type
'TestRunner'
end
def run_tests
raise NotImplementedError, "Run tests method must be implemented by #{type}"
end
end
class TestResult
attr_accessor :failed, :tests, :time, :target
attr_reader :errors
def in... | true |
9a312b7413347333cc7da3f395d8e3d632c67a61 | Ruby | jonasmedcapital/clinics | /app/repositories/operations/products/clinics/taker_repository.rb | UTF-8 | 1,351 | 2.578125 | 3 | [] | no_license | class Operations::Products::Clinics::TakerRepository < Base
def self.build(attrs)
obj = entity.new
obj.clinic_id = attrs["clinic_id"]
obj.taker_id = attrs["taker_id"]
obj.taker_type = TAKER_TYPE[attrs["taker_type"]]
obj.taker_number = attrs["taker_number"]
obj.taker_name = attrs["taker_... | true |
1ea555f3a2659b60726f42a4e6565b5d08cea77e | Ruby | elpadrinoIV/blackjack | /test/test_jugador_tramposo.rb | UTF-8 | 4,008 | 2.734375 | 3 | [] | no_license | require File.dirname(__FILE__) + '/helper.rb'
require 'jugador_tramposo'
require 'game'
class TestJugadorTramposo < Test::Unit::TestCase
def setup
@game = Game.new
@jugador = JugadorTramposo.new(1000, @game)
@game.agregar_jugador(@jugador)
end
def teardown
# nada...
end
def test_debe_pedir_si_no_se... | true |
4349347c4beb1e677a9a33fc7d6a945f1086164c | Ruby | lsamano/collections_practice-dumbo-web-121018 | /collections_practice.rb | UTF-8 | 653 | 3.90625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
array.sort
end
def sort_array_desc(array)
array.sort do |a, b|
b <=> a
end
end
def sort_array_char_count(array)
array.sort_by{|word| word.length}
end
def swap_elements(array)
array[1],array[2] = array[2],array[1]
array
end
def reverse_array(array)
array.reverse
end
def k... | true |
753675d3a9faf7ed77ab36fb91e1ed237f41835d | Ruby | Telixia/leetcode-3 | /Medium/0831-Masking Personal Information/Solution.rb | UTF-8 | 434 | 3.09375 | 3 | [] | no_license | # @param {String} s
# @return {String}
def mask_pii(s)
s.include?('@') ? mask_email(s) : mask_phone(s)
end
# @param {String} s
# @return {String}
def mask_email(s)
first, remain = s.downcase.split('@')
first[0] + '*****' + first[-1] + '@' + remain
end
# @param {String} s
# @return {String}
def mask_phone(s)
... | true |
0b4d4a09110304cf47ab7a0cf759cc7138a5128f | Ruby | rails/rails | /activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb | UTF-8 | 1,615 | 2.546875 | 3 | [
"MIT",
"Ruby"
] | permissive | # frozen_string_literal: true
require "sucker_punch"
module ActiveJob
module QueueAdapters
# = Sucker Punch adapter for Active Job
#
# Sucker Punch is a single-process Ruby asynchronous processing library.
# This reduces the cost of hosting on a service like Heroku along
# with the memory footpr... | true |
37ab67e8ad39fb1935033ed81f89f01e3e20a40f | Ruby | burnt43/active-record-bulk-ops | /lib/active-record-bulk-ops.rb | UTF-8 | 7,707 | 2.703125 | 3 | [] | no_license | module ActiveRecord
module BulkOps
class << self
def comparable_ruby_version
@comparable_ruby_version ||= RUBY_VERSION.split('.').map{|x| sprintf("%02d", x)}.join
end
end
module Insertion
# NOTE: The constructor takes a collection of records that have not yet
# been save... | true |
b37858af1772443b53bba673bf1acffa480f8c85 | Ruby | FionaDL/gif-upload | /app/models/gif.rb | UTF-8 | 657 | 2.71875 | 3 | [] | no_license | class Gif < ApplicationRecord
has_one_attached :file
validates :file, size: { less_than: 10.megabytes , message: 'is not given between size' }
has_many :rankings
has_many :labels, through: :rankings
def labels_string=(value)
if value == ""
return ""
else
result = []
labels = valu... | true |
dd831df603b6b323b8d17000332726620556b480 | Ruby | sgibbons/partially | /partially.rb | UTF-8 | 679 | 3.09375 | 3 | [
"MIT"
] | permissive |
class Proc
NOBIND = (MATCH_ONE, MATCH_ALL = :_, :*)
def partially(*args_now)
uncurried = self
lambda do |*args_later|
arity = args_now.include?(MATCH_ALL) ? (args_now.size + args_later.size - 1) : args_now.size
evaluated = uncurried.curry(arity)
args_now.each do |arg|
evaluated... | true |
18fe12a9764509f0ba8c7d850074507d81ba5027 | Ruby | rterrabh/rdf | /dataset/rails/activesupport/lib/active_support/core_ext/integer/time.rb | UTF-8 | 319 | 2.765625 | 3 | [
"MIT",
"Ruby"
] | permissive | require 'active_support/duration'
require 'active_support/core_ext/numeric/time'
class Integer
def months
ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
end
alias :month :months
def years
ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
end
alias :year :years
end
| true |
ba582a1abe440cccb5c42f115d3b78af870779a4 | Ruby | joshwalsh/Permutations | /permutations.rb | UTF-8 | 1,458 | 3.859375 | 4 | [] | no_license | testNumber = "321"
class Permutations
def initialize(number_to_permutate)
@number_to_permutate = number_to_permutate
end
def possibilities
low_end = find_lowest_possible_value
high_end = find_highest_possible_value
matches = []
(low_end..high_end).each do |value|
if matches? value
... | true |
2663373a33a8f7aab614e8c7dc4a1468c6aaa402 | Ruby | CassiaCaris/calculadora_ruby | /calculadora_basica.rb | UTF-8 | 738 | 4.5 | 4 | [] | no_license | puts "Calculadora"
puts "-----------"
puts "Escolha a operacao!"
puts "1 Adicao"
puts "2 Subtracao"
puts "3 Divisao"
puts "4 Multiplicacao"
puts "Digite um numero?"
n1 = gets.chomp().to_f
puts "Digite o Numero da Operacao escolhida?"
operacao = gets.chomp().to_i
puts "Digite o segundo numero?"
n2 = ... | true |
46bed5e2c7819435a7dfeb2242c34a8182e3fea4 | Ruby | Clark-W-Griswold/vets-api | /lib/common/models/concerns/active_record_cache_aside.rb | UTF-8 | 2,586 | 2.84375 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | # frozen_string_literal: true
module Common
# Cache Aside pattern for caching an ActiveRecord::Base db record in redis.
#
# Requires the model mixing it in to:
# - be an ActiveRecord::Base class
# - implement a #cache? method
#
# Expects the model mixing it in to:
# - set the config by calling redi... | true |
9e7ad4e0ff0a972ebab363ace6dc8cc57a5d0ac7 | Ruby | ali-mohamed/web-parser | /app/models/parser.rb | UTF-8 | 753 | 2.78125 | 3 | [] | no_license | require 'readability'
require 'open-uri'
require 'json'
class Parser
def self.parse_div_contents_into_array(content)
body = []
content.children.each do |f|
if f.name == 'div'
inner_content = parse_div_contents_into_array(f)
else
inner_content = f.inner_html
end
body <<... | true |
76d3f3140c0bddec922da57293da2c4ba73b039e | Ruby | nitinsavant/ruby_exercises | /ruby_challenges/octal.rb | UTF-8 | 344 | 3.453125 | 3 | [] | no_license | class Octal
attr_reader :octal
def initialize(digits)
@octal = test_valid_input(digits)
end
def to_decimal
decimal = 0
1.upto(octal.length) do |num|
decimal += (octal[-num].to_i * 8 ** (num-1))
end
decimal
end
private
def test_valid_input(digits)
digits =~ /[a-zA-Z8-9]/ ?... | true |
5d894a502035df700cfea1050fa1d1dd2c0741bd | Ruby | zhujiale2/HITS-Project | /patent-app/lib/assets/patents/cites.rb | UTF-8 | 478 | 2.796875 | 3 | [] | no_license | cite = Hash.new([])
IO.foreach("cite75_99.csv"){|cit|
a = cit.to_i
b = cit[8..100].to_i
cite[a] = cite[a]+[b]
}
puts "loaded"
for i in 11..69
pats = Array.new
File.open("pat#{i}.csv", "r") do |patFile|
pats = patFile.readlines()
end
citeFile = File.new("cite#{i}.txt", "a")
for j in 0..pats.size-1
code = pa... | true |
7252da5e1707d982e3202474f92a1956dc1fbaf1 | Ruby | soutaro/jack_and_the_elastic_beanstalk | /lib/jack_and_the_elastic_beanstalk/runner.rb | UTF-8 | 1,580 | 2.59375 | 3 | [] | no_license | module JackAndTheElasticBeanstalk
class Runner
attr_reader :stdin
attr_reader :stdout
attr_reader :stderr
attr_reader :logger
def initialize(stdin:, stdout:, stderr:, logger:)
@stdin = stdin
@stdout = stdout
@stderr = stderr
@paths = [Pathname.pwd]
@logger = logger
... | true |
1d6c780558c6e073c7c441af5694b645bf5f82c8 | Ruby | lucignolo/events1617 | /provaOttobre0.rb | UTF-8 | 1,254 | 2.75 | 3 | [] | no_license | #!/usr/local/bin/ruby
base0 = "@book.update_attribute(XXX,YYY)"
provaHash = Hash(titolo: Hash(ok: ["titolononbidone","titoloqualunque"], nok: ["titolobidone"]),
copie: Hash(ok: [1, 2, 50] , nok: [0, -1]),
deposito: Hash(ok: [false] ... | true |
85c50b603b8e93de11e33e3cbd8e314bfb3d2de1 | Ruby | strychemi/assignment_file_ops_sprint | /dictionary_loader.rb | UTF-8 | 516 | 3.296875 | 3 | [] | no_license | class DictionaryLoader
def self.load(dictionary_file)
return false unless File.exists?(dictionary_file)
# check if dictionary_file is a valid path
dictionary = Dictionary.new
File.open(dictionary_file).each do |line|
word = line.strip
dictionary.add_word(word)
end
puts "Dictionary ... | true |
172b190bca4bf6b657de14d144922c4646536d84 | Ruby | Lo1176/codewar | /test.rb | UTF-8 | 250 | 3.328125 | 3 | [] | no_license | def solution(number)
# put your solution here
divisible_numbers = []
for n in 1..number
if n % 3 == 0 || n % 5 == 0
divisible_numbers.push(n)
end
divisible_numbers.sum
end
end
puts solution(10)
puts "____"
puts divisible_numbers
| true |
522724eaf9c2bf729475df14cf6083dda645e36b | Ruby | Srjordao/One-Bit-Code | /OperadoresMatematicos.rb | UTF-8 | 181 | 3.28125 | 3 | [] | no_license | + (Adição)
– (Subtração)
* (Multiplicação)
/ (Divisão)
% (Módulo)
** (Expoente)
#soma
5+5 = 10
#menos
1-1 = 0
#multi
2*2 = 4
#divisao
2/2 = 1
#modulo
10%3 =
#expo
2**3 | true |
6f9f4132a22c90456fe3b460e2a162ad3caaf25e | Ruby | nergdnvlt-zz/euler_poker | /test/game_test.rb | UTF-8 | 14,202 | 3.21875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require 'pry'
require './lib/game.rb'
class GameTest < MiniTest::Test
def test_it_exists
game = Game.new('5H 5C 6S 7S KD 2C 3S 8S 8D TD')
assert_instance_of Game, game
end
def test_it_makes_two_hands
game = Game.new('5H 5C 6S 7S KD 2C 3S 8S 8D TD... | true |
c0b3f0684b0f1eb48c8a0956194b0f8f96f7f6dd | Ruby | morgano24/fullstack-challenges | /03-AR-Database/03-ActiveRecord-Basics/04-Seed-API/db/seeds.rb | UTF-8 | 385 | 2.796875 | 3 | [] | no_license | require "json"
require "rest-client"
# TODO: Write a seed to insert 10 posts in the database fetched from the Hacker News API.
response = RestClient.get "https://hacker-news.firebaseio.com/v0/topstories.json"
posts = eval(response)[0...10]
posts.to_a.each do |n|
resp = RestClient.get("https://hacker-news.firebase... | true |
9525537930485daee74c1622952d052f064896f6 | Ruby | dladowitz/night-market | /app/models/event.rb | UTF-8 | 2,066 | 2.53125 | 3 | [] | no_license | # == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# name :string(255) not null
# guests :integer not null
# user_id :integer
# location :string(255)
# start_date :date
# end_date :date
# budget :integer
# gluten_free... | true |
1b8c9e971b61548b1a5cd28b430b4eac057f76c6 | Ruby | joecarlyon/imgur_uploader | /spec_helper.rb | UTF-8 | 1,074 | 2.6875 | 3 | [] | no_license | require 'selenium-webdriver'
require 'rspec'
# Import all files from a given directory, so nothing needs to get updated once adding/removing from there
Dir[File.dirname(__FILE__) + '/pages/*.rb'].each {|file| require_relative file}
# Let's restrict this to Firefox because it's only a code sample
#
def setup
if ENV[... | true |
04871cb1ba285f484421000300266db1b1b99d80 | Ruby | Diogomsantoss/delivery_tools | /lib/shipping_watcher/trackers/correios_tracker.rb | UTF-8 | 2,529 | 2.640625 | 3 | [] | no_license | require 'correios-sro-xml'
# This is a Pure Ruby Object class, its methods return clean data, to be stored in the database
# It sums the three arguments and returns that value.
#
class CorreiosTracker
#shipped
#transit
#delivered
#failed
COMMON_STATES = [2,3,4,5,6,7,8,9,10,12,19,20,21,22,23,24,25,26,28,32,33... | true |
910079fa5a843ac8d8eebfa881a10a50256e40c7 | Ruby | domi10momo/TravelApp | /app/models/course_param.rb | UTF-8 | 378 | 2.78125 | 3 | [] | no_license | class CourseParam
def initialize
@model_course_id = 0
@route_id = 0 # course_routesテーブルのid
@order_number = 0 # 観光順序を表す値
end
def upper_course_id
@model_course_id += 1
end
def upper_route_id
@route_id += 1
end
def upper_order_number
@order_number += 1
end
def order_reset
... | true |
2f3c53bc868861ecf424d68fe22743444f8c4c4f | Ruby | gkosae/spreadshot | /lib/spreadshot/reader.rb | UTF-8 | 5,574 | 3.140625 | 3 | [
"MIT"
] | permissive | module Spreadshot
class Reader
# @param [Hash] options
# @option options [Symbol, Spreadshot::ReaderBackend] :backend
# The reader backend to use or the id if one of the provided backends
# @option options [Hash] :backend_options
# Required if one of the provided backends is used
# ... | true |
fc0f6853d9a0e0f1bb661d313c7bcb0660bb1858 | Ruby | zendesk/biz | /spec/day_time_spec.rb | UTF-8 | 7,818 | 2.953125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0"
] | permissive | # frozen_string_literal: true
RSpec.describe Biz::DayTime do
subject(:day_time) {
described_class.new(day_second(hour: 9, min: 53, sec: 27))
}
context 'when initializing' do
context 'with a valid integer-like value' do
it 'is successful' do
expect { described_class.new('1') }.not_to raise_... | true |
b416bf0939aad0b859f9823e718dbce025a0ff1c | Ruby | spemmons/rails-example | /app/controllers/api/jog_time_controller.rb | UTF-8 | 3,255 | 2.515625 | 3 | [] | no_license | class Api::JogTimeController < ApiController
before_filter :authorize_user
before_action :set_user
before_action :set_jog_time,except: [:index,:create,:weekly_summary]
def index
scope = @user.jog_times
scope = scope.limit(params[:limit]) if params[:limit] and params[:limit].to_i > 0
scope = scope_... | true |
e3093f58068ac91a2949a3a3bb7b4365014e0eb9 | Ruby | clbustos/dirty-memoize | /spec/dirty_memoize_spec.rb | UTF-8 | 2,836 | 2.984375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
class ExpensiveClass
attr_writer :x, :y
include DirtyMemoize
def initialize
@a=nil
@b=nil
@x='x'
@y='y'
end
def set_a(aa)
@a=aa
end
def compute
@a=@x
@b=@y
end
def a
"@a=#{@a}"
end
def b
"@b=#{@b... | true |
acc2a86c4f50cfe07541cd458f4a654484d66b6c | Ruby | dzunk/spiralizer | /lib/spiralizer/result.rb | UTF-8 | 513 | 3.140625 | 3 | [
"MIT"
] | permissive | module Spiralizer
class Result
def initialize(value)
@raw_value = value
end
def valid!
raise NumericElementError if raw_value.match? /[0-9]/
raise LowercaseElementError if raw_value.match? /[a-z]/
raise InvalidElementError unless raw_value.match? /^[A-Z\s]*$/
true
end
... | true |
14e7b5401dcaf877224e408a57654b7878d9059b | Ruby | Romu-Muroga/docking | /app/helpers/application_helper.rb | UTF-8 | 1,904 | 2.546875 | 3 | [] | no_license | module ApplicationHelper
# Highlight current link
def cp(path)
'current' if current_page?(path)
end
def posts_index_page?(target_controller, target_action)
'current' if target_controller == 'posts' &&
(target_action == 'index' || target_action == 'search')
end
def my_page?(target_... | true |
d24314b17365a7469336210fda7c2000531fc8e0 | Ruby | scottmacphersonmusic/data_structures | /spec/features/linked_list/to_s_spec.rb | UTF-8 | 362 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'linked_list'
describe LinkedList do
before do
# Given a linked list with several nodes
@list = LinkedList.new 7
temp = @list.head
@list.head = Node.new(4, Node.new(5, Node.new(6, temp)))
end
it "to_s prints all values in comma-separated list" do
proc { @list.to... | true |
6b74c2b0f777542288ba31a4d07f4846c3466b5e | Ruby | pyrat/gravatar | /lib/attributes.rb | UTF-8 | 2,538 | 2.6875 | 3 | [
"MIT"
] | permissive | #
# Mixin for ActiveRecord::Base classes. Will add a gravatar(..) method
# which returns the URL of the gravatar resource associated to the model's
# instance.
#
# Author:: Juris Galang (mailto:jurisgalang@gmail.com)
# Copyright:: Copyright (c) 2010 Juris Galang
# License:: MIT License
#
# Permission is hereby gr... | true |
a0a155dbfe5688d181a50676159f9eedbc9d9390 | Ruby | asg0451/Teensy-Mixer | /client.rb | UTF-8 | 1,835 | 2.828125 | 3 | [] | no_license | #!/usr/bin/env ruby
##
# client.rb -- the client program for my Teensy-based mixer thing
# author: Miles Frankel (miles.frankel at gmail.com)
##
# require 'pry'
require 'serialport'
def inputs_readout # TODO: check for failure
inputs = `pactl list sink-inputs`
inp_list = (inputs.split(/Sink Input/)).map do |s|
... | true |
2ddec07f2344181343a3d2b81cba3fd5369f96e0 | Ruby | apoc64/analyzip | /app/presenters/zips_index_presenter.rb | UTF-8 | 730 | 2.609375 | 3 | [] | no_license | class ZipsIndexPresenter < Presenter
def initialize(current_user)
set_user(current_user)
set_default_map
@card1 = find_high_incomes
@card2 = find_low_incomes
@card3 = find_high_pops
end
def page_title
'US Zip Codes - AnalyZip'
end
private
def find_high_incomes
cp = CardPresent... | true |
d48e2ce36abd062a0a7bc6a3455e02994489e6e4 | Ruby | Hawk1n5/TUCTF_2016_write_up | /pwn/woo/exp.rb | UTF-8 | 1,008 | 2.75 | 3 | [] | no_license | #!/usr/bin/env ruby
require '~/Tools/pwnlib'
local = false#true
if local
host, port = '127.0.0.1', 4444
else
host, port = '104.196.15.126', 15050
end
def bring(index, type, name)
@r.recv_until("Enter your choice:")
@r.send("#{index}\n")
@r.send("#{type}\n")
@r.send("#{name}\n")
@r.recv_until("Menu Options:")
... | true |
73f314dd6251c74c2a00512896922599768f8233 | Ruby | jwaldrip/navigable_hash | /spec/helpers/helper_methods.rb | UTF-8 | 1,294 | 2.5625 | 3 | [
"MIT"
] | permissive | module NavigableHash::HelperMethods
def test_key_with_dot_notation(key, hash)
case (value = hash[key])
when Hash
value.keys.each { |key| test_key_with_dot_notation key, hash }
end
describe "##{key}" do
it "should call navigate" do
navigable.stub(:navigate)
navigable.send(k... | true |
caf8e7ce7801316be1e6655f96905808047b96c2 | Ruby | l-plan/soccer_bet | /app/models/team.rb | UTF-8 | 981 | 2.640625 | 3 | [] | no_license | class Team < ApplicationRecord
has_many :winners, -> { winner }, class_name: "Bet::Team", inverse_of: :team
has_many :redcards, -> { redcard }, class_name: "Bet::Team", inverse_of: :team
has_many :finalists, -> { finale }, class_name: 'Bet::Team', inverse_of: :team
has_many :semifinalists, -> { semifinal }, class... | true |
e37d1e2491fb416ab938cf49a38de8db66a07e8b | Ruby | MassICTBV/nlexch-slanger | /benchmark.rb | UTF-8 | 4,266 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pusher'
require 'pusher-client'
require 'json'
require 'uri'
require 'optparse'
options = {
api_uri: 'http://api.pusherapp.com:80',
ws_uri: 'ws://ws.pusherapp.com:80',
num: 1,
messages: 10,
payload_size: 20,
send_rate: 10
}
OptionParser.new do |opts|
opts.on '-c', '--concu... | true |
bf1d70f3ebbae62a6b4aad9abf2799abb0b541e8 | Ruby | floriandejonckheere/advent-of-code | /2020/1/solution.rb | UTF-8 | 347 | 3.5 | 4 | [] | no_license | #!/usr/bin/env ruby
# frozen_string_literal: true
numbers = File
.read("./input.txt")
.split("\n")
.map(&:to_i)
# Part one
a, b = numbers.permutation(2).find { |a, b| a + b == 2020 }
puts "#{a} * #{b} = #{a * b}"
# Part two
a, b, c = numbers.permutation(3).find { |a, b, c| a + b + c == 2020 }
puts "#{a} * #... | true |
22371771060b447ed1bfa6b4df1cae282baf0c0e | Ruby | alexignat/ruby_fundamentals_part1 | /exercise1.rb | UTF-8 | 299 | 4.1875 | 4 | [] | no_license | # puts
puts 2
puts 3
puts 2 != 3
# single quotes
puts "Betty's pie shop"
puts 'Betty\'s pie shop'
# playing with strings
puts "Hello\t\tworld" # \t tabs
puts "Hello\b\b\b\b\bGoodbye world" #\b backspaces
puts "Hello\rStart over world" #\ carriage return
puts "1. Hello\n2. World" #\ new line | true |
34633caa20021a9d8e2235b52b75584de80a86eb | Ruby | smeds1/Ruby_Practice | /Unit5/randomMonth.rb | UTF-8 | 179 | 3.125 | 3 | [] | no_license | #Sam Smedinghoff
#3/13/18
#randomMonth.rb
months = ['January','February','March','April','May','June','July',
'August','September','October','November','December']
puts months[rand(12)]
| true |
54c0447cdecb1a41cb84683a60bc607f24f3f004 | Ruby | satoknj/chapex | /lib/chapex/parser/lexer.rb | UTF-8 | 3,016 | 2.890625 | 3 | [
"MIT"
] | permissive | module Chapex
module Parser
# Tokenize input string to consume it with racc
class Lexer
Lexicality = Struct.new(:expression, :token, :invoke)
attr_reader :tokens
SCOPE = /\b(public|protected|private|global)\b/
KEYWORDS = %i[
virtual
abstract
class
impl... | true |
c9a14ca36cfeb3c1e557e45b15fde8ec1b1c1258 | Ruby | mfilej/pv181 | /homework/05-standards/pad.rb | UTF-8 | 215 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require "padding"
puts "ANSI:"
Padding::ANSI.pad(open(ARGV[0]).read)
puts "\n\n"
puts "PKCS:"
Padding::PKCS.pad(open(ARGV[0]).read) | true |
9b66b4ed2e9f16e2651c90119642637d4ba65f29 | Ruby | katiebugsings/cli-data-gem-assessment-v-000 | /henry_ford/lib/henry_ford/village.rb | UTF-8 | 210 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Village
attr_accessor :restaurants
def initialize(restaurants)
self.restaurants = []
@restaurants = restaurants
end
def self.all
@@all
end
def save
@@all << self
end
end
| true |
94de64aab9ea8356c8f331190b0416fd916a8dcb | Ruby | ypadron/skillcrush-104 | /always_three_argument.rb | UTF-8 | 221 | 3.390625 | 3 | [] | no_license | puts "Give me a number, please."
input_number = gets.to_i
def always_three_argument(input_number)
puts 'still ALWAYS ' + (((input_number + 5) * 2 - 4) / 2 - input_number).to_s
end
always_three_argument(input_number)
| true |
017c6c96732cedc1614cb4f726c9aa55da16106d | Ruby | MosheBerman/oop-1 | /1.3/Car.rb | UTF-8 | 681 | 3.78125 | 4 | [
"MIT"
] | permissive | =begin
Moshe Berman
Professor Zhou
CISC 3150
Spring 2014
Assignment 1.3
=end
class Car
attr :gasLevel
attr :fuelEfficiency
def initialize(fuelEfficiency)
@fuelEfficiency = fuelEfficiency
@gasLevel = 0
end
# Returns the amount of gas
def addGas(gasToAdd)
self.gasLevel += gasToAdd
end
# Adds g... | true |
9dc008ad7c0ec036ea447371eab654b916208262 | Ruby | nickrim/qa_repo | /ITA/hw_13/lib/script_13_07.rb | UTF-8 | 571 | 2.96875 | 3 | [] | no_license | # ========================================================================
puts ""
puts "Script \s\s\s\s: " + __FILE__.chop.chop.chop
# ========================================================================
# Description = "This is a description of the script"
# Name = "Nick Krimnus"
... | true |
db6e3afaec1b3ac7790626078a0b7e3b57d3c822 | Ruby | mattbryce93/CodeClan-Course | /week_01/day_2/what_animal.rb | UTF-8 | 197 | 3.75 | 4 | [] | no_license | p "What animal are you?"
name = gets.chomp.downcase
if (name == "chicken")
p "This is my favourite animal!"
elsif (name == "kitten")
p "I love kittens!"
else
p "Not my favourite animal."
end
| true |
c3200577de0bada5afbec268436dcacade3888bd | Ruby | stephenprill/hangry-angular | /server/app/services/restaurant_service.rb | UTF-8 | 402 | 2.828125 | 3 | [] | no_license | class RestaurantService
def initialize(restaurant_client)
@restaurant_client = restaurant_client
end
def find(attrs)
restaurant_client.find_by_location(
latitude: attrs[:latitude],
longitude: attrs[:longitude]
).map do |restaurant_data|
Restaurant.n... | true |
5fdbe188ac1b33489a9195d48982f1acf8a1ab6a | Ruby | Tanzi11/nyc-pigeon-organizer-dc-web-082718 | /nyc_pigeon_organizer.rb | UTF-8 | 384 | 3 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def nyc_pigeon_organizer(data)
pigeon_list = {}
data.each do |attribute_category, attribute_values|
attribute_values.each do |attribute_value, names|
names.each do |name|
pigeon_list[name] ||= {}
pigeon_list[name][attribute_category] ||= []
pigeon_list[name][attribute_category] << ... | true |
a645ab629fe23a0fb4eee4599ee83107bc1b3e94 | Ruby | rgrier104/reverse-each-word-v-000 | /reverse_each_word.rb | UTF-8 | 228 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(string)
array = string.split(' ')
reverse_array = []
array.each do |word|
reverse_array << word.reverse
end
array.collect do |word|
word.reverse
end
return reverse_array.join(" ")
end
| true |
edf67bd82ffbfbae9b57e2639c7e68da58c06574 | Ruby | elastic/docs | /resources/asciidoctor/lib/alternative_language_lookup/listing.rb | UTF-8 | 4,126 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'alternative'
require_relative '../log_util'
module AlternativeLanguageLookup
##
# Information about a listing in the original document.
class Listing
RESULT_SUFFIX = '-result'
RESULT_SUFFIX_LENGTH = RESULT_SUFFIX.length
include LogUtil
attr_reade... | true |
18e16529bafc56eb68c44048469aa7baa9e95952 | Ruby | queso/status | /app/models/status.rb | UTF-8 | 360 | 2.8125 | 3 | [] | no_license | class Status < ActiveRecord::Base
attr_protected :up
validates :up, :inclusion => {:in => [true, false], :message => "status can't be blank"}
def status
up ? "up" : "down"
end
def status=(status)
matcher = status.to_s.downcase
if matcher == "up"
self.up = true
elsif matcher == "down"
... | true |
2d5e39a1c15effa443ee9395daf8e1c5f6349b31 | Ruby | anicholson/json_schema_tools | /lib/schema_tools/modules/read.rb | UTF-8 | 2,784 | 2.6875 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'active_support'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/inflections'
module SchemaTools
module Modules
# Read schemas into a hash
module Read
# Variable remembering already read-in schema's
# {
# :invoic... | true |
2e4562d894b93b7fa89a2c41b18cf40d3c135871 | Ruby | nickdiaz57/oh_seven | /lib/component.rb | UTF-8 | 449 | 3 | 3 | [
"MIT"
] | permissive | class Component
attr_accessor :name, :engineers
extend Concerns
@@all = []
def initialize(name)
@name = name
@engineers = []
end
def self.all
@@all
end
def save
@@all << self
end
def add_engineer(engi)
engi.componen... | true |
c77d0e92a090c18199595d10119c57197fa6d451 | Ruby | alemohamad/book-of-ruby | /08 - Passing Arguments and Returning Values/default_args.rb | UTF-8 | 395 | 3.78125 | 4 | [] | no_license | # The Book of Ruby - http://www.sapphiresteel.com
def aMethod( a=10, b=20, c=100, *d )
return a, b, c, d
end
def anotherMethod( greeting="Hello", name="friend" )
return "#{greeting}, #{name}"
end
p( aMethod )
p( aMethod( 1,2 ) )
p( aMethod( 1,2,3 ) )
p( aMethod( 1,2,3,4,6 ) )
p( anotherMethod )
p( a... | true |
5af1d3bf441e0e912a4c553a05cb4b9a3702acbd | Ruby | dsauerbrun/climbcation | /app/models/post.rb | UTF-8 | 888 | 2.609375 | 3 | [] | no_license | def is_numeric(o)
true if Integer(o) rescue false
end
class Post < ActiveRecord::Base
has_paper_trail
belongs_to :forum_thread
belongs_to :user
DestinationCategoryName = 'Destinations'
def self.createNewPost(content, user_id, forum_thread_id)
if !is_numeric(forum_thread_id)
# must looks like this ... | true |
2613d7b8afe17c07e1ce486c841507e69fdba001 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/6ebe118219c34ccf999effdd8b0b2d72.rb | UTF-8 | 259 | 3.28125 | 3 | [] | no_license | class Hamming
def self.compute(source, mutation)
shortest_length = [source, mutation].map(&:length).min
distance = 0
shortest_length.times do |i|
if source[i] != mutation[i]
distance += 1
end
end
distance
end
end
| true |
24b07b6d2bae9547f0585d39ddc17b4964c9539c | Ruby | mazamachi/sentence2graph | /sentence2graph.rb | UTF-8 | 2,228 | 3.265625 | 3 | [] | no_license | require 'cabocha'
require 'gviz'
class Sentence2Graph
attr_accessor :parser, :gv
def initialize
@parser = CaboCha::Parser.new
@gv = Gviz.new
end
# 空白を含まないものを文節に分解して配列にする
def parse_string_to_array(str)
if str.match("\s")
raise "str must be one line"
end
tree = self.parser.parse(str)... | true |
894acf6467f3ed8563b0d9e364abe6fb559c1ba5 | Ruby | itggot-emil-babayev/standard-biblioteket | /lib/quicksort.rb | UTF-8 | 421 | 4.09375 | 4 | [] | no_license | # Public: Sorts an Array with the Quicksort algorithm
#
# arr - The Array that will be sorted
#
# Examples
#
# quicksort([7,3,1,3])
# # => [1,3,3,7]
#
# Returns the sorted Array
def quicksort(arr)
return arr if arr.length <= 1
pivot = arr.pop
smaller = arr.map{|x| x if x <= pivot}.compact
bigger =... | true |
d219d4f4a489b6b127ba06f9ec9b7ef798534d95 | Ruby | odangitsdjang/cat_rental | /app/models/cat.rb | UTF-8 | 1,004 | 2.75 | 3 | [] | no_license | # == Schema Information
#
# Table name: cats
#
# id :integer not null, primary key
# birth_date :date not null
# color :string not null
# name :string not null
# sex :string(1) not null
# description :text not null
# creat... | true |
f4176f9154413622a60385ca8d97a387cdf4cbca | Ruby | kmac02/phase-0-tracks | /ruby/hashes.rb | UTF-8 | 2,764 | 3.96875 | 4 | [] | no_license | #Declare keys (with empty values) in questionnaire
questionnaire = {
name: "",
age: "", #integer
family_size: "", #integer
children_under_10: "", #boolean
decor_theme: "",
number_of_rooms: "", #integer
need_new_walls: "", #boolean
has_pets: "", #boolean
number_of_pets: "" #integer
}
#Ask user to begi... | true |
dcf9c3aab5fb81f79df8093fb9e2e87c15c5660e | Ruby | whatsrupp/gilded-rose | /spec/quality_updater_spec.rb | UTF-8 | 4,488 | 2.703125 | 3 | [] | no_license | describe Quality do
let (:quality) {described_class.new}
describe '#set_item' do
it 'updates the old item with a new item' do
item = Item.new("Sulfuras, Hand of Ragnaros", 0, 80)
expect(quality.item).not_to eq(item)
quality.set_item (item)
expect(quality.item).to eq(item)
end
end
... | true |
379ff41c2e0cb0a46c8128a6098d218fdb65b997 | Ruby | SudhakerVeerendraManikonda/Mocking_WebService | /test/net_asset_value_test.rb | UTF-8 | 3,130 | 2.75 | 3 | [] | no_license | $:.unshift(File.join(File.dirname(__FILE__), '..', 'src'))
$:.unshift '..'
require 'simplecov'
SimpleCov.start
require 'net_asset_value'
require 'test/unit'
require 'stringio'
class NetAssetValueTest < Test::Unit::TestCase
def setup
@asset = NetAssetValue.new
end
def te... | true |
3438b2c5be2d89899bf8727fa1c126501cfd2ace | Ruby | drjolo/RubyLearning | /week_4/exercise4-Swap_File_Contents.rb | UTF-8 | 343 | 2.78125 | 3 | [] | no_license | def file_swap( pathA, pathB )
pathC = File.dirname(pathA) + '/.temp'
move( pathA, pathC )
move( pathB, pathA )
move( pathC, pathB )
end
def move( old_path, new_path )
File.link( old_path, new_path )
File.delete( old_path )
end
if __FILE__ == $0
pathA, pathB = 'docs/first.txt', 'docs/second.txt'
file_s... | true |
0f9df5fed1ed66b4d68ddc34d9f78993b39e260a | Ruby | albertbahia/wdi_june_2014 | /w02/d02/liza_ramo/Pets/Dog.rb | UTF-8 | 319 | 3.140625 | 3 | [] | no_license | class Dog < Pet
attr_reader(:ear_type)
def initialize(name, age, owner, ear_type)
# @name = name
# @age = age
# @owner = owner
super(name, age, owner)
@foods_eaten = []
@ear_type = ear_type
end
def eat(food)
return "Woof"
end
def sleep()
@hours_slept += 1
end
end
| true |
997fa8fc919ac4d44e5992db46b0532083cfd07e | Ruby | bosh/CompilerConstruction | /lib/Buffer.rb | UTF-8 | 2,691 | 3.5 | 4 | [] | no_license | class Buffer
attr_accessor :contents, :current, :current_head, :style
def initialize(str, dirty = false, style = :default)
@contents = str.strip
@current = @current_head = 0
@style = style
clean! unless dirty #Heh heh heh
end
def clean!; @contents.gsub!(/\{.*?(\}|\z)/m, "") end #St... | true |
f78312b695a52101eba06de15f04e5d70cb9f9e2 | Ruby | m-rwash/ruby-hackerrank | /array_selection.rb | UTF-8 | 467 | 4.03125 | 4 | [] | no_license | # https://www.hackerrank.com/challenges/ruby-array-selection/problem
def select_arr(arr)
# select and return all odd numbers from the Array variable `arr`
arr.select{|n| n.odd?}
end
def reject_arr(arr)
# reject all elements which are divisible by 3
arr.reject{|n| n%3==0}
end
def delete_arr(arr)
# delet... | true |
a15ea055c8d3cacae88cd15e51cf7418187104b9 | Ruby | Jenietoc/Ruby_kommit_course | /Arrays II/The_each_with_index_Method.rb | UTF-8 | 444 | 4 | 4 | [] | no_license | colors = %w[Red Blue Green Yellow]
colors.each_with_index do |color, index|
puts "Moving on index number #{index}"
puts "The current color is #{color}"
end
=begin
Write a loop that iterates over a numeric array
Output the PRODUCT of each number a and its index
position
=end
fives = [5, 10, 15, 20... | true |
feae47ad3914345e9eed6e3464c881c670c9b651 | Ruby | Cowskin/Design-patterns | /patterns_explain/模板方法模式/report.rb | UTF-8 | 2,026 | 3.203125 | 3 | [] | no_license | # -*- coding: utf-8 -*-
class Report
def initialize
@title= 'Monthly Report'
@text = ['Things are going','really ,really well.']
end
# 这个是模板方法的组合,只放在模板类里面,子类不重载,其他方法可能被重载
# 这个抽象的基类通过模板方法来控制高端的处理流程
def output_report
output_start
output_head
output_body_start
output_body
output_body... | true |
82afb5ee987eb2cfd712b54780053db9b1496fbc | Ruby | Reksford/ruby-book-exercises | /hashes/exercise8.rb | UTF-8 | 416 | 3.75 | 4 | [] | no_license | =begin
NoMethodError: undefined method `keys' for Array
This error is the result of calling the #keys method on
an Array object which has no keys method available to it.
#keys is a method for hash objects.
array_of_hashes = [{key: "value"}, {a: "apple"}, {one: 1, two: 2, three: 3}]
array_of_hashes.keys #throws NoMeth... | true |
09e1991b7fe9dd95071a7305c97c53003f2ace8b | Ruby | buntine/Bolverk-Assembler | /test/functional/lexer.rb | UTF-8 | 7,617 | 3.03125 | 3 | [] | no_license | require 'test/unit'
require File.join(File.dirname(__FILE__), "../..", "lib", "asm")
class LexerTest < Test::Unit::TestCase
# This is easy. We just need to scan a few programs and verify that
# the lexer responds appropriately.
def setup
path = lambda { |file| File.join(File.dirname(__FILE__), "data", file... | true |
f252cb6a062242329de607a9558b7fb21fd1cbcd | Ruby | CodingDojoDallas/ruby_dec_2018 | /andrew_barstow/ruby_fundamentals/human.rb | UTF-8 | 589 | 3.46875 | 3 | [] | no_license | class Human
attr_accessor :health, :strength, :stealth, :intelligence
def initialize
@strength = 3
@stealth = 3
@intelligence = 3
@health = 100
init_extension
end
def attack(character, damage = 10)
#pass a character object here with a health attribute. ... | true |
736712d1f9ef5650c2a07660de27405ddf2f7c23 | Ruby | Mohafizz/Tealeaf_Lesson_1 | /calculator.rb | UTF-8 | 964 | 4.34375 | 4 | [] | no_license | #Code up your own calculator from the lecture. Make sure you can run it from the command line. Save the calculator file in a directory,
#and initialize the directory as a git repository. Make sure this isn't nested in another existing git repository. Then, push this git
#repository to Github.
def output(msg)
puts ... | true |
5f021155e1463a2983859d4a47fd9d4c18082a1f | Ruby | gabrielrigon/schommunity | /config/initializers/constantine.rb | UTF-8 | 1,357 | 2.640625 | 3 | [
"MIT"
] | permissive | #:nodoc:
module Constantine
def self.included(base)
base.extend(ClassMethods)
end
#:nodoc:
module ClassMethods
def constantine(attributte = :name)
return unless table_exists?
all.each do |item|
constant_name = item.try(attributte)
.remove_non_ascii_and_s... | true |
925d86c04561f53953ef496769f7f3e5060598da | Ruby | yhara/sinatra_project_template | /app/controllers/books_controller.rb | UTF-8 | 1,162 | 2.515625 | 3 | [
"MIT"
] | permissive | class MyApp < Sinatra::Base
get '/books' do
session["ct"] ||= 0; session["ct"] += 1
@books = Book.order(updated_at: :desc)
slim :'books/index'
end
get '/books/new' do
@book = Book.new
slim :'books/new'
end
get '/books/:id' do
@book = Book.find_by!(id: params[:id])
slim :'books/sh... | true |
66a01b64286ca8ec80915053df8b2185df4bcf4e | Ruby | mjvsha/collections-iteration | /ex3.rb | UTF-8 | 965 | 4.375 | 4 | [] | no_license | =begin
Print out the first two performing artists in that array.
For each of your favourite movies, print out a sentence about when the movie was released. For example:
Avatar came out in 2009.
Mean Girls came out in 2004.
The Matrix came out in 1999.
Sort and reverse the array of ages of your family. Save it and print... | true |
87f1e6687cac54c065476cd90c89496c2593473c | Ruby | sllimnnodnarb/sep-assignments | /02-algorithms/03-sort-algorithms/bucket.rb | UTF-8 | 571 | 3.3125 | 3 | [] | no_license | class BucketSort
require_relative 'insertion_sort'
def self.sort(array, bucket_size)
bucket_count = ((array.max - array.min) / bucket_size).floor + 1
buckets = Array.new(bucket_count)
(0..buckets.length - 1).each do |i|
buckets[i] = []
end
(0..array.length - 1).each do |i|
buckets... | true |
f900e16c449582a63e449aeeb7f02899067bb6c1 | Ruby | lburl01/tasks_sinatra | /tasks_api.rb | UTF-8 | 1,113 | 2.6875 | 3 | [] | no_license | require 'sinatra'
require_relative 'task'
require 'json'
get '/api/tasks' do
if !params['completed'].nil?
Task.where(completed: params['completed']).to_json
elsif !params['search'].nil?
Task.where("description like ?", "%#{params['search']}%").to_json
elsif !params['sort'].nil?
Task.order(priority: :... | true |
656d6774ea03feb03b7b7af3e1f975371e2ec86a | Ruby | rkh/nii | /nii-rbnf/lib/nii/rbnf/parser.rb | UTF-8 | 1,577 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
class Nii::RBNF
# @api internal
class Parser
# PUBLIC_RULESET = /\s*%([\w\-]+)\s*:\s*/m
# PRIVATE_RULESET = /\s*%%([\w\-]+)\s*:\s*/m
# RULE = /\s*([^%\s\:\;][^\:\;]*)?;\s*/
SET = %r{ \s* (?<prefix>%%?) (?<name>[\w\-]+) : \s* }mx
SIMPLE = %r{ \s* (?!... | true |
93f9c36c423551486857c867bd7333f86f9cfd2b | Ruby | ryoma123/competitive-programming | /atcoder/abc152/abc152_c.rb | UTF-8 | 148 | 2.921875 | 3 | [] | no_license | n = gets.to_i
a = gets.split.map(&:to_i)
num = 0
min = 200000
(0...n).each do |i|
if a[i] <= min
num += 1
min = a[i]
end
end
puts num
| true |
e4d7f08a8fbd77d58c65192d7782c2d0498162fd | Ruby | Nevillealee/recharge_checkout_webhook | /app/services/un_tagger.rb | UTF-8 | 4,130 | 2.59375 | 3 | [] | no_license | # Internal: Using subscription or customer json recieved from recharge,
# remove 'recurring_subscription' tag from matching shopify customer object
# if customer no longer has an active subscription.
class UnTagger
def initialize(id, type, obj)
@my_id = id
@id_type = type
@cust = obj
my_token = ENV['R... | true |
127f3b985010a3c25c9aed4859dd6fb5f2312050 | Ruby | philwilt/data-structs-algs | /lib/array_sorter.rb | UTF-8 | 1,447 | 3.453125 | 3 | [] | no_license | class Array
def insertion_sort!
(1..size - 1).each do |i|
j = i
while j > 0 && (self[j - 1] > self[j])
self[j - 1], self[j] = self[j], self[j - 1]
j -= 1
end
end
end
def merge_sort
ms_sort(self)
end
def quick_sort
q_sort(self)
end
def radix_sort
rad... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.