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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
f19de996e0b13e9db86bcaf7aa44da6071aaf5eb | Ruby | JennicaStiehl/ruby-exercises | /initialize/lib/horse.rb | UTF-8 | 176 | 3.609375 | 4 | [] | no_license | class Horse
attr_reader :name
attr_accessor :diet
def initialize(name)
@name = name
@diet = []
end
def add_to_diet(food)
@diet << food
end
end
| true |
a3af1e0fbf9cce938fcb2110ab4ba8b54d6e5d13 | Ruby | synesissoftware/xqsr3-xml | /test/unit/xml/utilities/tc_navigation.rb | UTF-8 | 1,172 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause"
] | permissive | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
require 'xqsr3/xml/utilities/navigation'
require 'xqsr3/extensions/test/unit'
require 'test/unit'
require 'nokogiri'
class Test_Xqsr3_XML_Utilities_Navigation < Test::Unit::TestCase
include ::Xqsr3::XML::Utilities::Navigation
... | true |
6f7853760e8ab9e82446db8a2fae162947843104 | Ruby | guyviner/codecorelife | /day12/PersonalityQuiz/app.rb | UTF-8 | 1,662 | 3.109375 | 3 | [] | no_license | require "sinatra"
#downloaded sinatra reloader to keep the server fresh
require "sinatra/reloader"
# tell it to reference the root
get "/" do
erb :index, layout: :template
# or erb(:index, {layout: :template}) , alternative syntax
# need to embed some ruby to actually see it , using erb
end
post '/index' do
... | true |
85705dc4f7251fb03300810066b6ab9a495283f6 | Ruby | sigus/solutions | /cf/1077A.rb | UTF-8 | 93 | 2.75 | 3 | [] | no_license | t = gets.to_i
t.times do
a, b, k = gets.split.map(&:to_i)
p(a*((k + 1)/2) - b*(k/2))
end
| true |
2864c448120b99860aee256abc948ab6b2fa4abd | Ruby | epair/autodo | /app/models/list.rb | UTF-8 | 591 | 2.59375 | 3 | [] | no_license | class List < ActiveRecord::Base
has_many :cards
belongs_to :board
validates :title, presence: true
validates :board_id, presence: true
def self.generate_calendar(date, board_id)
i = 0
while i < 8 do
new_date = date + i
date_title = new_date.strftime('%a %b %d')
List.create(title: da... | true |
4bbdc019a6572a79ab8bed394b8c3d1fc8a96d0a | Ruby | derekjmaloney/anagram-detector-v-000 | /lib/anagram.rb | UTF-8 | 182 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Your code goes here!
require 'pry'
class Anagram
def initialize(word)
@word = word
end
def match(array)
array.select {|w| w.split("").sort == @word.split("").sort}
end
end
| true |
9dd96f96af1764982a63a7c8c50823ffc46e962e | Ruby | simonc/absolute_renamer | /lib/absolute_renamer/interpreters/original_filename_interpreter.rb | UTF-8 | 503 | 2.6875 | 3 | [] | no_license | require 'absolute_renamer/interpreters/base'
module AbsoluteRenamer
module Interpreters
class OriginalFilenameInterpreter < Base
def search_and_replace(part_name, new_value, path_handler)
original_value = path_handler.send(part_name)
new_value.gsub(/\$/) { original_value }
... | true |
8ce169c5345403c2302638e80b8bddf5b65483aa | Ruby | bbuchalter/decoder | /lib/decoder/county.rb | UTF-8 | 212 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Decoder
class County
include ::CommonMethods
attr_accessor :name, :fips
def initialize(args)
self.name = args[:name]
self.fips = args[:fips].to_i if args[:fips]
end
end
end | true |
a2a9a7f251093721de946de097550101cbde61ed | Ruby | anshulacro/myapp | /testwithnoko.rb | UTF-8 | 854 | 2.859375 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
PAGE_URL = "http://ruby.bastardsbook.com/files/hello-webpage.html"
XML_URL= "http://asciicasts.com/episodes.xml"
page = Nokogiri::HTML(open(PAGE_URL))
xml_page=Nokogiri::XML(open(XML_URL))
puts xml_page
puts page.css("title")[0].name # =>... | true |
0f64a516e89e3ead50e40cb739e831dd79b2ba2f | Ruby | andrewgho/movewin-ruby | /examples/findleaks | UTF-8 | 1,327 | 2.734375 | 3 | [
"BSD-3-Clause"
] | permissive | #!/usr/bin/env ruby
# Load local development directories, if it looks like we are in a repository
DIRNAME = File.dirname(__FILE__);
if File.exists?("#{DIRNAME}/../lib/movewin.rb") &&
File.directory?("#{DIRNAME}/../ext/movewin")
then
$LOAD_PATH.unshift("#{DIRNAME}/../lib", "#{DIRNAME}/../ext")
else
require 'ruby... | true |
e5df85c80fa5a38edcd34bbc9ecb1e14b33dad14 | Ruby | quietpochatok/hangman | /main.rb | UTF-8 | 1,225 | 2.953125 | 3 | [] | no_license | if Gem.win_platform?
Encoding.default_external = Encoding.find(Encoding.locale_charmap)
Encoding.default_internal = __ENCODING__
[STDIN, STDOUT].each do |io|
io.set_encoding(Encoding.default_external, Encoding.default_internal)
end
end
require_relative 'lib/console_interface'
require_relative 'l... | true |
5681d5ca87a6eb589d3e769d91d06009e8bed3ab | Ruby | molit-korea/main | /Pages/2017 국토교통 빅데이터 해커톤 참가작/molit_HAB-master/elastic/logstash-5.5.2/vendor/bundle/jruby/1.9/gems/logstash-filter-metrics-4.0.3/lib/logstash/filters/metrics.rb | UTF-8 | 8,640 | 2.890625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | # encoding: utf-8
require "securerandom"
require "logstash/filters/base"
require "logstash/namespace"
# The metrics filter is useful for aggregating metrics.
#
# IMPORTANT: Elasticsearch 2.0 no longer allows field names with dots. Version 3.0
# of the metrics filter plugin changes behavior to use nested fields rather ... | true |
29b63441b37bcde2c865e388c444d92c2d4873b6 | Ruby | johnnykalalua/ruby-challenges | /12. Advanced Arguemnt Emily Greeting/Advanced_argument_Emily_greeting.rb | UTF-8 | 486 | 3.96875 | 4 | [] | no_license | puts "What is your name?"
user_name = gets.to_s
def determine_current_hour
current_time = Time.new
current_hour = current_time.hour
end
def greeting(user_name)
current_hour = determine_current_hour
if (current_hour > 3 && current_hour < 12)
time = "morning"
elsif (current_hour > 12 && current_hour < 18)
... | true |
65792ec76047e29be3c5e2ca2b52974212adcf80 | Ruby | tullur/mampf | /app/models/link.rb | UTF-8 | 1,091 | 2.671875 | 3 | [
"MIT"
] | permissive | # Link class
# JoinTable for medium<->medium many-to-many-relation
# describes which media are related to a given medium
class Link < ApplicationRecord
belongs_to :medium
belongs_to :linked_medium, class_name: 'Medium'
# we do not want duplicate entries
validates :linked_medium, uniqueness: { scope: :medium }
... | true |
f6668943e62685ce578374b5b8dc87fd748cce1b | Ruby | iwaseasahi/design_pattern_with_ruby | /facade/html_writer.rb | UTF-8 | 551 | 2.90625 | 3 | [] | no_license | class HtmlWriter
def initialize(writer)
@writer = writer
end
def title(title)
@writer.puts('<html>')
@writer.puts('<head>')
@writer.puts('<title>' + title + '</title>')
@writer.puts('</head>')
@writer.puts('<body>')
@writer.puts('<h1>' + title + '</h1>')
end
def paragraph(msg)
... | true |
89ac8b5d31ab40750d602330f504ba121b5f42bd | Ruby | mmaltar/flighter | /isa-backend-flighter-mmaltar-feature-hw8/app/services/world_cup/match.rb | UTF-8 | 1,739 | 2.8125 | 3 | [] | no_license | module WorldCup
class Match
attr_accessor :venue, :status, :starts_at
attr_reader :home_team_goals, :home_team_code, :home_team_name,
:away_team_goals, :away_team_code, :away_team_name,
:events, :goals
def initialize(match = {})
@venue = match['venue']
@status ... | true |
ff59bfcefdb7736836d4fbebec1c284a0dabf743 | Ruby | ykumawat/cartoon-collections-ruby-cartoon-collections-000 | /cartoon_collections.rb | UTF-8 | 598 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def roll_call_dwarves(dwarves)# code an argument here
# Your code here
dwarves.each_with_index do |dwarf, index|
puts "#{index+1}.#{dwarf}"
end
end
def summon_captain_planet(calls)# code an argument here
# Your code here
calls.collect{|call|"#{call.capitalize}!"}
end
def long_planeteer_calls(calls)# cod... | true |
83d05667e987a562526c0631f6b70470878165bd | Ruby | joannajohn0214/kwk-l1-garden-gnome-oo-lab-kwk-students-l1-raleigh-072318 | /garden_gnome.rb | UTF-8 | 1,236 | 3.890625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Code your instances here
class GardenGnome
def name=(name)
@name= name
end
def name
@name
end
def age=(age)
@age=age
end
def age
@age
end
def gluten_allergy=(gluten_allergy)
@gluten_allergy=gluten_allergy
end
def gluten_allergy
@gluten_allergy
end
d... | true |
a14e105b1ccad81b263bae8c1b68040a23f0dbd3 | Ruby | betweenparentheses/ruby_building_blocks | /caesar_cipher.rb | UTF-8 | 924 | 3.96875 | 4 | [] | no_license | #working version!
def caesar_cipher (string, num)
shift = num % 26
chars = string.split(//)
chars.map! do |char|
char_num = char.ord
was_letter = false
was_letter = true if (char =~ (/\w/)) #checks if it was originally a letter rather than space or punctuation
#wraparound check. handles capitals and low... | true |
822b7cb55f159e5c995809fa2d139b47e925fd3d | Ruby | russellschmidt/BlocBooks | /app/controllers/books_controller.rb | UTF-8 | 796 | 2.59375 | 3 | [] | no_license | class BooksController < BlocWorks::Controller
def welcome
render :welcome, book: 'Loquacious Ruby'
end
def index
render :index, books: Book.all
end
def show
book = Book.find(params['id'])
render :show, book: book
end
def new
render :new
end
def create
# add to db
redirect :index
end
def ed... | true |
895efb10eaaf3be005088f6bbe3bc6f4cd5df075 | Ruby | Diley/studio_game | /_partial_versions/fundraising_program/fundraising_program_v18/fundrequest.rb | UTF-8 | 1,822 | 3.40625 | 3 | [] | no_license | require_relative 'project'
require_relative 'die'
require_relative 'funding_round'
require_relative 'pledge_pool'
class FundRequest
attr_accessor :name
def initialize(name)
@name = name
@projects = []
end
def add_project(project)
@projects << project
end
def request_funding(rounds)
pledges = PledgePo... | true |
261d87f552c43de909454f03b4bd5b786bddcfd6 | Ruby | kiwofusi/column_name_conv | /2_column_name_conv2_timeover.rb | UTF-8 | 2,362 | 3.078125 | 3 | [] | no_license | =begin
start:1854
end:1915(21m)
end:1925(31m) リファクタリング&バグ修正
start2:1925
end2:2016 ruby column_name_conv2.rb 1 1 成功
deadline:2024 終了……
26**0 => 1
A=>1
AA=> (26**1 * 1) + (26**0 * 1)
BA=> (26**1 * 2) + (26**0 * 1)
BB=> (26**1 * 2) + (26**0 * 2)
AAA=> (26**2 * 1) + (26**1 * 1) + (26**0 * 1)
XFD=> (26**2 * 2... | true |
79d08c86b9276368a71402d17113c864d6ae7471 | Ruby | ostarling/planner | /planning/ordering.rb | UTF-8 | 11,468 | 2.90625 | 3 | [] | no_license | module Math
def self.min a,b
a<b ? a : b
end
def self.max a,b
a>b ? a : b
end
end
module Planning
class OrderingException < Exception
end
class OrderingData
attr_reader :prev_version, :version
attr_writer :order
def initialize prev_version, version, ... | true |
ccc2548344608a11e31ecb2898e55c4f4fb15676 | Ruby | westonganger/rodf | /lib/rodf/row.rb | UTF-8 | 945 | 2.796875 | 3 | [
"MIT"
] | permissive | module RODF
class Row < Container
attr_reader :number
def initialize(number=0, opts={})
@number = number
@elem_attrs = {}
@elem_attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
if opts[:attributes]
@elem_attrs.merge!(opts[:attributes])
end
supe... | true |
0d7e692ba8d75de4b01131502b39726d64475ddb | Ruby | Catharz/Raids-Per-Loot | /app/models/player_character.rb | UTF-8 | 956 | 2.671875 | 3 | [] | no_license | # @author Craig Read
#
# PlayerCharacter is a composite representing
# the Player and one of their Characters.
# This is used to simplify editing loot statistics
# for a particular player and character.
class PlayerCharacter
include Virtus.model
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_... | true |
78f8e60521901f93b363163a3596ccba492aa7b3 | Ruby | kgoettling/ruby_lessons | /lesson_3_practice_problems/medium_1/medium_1_7.rb | UTF-8 | 262 | 4.0625 | 4 | [] | no_license | # What is the output of the following code?
answer = 42
def mess_with_it(some_number)
some_number += 8
end
new_answer = mess_with_it(answer)
p answer - 8
# A: The code will output '34' to the screen. The variable answer is
# not modified by the method. | true |
f55aee5f0440285e56f597b6f1ac1e75d1475f86 | Ruby | jarombra/codecademy_Ruby | /lessonSeries/04_RB_thithMeanthWar/07_returningTheFinalStringErThtring.rb | UTF-8 | 234 | 3.890625 | 4 | [] | no_license | print "Type a phrase that uses the letter 's'"
user_input = gets.chomp
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/, "th")
puts "WAAAA! #{user_input}!"
else
puts "The letter 's' was not found"
end
| true |
b8b87430fc6959dc9f1cbcd692c923b6b777c0ca | Ruby | Josh-Gotro/ruby-oo-object-relationships-collaborating-objects-lab-austin-web-030920 | /lib/song.rb | UTF-8 | 784 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
attr_accessor :name, :artist
@@all = []
def initialize (name)
# binding.pry
@name = name
@@all << self
end
def self.all
@@all
end
def self.new_by_filename (filename)
# binding.pry
# associates new song instance wi... | true |
ab97e8e253ae14c9aed03bf225d70194e40bee07 | Ruby | clucas/caplinkedex | /app/models/book.rb | UTF-8 | 1,392 | 2.65625 | 3 | [] | no_license | require 'csv'
class Book < ApplicationRecord
searchkick
validates :title, presence: true
validates :author, presence: true
validates :publisher, presence: true
validates :category, presence: true
validates :published_on, presence: true
composed_of :unit_cost,
:class_name => 'Money',
... | true |
8cd22e4ce4422a2776ce6ea18f4b1708183d3526 | Ruby | baya/topic-api | /app/errors/api_error.rb | UTF-8 | 331 | 2.703125 | 3 | [] | no_license | module ApiError
Base = Class.new(StandardError)
Unauthorized = Class.new(Base)
CODE = {
Unauthorized => 401
}
def self.raise_error(error_class_name, error_msg = nil)
error_class = const_get(error_class_name)
raise error_class, error_msg
end
def self.get_code(error)
CODE[error.class]
... | true |
6d19e149a4e892edb703c797848aa27a90149821 | Ruby | envato/flip | /lib/flip/abstract_value_in_list_strategy.rb | UTF-8 | 800 | 2.53125 | 3 | [
"MIT"
] | permissive | module Flip
class AbstractValueInListStrategy < AbstractStrategy
include StrategyPersistence
def description
raise NotImplementedError
end
def value_param_name
raise NotImplementedError
end
def knows?(definition, options = {})
options[value_param_name] && on?(definition, o... | true |
b15c20333270231050f50bb258bb8cf2ab7df83e | Ruby | Illianthe/ProjectEuler | /solutions/023/non_abundant_sums.rb | UTF-8 | 897 | 3.609375 | 4 | [] | no_license | # Problem #23 - http://projecteuler.net/problem=23
require '../../lib/utility.rb'
include Utility
def non_abundant_sums
abundant_numbers = Hash.new(false)
# Find all abundant numbers. We have an upper limit of 28111 because
# we will only check for sums up to 28123 (and 12 is the smallest abundant #)
(12..28... | true |
78e7cca7328f523ecbeaca0066e346218da1374d | Ruby | leandroalemao/gb-blog | /app/facades/archive.rb | UTF-8 | 388 | 3.03125 | 3 | [] | no_license | module Facades
class Archive
def initialize(posts = [])
@posts = posts
end
def years
@posts.map { |post| publication_year(post) }.uniq
end
def posts_from_year(year)
@posts.select { |post| publication_year(post) == year }
end
private
attr_reader :posts
def pub... | true |
3a8bf80d55200567886bbfe8ca32cea1b2dbe652 | Ruby | Joellehelm/silicon-valley-code-challenge-austin-web-091619 | /app/models/funding_round.rb | UTF-8 | 487 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative "venture_capitalist"
require_relative "startup"
class FundingRound
attr_reader :startup, :venture_capitalist, :type, :investment, :all
# attr_accessor :type, :investment
@@all = []
def initialize(startup, vc, type, amount)
if amount.class == Float && amount.positive?
@startup =... | true |
8fa819e9acd33ec910c23b29b317dcc4f6e15eb6 | Ruby | jeanlazarou/calco | /spec/errors_spec.rb | UTF-8 | 2,431 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'calco'
RSpec.configure do |c|
c.alias_example_to :detect
end
describe 'Spreadsheet errors' do
detect "variable does not exist" do
expect {
spreadsheet do
sheet do
column value_of(:some_var)
end
end
}.to raise_error("Unknown variable some_var")
end
... | true |
1915867bfa2af988df047f51b72f4a476119af22 | Ruby | famished-tiger/Zenlish | /spec/zenlish/inflect/inflection_rule_spec.rb | UTF-8 | 4,060 | 2.875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../../../lib/zenlish/wclasses/common_noun'
require_relative '../../../lib/zenlish/lex/lexeme'
require_relative '../../../lib/zenlish/lex/lexical_entry'
require_relative '../../../lib/zenlish/inflect/feature_heading'
require_relative '../../../lib/zenlish/inflect/method_h... | true |
3859ca2b9705a33ddef989c82b3adc4064d63679 | Ruby | mohankapaganti/day3 | /access_specify.rb | UTF-8 | 268 | 3.34375 | 3 | [] | no_license | class A
#By default initialize method is a private
# public :This is used or comment1 is used
public
def m1
puts "Public method1"
end
def m2
puts "Public method2"
end
public :m1,:m2 #comment 1
end
a1=A.new
a1.m1 #Public method1
a1.m2 #Public method25
| true |
6cc2950ca6c0dab29ecc7f535bb92fc160afb802 | Ruby | fantasticfears/ffi-icu | /spec/transliteration_spec.rb | UTF-8 | 1,132 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: utf-8
require "spec_helper"
module ICU
describe Transliteration::Transliterator do
def transliterator_for(*args)
Transliteration::Transliterator.new(*args)
end
[
["Any-Hex", "abcde", "\\u0061\\u0062\\u0063\\u0064\\u0065"],
["Lower", "ABC", "abc"],
["en", "雙屬性集合之空間分群演... | true |
3f889bf007315eefbbeb110f4c1aa21f0998e425 | Ruby | ratamabahata/lesson_2 | /5_year.rb | UTF-8 | 606 | 3.71875 | 4 | [] | no_license | # Ввод данных
puts 'Введите день месяца'
day = gets.chomp.to_i
puts 'Введите число месяца'
month = gets.chomp.to_i
puts 'Введите год'
year = gets.chomp.to_i
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days[1] = 29 if (year % 4 == 0 && year % 100 != 0) || year % 400 == 0
number_day = days.ta... | true |
b109279c586429a1585ef895a73608f845a2b2c5 | Ruby | mespealva/patronesyciclos | /patrones.rb | UTF-8 | 1,797 | 3.515625 | 4 | [] | no_license | num = ARGV[0].to_i
def letra_o(n)
print "*" * n
puts
(n-2).times do |i|
(n).times do |j|
if j== 0 || j==(n-1)
print "*"
else
print " "
end
end
puts
end
print "*" * n
puts
end
def letra_i(n)
print "*" * ... | true |
da0f1abe484e66152bd901d80e32bb5c94ff9fc0 | Ruby | justindell/ProjectEuler | /ruby/src/problem7.rb | UTF-8 | 68 | 2.875 | 3 | [] | no_license | require 'mathn.rb'
puts "10001st Prime: #{Prime.take(10001).last}"
| true |
051658d436f548c6765e39581b791f4ac28828e7 | Ruby | JakeH91/Career-Foundry | /practice/program.rb | UTF-8 | 96 | 3.703125 | 4 | [] | no_license | def greeting
puts "Please enter your name"
name = gets.chomp
puts "Hey " + name
end
greeting | true |
38c506d2e2c3a23b68baa75a4249047578c8ad13 | Ruby | cougarsyankeesfan/ltp | /DaManT_12.rb | UTF-8 | 137 | 3.4375 | 3 | [] | no_license | # get the character at the number within the [>>>] method
da_man = 'Mr. T'
big_T = da_man[4]
puts big_T
big_T = da_man[1]
puts big_T | true |
13b72a9a00f2379842c3264808ef1039e22c69dc | Ruby | amanelis/bulldozer | /document_titles.rb | UTF-8 | 2,683 | 2.734375 | 3 | [] | no_license | require 'rubygems'
require 'thread'
require 'json'
require 'uri'
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'net/http'
require 'active_record'
require 'rails/all'
require File.expand_path(File.dirname(__FILE__) + '/models/document')
require File.expand_path(File.dirname(__FILE__) + '/models/profe... | true |
4db433dcd290c6e5505f635e487a18f07ed09ed1 | Ruby | blackmagic42/ruby-thp | /exo_16.rb | UTF-8 | 102 | 3.28125 | 3 | [] | no_license | puts"combien d'étages veux tu?"
etages=gets.to_i
for n in 0..etages
puts" "*(etages-n) +"#"*n
end | true |
c83035ad06454ec2f846503746ccb925c8dac713 | Ruby | gditrick/tpl | /helpers/integer.rb | UTF-8 | 370 | 3.25 | 3 | [] | no_license | class Integer
def second
self
end
alias :seconds :second
def minute
60.seconds*self
end
alias :minutes :minute
def hour
60.minutes*self
end
alias :hours :hour
def day
24.hours*self
end
alias :days :day
def week
7.days*self
end
alias :weeks :week
def... | true |
0ea198c553620d720bad531ae643c7db5efd85e4 | Ruby | nikhiljagtap/puppet | /lib/puppet/util/http_proxy.rb | UTF-8 | 5,951 | 2.71875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'uri'
require 'puppet/ssl/openssl_loader'
require 'puppet/http'
module Puppet::Util::HttpProxy
def self.proxy(uri)
if http_proxy_host && !no_proxy?(uri)
Net::HTTP.new(uri.host, uri.port, self.http_proxy_host, self.http_proxy_port, self.http_proxy_user, self.http_proxy_password)
else
http ... | true |
88c7327b08a32de49ada0ac496a948505f06dc5f | Ruby | lynrco/lynr.co | /lib/lynr/controller/component/authentication.rb | UTF-8 | 1,179 | 2.5625 | 3 | [] | no_license | require './lib/lynr/controller'
module Lynr::Controller
# # `Lynr::Controller::Authentication`
#
# Provide methods to determine the state of authentication, whether or
# not a valid user exists. This helps decouple authentication from
# authorization.
#
module Authentication
# ## `Authentication#au... | true |
4a66c875b8f9b16307a979b0a216eedf0361e846 | Ruby | ortizjs/algorithms_ | /LeetcodeQuestions/beautiful_arrangements_ii-667.rb | UTF-8 | 708 | 3.296875 | 3 | [] | no_license | # @param {Integer} n
# @param {Integer} k
# @return {Integer[]}
def construct_array(n, k)
res = Array(n)
idx = 0
min = 1
max = n
is_max = false
res[idx] = min
idx += 1
min += 1
while k > 1
res[idx] = max
idx += 1
max -= 1
is_max = true
k -... | true |
6a040d46fec84f3ccaa509d3adc35e656b9d6d01 | Ruby | Demeco/nor_robo_01 | /analyzer.rb | UTF-8 | 1,478 | 3.28125 | 3 | [] | no_license | # coding: utf-8
#= 解析クラス
=begin
文章を解析する働きを持つ
解析結果オブジェクト Sampleを返す
Sampleもここで一緒に定義する
=end
#require 'mecab'
require 'natto'
require_relative 'dictionary.rb'
#== 基底クラス
class Analyzer
def initialize(name,dictionaries)
@name = name
end
def analyze(input)
return ''
end
def name
return @name
... | true |
d0c1b98b901061e36d8aa1baad082eebea1d3f0e | Ruby | christophertoy/TwO-O-Player-Math-Game | /main.rb | UTF-8 | 722 | 3.921875 | 4 | [] | no_license | require "./players"
require "./questions"
p1 = Players.new("Player 1")
p2 = Players.new("Player 2")
def turn(player)
question = Questions.new()
puts "#{player.name}: #{question.ask}"
answer1 = gets.chomp.to_i
if answer1 == question.answer
puts "YES! You are correct"
else
puts "Seriously? No!"
player.re... | true |
43d04b2970a5f94a8042d58d3b12d0e39f1e2861 | Ruby | konovalov-nk/ERA | /lib/ERA/arrays/repeat_and_missing_number_array.rb | UTF-8 | 1,195 | 3.796875 | 4 | [
"MIT"
] | permissive | module ERA
module Arrays
# Original URL: https://www.interviewbit.com/problems/repeat-and-missing-number-array/
#
# You are given a read only array of n integers from 1 to n.
# Each integer appears exactly once except A which appears twice and B which
# is missing.
# Return A and B.
#
... | true |
31b896a1602f49841b76921924236bbd1e1931b9 | Ruby | moonlighters/webobots | /spec/lib/emulation_system/emulation/vector_spec.rb | UTF-8 | 2,144 | 3.265625 | 3 | [] | no_license | require 'emulation_system_helper'
describe EmulationSystem::Emulation::Vector do
before do
@v = Vector.new 2, 3
end
it "should be creatable" do
@v.x.should == 2
@v.y.should == 3
end
describe ".[]" do
it "should act as .new" do
u = Vector[@v.x, @v.y]
u.x.should == @v.x
u.y.... | true |
22780414545706091b3a6efcb957a8ec41dac064 | Ruby | softilluminationsdipak/shw | /lib/i_contact_response.rb | UTF-8 | 1,053 | 2.859375 | 3 | [] | no_license | require 'rexml/document'
class IContactResponse
attr_reader :xml, :error_code, :error_message
def initialize(body)
@xml = REXML::Document.new(body)
unless self.successful?
@error_code = xml.root.elements['error_code'].text.to_i
@error_message = xml.root.elements['error_message'].text
end... | true |
94920a34e54a041e10b385ef7d5ed4f1f07b2e2c | Ruby | colehart/HTTP | /lib/server.rb | UTF-8 | 1,053 | 3.1875 | 3 | [] | no_license | require 'socket'
class Server
def initialize(port)
@tcp_server = TCPServer.new(port)
end
def run
loop do
intro
path = gets.chomp
connection = @tcp_server.accept
request_lines = populate_lines(connection)
respond(path, request_lines, connection)
connection.close
... | true |
a29f5dff21b5526f8ce8a41d6f691f8d56f134e0 | Ruby | codequest-eu/polish_number | /lib/polish_number/classify_numbers.rb | UTF-8 | 409 | 3.53125 | 4 | [
"GPL-2.0-only",
"MIT"
] | permissive | module PolishNumber
class ClassifyNumbers
def initialize(value, digits)
@value = value.to_i
@digits = digits
end
def self.call(value, digits)
new(value, digits).call
end
def call
return :one if @value == 1
return :few if @digits && (2..4).cover?(@digits[-1]) && @dig... | true |
9c406d33e3a67f546af948f421c89c42853e8bb1 | Ruby | kidooom/ruby_traning | /highline_test.rb | UTF-8 | 552 | 3.21875 | 3 | [] | no_license | require 'highline/import'
username = ask("Enter user: ") { |q| q.echo = true }
password = ask("Enter password: ") { |q| q.echo = false }
ask("retry number?: ", Integer) { |q| q.in = 0..10 }
interests = ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
p interests
say("This should be <%= colo... | true |
acf83c787a51d3057a1d346245bde29c23ef8d92 | Ruby | zhiqiang-yu/RHOSP-deploy | /usr/share/foreman/extras/rdoc/rdoc_prepare_script.rb | UTF-8 | 1,963 | 2.75 | 3 | [] | no_license | #!/usr/bin/ruby193-ruby
verbose = false
require 'fileutils'
# Takes a list of directories and copies them, ignoring version control directories, to a new location
# It then sanitizes them by removing any circular symlinks
# It must return the new root directory for the tree
modules_root = "/tmp/puppet"
FileUtils.mkpath... | true |
722a4e1ef995f63e96b2e1c84046e54cfe0fc6ae | Ruby | ozwtkm/rails_rubyquest | /app/models/session.rb | UTF-8 | 2,442 | 2.859375 | 3 | [] | no_license | # 他のmodelとは異なり、
# SQL操作しないし実態が異なるが、
# コントローラからsessionへの操作インターフェースがmodelと類似するため、sessionhelperではなくmodelとして実装。
class Session
@@cache = nil
attr_accessor :id, :variables, :is_logined
def self.get(sessionid=nil)
if sessionid.nil?
session = Session.new()
else
cache = ... | true |
af47afcd24cabf9d65f3943ba68e508e7549f89e | Ruby | luikore/property-list | /lib/property-list/ascii_parser.rb | UTF-8 | 5,120 | 2.859375 | 3 | [
"BSD-3-Clause"
] | permissive | module PropertyList
# Parse ASCII plist into a Ruby object
def self.load_ascii text
AsciiParser.new(text).parse
end
class AsciiParser #:nodoc:
def initialize src
@lexer = StringScanner.new src.strip
end
def parse
res = parse_object
skip_space_and_comment
if !@lexer.eos?... | true |
f98db9ee1109861192f67d4a2551446b964d3e8a | Ruby | bird1204/codeSignal | /interview/Common Techniques/adv_count_inversions.rb | UTF-8 | 1,176 | 3.703125 | 4 | [] | no_license | # The inversion count for an array indicates how far the array is from being sorted. If the array is already sorted, then the inversion count is 0. If the array is sorted in reverse order, then the inversion count is the maximum possible value.
# Given an array a, find its inversion count. Since this number could be q... | true |
406999d05545f890e401abaa00549ceb8f0d1726 | Ruby | OpenRubyRMK/game-engine | /data/scripts/new_rpg_data/enemy_ability.rb | UTF-8 | 683 | 2.65625 | 3 | [] | no_license | require_relative "battler_ability"
require_relative "enemy"
module RPG
class Enemy
attr_accessor :abilities
private
def abilities_cs_init
@abilities = {}
end
def abilities_cs_to_xml(xml)
xml.abilities{
@abilities.each{|k,l| xml.ability(:name=>k,:level=>l) }
}
end
def abilities_cs_pars... | true |
4b55b5640a15c816e6ea7ff349f03b01b69979cc | Ruby | antoniofogaca/rails | /modulo/metodos/app.rb | UTF-8 | 243 | 2.859375 | 3 | [] | no_license | require_relative 'pagamento'
include Pagamento
puts "Digite a bandeira do cartão"
b = gets.chomp
puts "Digite o número do cartão"
c = gets.chomp
puts "Informe o valor"
v = gets.chomp
puts pagar(b, c, v)
puts Pagamento::pagar(b, c, v)
| true |
254ed3e61a587080868c66b67d0f2ef7f7eac5b2 | Ruby | kathryn0908/programming-univbasics-nds-green-grocer-denver-web-033020 | /grocer.rb | UTF-8 | 2,305 | 3.8125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Constants help us "name" special numbers
CLEARANCE_ITEM_DISCOUNT_RATE = 0.20
BIG_PURCHASE_DISCOUNT_RATE = 0.10
def find_item_by_name_in_collection(name, collection)
i = 0
while i < collection.length do
return collection[i] if name === collection[i][:item]
i += 1
end
nil
end
def consolidate_cart(car... | true |
a2a408dbcdb2b05171598780257f36f8bff6d95f | Ruby | jwshinx/SubscriptionCircus | /lib/address.rb | UTF-8 | 353 | 3.015625 | 3 | [] | no_license | class Address
attr_reader :address, :zip, :isactive
def initialize options={}
@address = options[:address] ? options[:address] : 'N/A'
@zip = options[:zip] ? options[:zip] : 'N/A'
@isactive = options[:isactive] ? options[:isactive] : false
end
def to_s
%Q{
address: #{@address}
zip: #{@zip}
isac... | true |
bf7c5018a5591c9d7f2aa93661c2a48df79ed55d | Ruby | chegwer/PinePractice | /ch5.rb | UTF-8 | 431 | 3.859375 | 4 | [] | no_license | #full name greeting
puts "Howdy! What's your first name?"
first = gets.chomp
puts "Thanks! How about your middle name?"
middle = gets.chomp
puts "Alright, how about your last name?"
last = gets.chomp
puts "It's nice to meet you #{first} #{middle} #{last}!"
#your favourite number is bogus
puts "What's your favourite nu... | true |
0a713e2035dd4de18892fc0bed3e25fed231802f | Ruby | Finble/ruby-kickstart | /session2/3-challenge/5_array.rb | UTF-8 | 806 | 4.5625 | 5 | [
"MIT"
] | permissive | # Write a function named mod_three which takes an array of numbers,
# and return a new array consisting of their remainder when divided by three.
# Exclude any numbers which are actually dividible by three.
#
# EXAMPLES:
# mod_three [0] # => []
# mod_three [1] # => [1]
# mod_three [2] # => [2]
# mod_three [3] # => ... | true |
97ddd456e9fbf564ece9af2cf51d76551a540433 | Ruby | jr1412594/ruby-check | /reverse_method_on_a_array.rb | UTF-8 | 126 | 2.84375 | 3 | [] | no_license | # p "Hello".reverse
# array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
# p array.reverse!
# p array
queue = [4, 8, 15, 16, 23, 42]
| true |
8388c7cf1ce658918220702e33f904f155a271ce | Ruby | jantman/puppet-facter-facts | /python_version.rb | UTF-8 | 2,069 | 2.6875 | 3 | [] | no_license | # Facter facts for python versions and paths
# https://github.com/jantman/puppet-facter-facts/blob/master/python_version.rb
Facter.add("python_default_version") do
setcode do
begin
Facter::Util::Resolution.exec('python -c "import sys; print(\'.\'.join(map(str, sys.version_info[:3])));" 2>/dev/null')
re... | true |
549f4c8f94472c6647082154525d51d122d14756 | Ruby | abhramishra/Ruby | /array.rb | UTF-8 | 157 | 3.546875 | 4 | [] | no_license | num = [9,2,55,41,22,43,66,10]
even = []
odd = []
num.each do |n|
if n % 2 == 0
even.push(n)
else
odd.push(n)
end
end
puts "#{even}"
puts "#{odd}" | true |
d2bd9ee637991539693ce952370aae31a20f80f7 | Ruby | prakriti12/lyricit | /lib/lyricit/make_it_personal.rb | UTF-8 | 512 | 2.71875 | 3 | [
"MIT"
] | permissive | module Lyricit
module MakeItPersonal
def self.get_lyrics name, artist
print "Getting Lyrics for:\nSong: #{name.strip}\nArtist: #{artist}"
return :incomplete_info if name.strip == "" || artist.strip == ""
res = Faraday.get("http://makeitpersonal.co/lyrics?artist=#{artist.s... | true |
7157d09d3f917f817fd9f724b8e8c384d4d33c2b | Ruby | jodonnell/Bankruptcy-Plan | /payment.rb | UTF-8 | 286 | 2.984375 | 3 | [] | no_license | class Payment
attr_accessor :creditor, :payment
def initialize c, p
@creditor = c
@payment = p
end
def ==(other)
@creditor == other.creditor and @payment == other.payment
end
def to_s
"#{ @creditor.name } %0.2f" % [(@payment / 100.0).round(2)]
end
end
| true |
6dfab1802210f12cdb93aa6fc8097552a1500e6a | Ruby | ruidealencar/new_feature_ruby_2.5.0 | /Remove_top_level_constant_lookup/example_1.rb | UTF-8 | 595 | 3.125 | 3 | [] | no_license | class Project
end
class Category
end
Project::Category
# Ruby 2.4
# retorna a constante de nível superior com um aviso se não for capaz de encontrar uma constante no escopo especificado.
# Isso não funciona bem nos casos em que precisamos que as constantes sejam definidas com o mesmo nome no nível superior e também ... | true |
f6b0029acc8e96d70ecfeae1e52dd9762cbb0c39 | Ruby | ramaaa22/entrega2 | /Animales/aguila.rb | UTF-8 | 121 | 2.828125 | 3 | [] | no_license | require_relative 'ave'
class Aguila < Ave
def volar
puts "vuelo"
end
def caminar
puts "camino como aguila"
end
end
| true |
1eb66795e2081544391d39035551f1b897baaed7 | Ruby | rawls/railway | /bin/update_station_list | UTF-8 | 2,621 | 3.1875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# frozen_string_literal: true
require 'nokogiri'
require 'net/http'
require 'uri'
require 'csv'
require 'yaml'
require 'pathname'
YAML_PATH = Pathname.new(__FILE__).realpath.parent.parent + 'config' + 'stations.yml'
# Updates the project's config/stations.yml with the latest data
def update_stati... | true |
580207f0da2a9082b5a15101a633604c1b68c015 | Ruby | colemandavid55/list_more | /lib/list_more/repos/lists_repo.rb | UTF-8 | 3,050 | 3 | 3 | [] | no_license | module ListMore
module Repositories
class ListsRepo < RepoHelper
def all
result = db.exec('SELECT * FROM lists').entries
result.map{ |entry| build_list entry }
end
def save list
sql = %q[INSERT INTO lists (name, user_id) VALUES ($1, $2) RETURNING *]
result = db... | true |
4f804649d1ad17a82bb630b73940c613cf7fc66e | Ruby | spheregenomics/factura2 | /app/models/entity.rb | UTF-8 | 1,371 | 2.5625 | 3 | [] | no_license | class Entity < ActiveRecord::Base
has_many :integrations, :dependent => :destroy
STATUS_ACTIVE = 'active'
STATUS_INACTIVE = 'inactive'
SYSTEM_ORACLE = 'oracle'
SYSTEM_MYOB = 'myob'
SYSTEM_PEOPLESOFT = 'peoplesoft'
SYSTEM_SAP = 'sap'
SYSTEM_OTHER = 'other'
validates :name, :address, :ph... | true |
ade0ac499e3046f3a5d7fcdf84130cd2175d8f1d | Ruby | tonynassif/square_array-cb-000 | /square_array.rb | UTF-8 | 236 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
squared_array = []
array.each { |element| squared_array.push(element ** 2) }
return squared_array
end
=begin alternate solution
def square_array(array)
array.collect! { |element| element ** 2}
end
=end
| true |
2f5fdd955ac45c4639c0293f2de630f92f7935d5 | Ruby | sebaquevedo/desafiolatam | /guia_array_hash/ejercicio5.rb | UTF-8 | 1,226 | 3.8125 | 4 | [
"MIT"
] | permissive | a = [1 ,2, 3]
b = [:azul, :rojo, :amarillo]
c = ["Tacos", "Quesadillas", "Hamburguesas"]
def put_arrays(a,b,c)
a.each_with_index do |value,index|
puts "#{value} "+ ":#{b[index]} ," +"#{c[index]}"
end
end
def put_arrays_reverse(a,b,c)
rev = b.reverse
a.each_with_index do |value,index|
puts "#{value} "+ ":#{r... | true |
f9e7f938af43a52376238c7e5e3bf8dce2c8d55c | Ruby | DaoCalendar/stardate | /app/models/grammar.rb | UTF-8 | 1,503 | 3.03125 | 3 | [
"MIT"
] | permissive | class Grammar
def self.parse(string)
date = Grammar.parse_date string.slice!(/^\d+\/\d+(\/\d+)?\s/)
tag_list = (string.slice!(/\s\[.+\]$/) || '').gsub(/(^\s\[)|(\]$)/, '')
if string =~ /^(\$|\+)/
words = string.split ' '
explicit_value = words.shift.gsub('$', '')
string = words.j... | true |
bc864594eb9eaf5e7fe8cf54e414e95eb78dc0e2 | Ruby | grantspeelman/lottoinmypocket | /db/seeds.rb | UTF-8 | 1,606 | 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 =>... | true |
8c330c50434a5911081facd530f7a1346aa76bdc | Ruby | myGrid/t2-server-gem | /bin/t2-delete-runs | UTF-8 | 3,205 | 2.734375 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
# Copyright (c) 2010-2012 The University of Manchester, UK.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyri... | true |
d8729de0412c36f52fc9b11a29a92b0b04936090 | Ruby | SuperLazyDog/Algorithm-Practise | /books/oreilly/s6_tree/practice/42.rb | UTF-8 | 1,297 | 3.734375 | 4 | [] | no_license | require 'securerandom'
class TreeNode
attr_accessor :data, :first_child, :next_sibling
def initialize(data)
@data = data
@seed = SecureRandom
end
def show
puts "show tree"
_show(self)
puts ""
end
def self.build_tree(ary)
return if ary.empty?
data = ary.shift
node = TreeNode... | true |
ee6fb033ad6cfa99a14317ff196712c3dbc4d37a | Ruby | fab9/devbootcat | /vendor/bundle/gems/tins-1.3.0/lib/tins/token.rb | UTF-8 | 893 | 3.234375 | 3 | [
"MIT"
] | permissive | module Tins
class Token < String
DEFAULT_ALPHABET = ((?0..?9).to_a + (?a..?z).to_a + (?A..?Z).to_a).freeze
#def initialize(bits: 128, length: nil, alphabet: DEFAULT_ALPHABET)
def initialize(options = {})
bits = options[:bits] || 128
length = options[:length]
alphabet = options[:al... | true |
cb2519aae69acb8cf1259075b97bfa4dafdf7e1e | Ruby | jonasschneider/fichteplan | /lib/parser.rb | UTF-8 | 1,488 | 2.828125 | 3 | [] | no_license | require 'fichte'
require 'change'
require 'nokogiri'
require 'date'
class Fichte::Parser
def initialize data = ''
@data = data
@doc = Nokogiri::HTML.parse(@data)
end
def rows
@doc.css("tr.list:not(:first-child)").map do |row|
row.css("td").map do |cell|
txt = cell.text.gsub("\302\24... | true |
a29282b73ea38228352752470aae879a4dacfa31 | Ruby | skomer/hw_w2d1 | /engine_class.rb | UTF-8 | 170 | 2.84375 | 3 | [] | no_license |
class Engine
attr_reader :speed_bonus, :fuel_usage
def initialize(speed_bonus, fuel_usage)
@speed_bonus = speed_bonus
@fuel_usage = fuel_usage
end
end | true |
e2a7e81b10361704e172d113b72c4f1f3fcde828 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/src/4319.rb | UTF-8 | 118 | 3.203125 | 3 | [] | no_license | class Hamming
def compute(strand1, strand2)
(0..strand1.length).count{|i| strand1[i] != strand2[i]}
end
end
| true |
88e7548159d68cb246311d825fbb782cc766ee54 | Ruby | VanQuishi/Connect-Four | /spec/connect_four_spec.rb | UTF-8 | 3,239 | 3.09375 | 3 | [] | no_license | require './lib/connect_four.rb'
describe Player do
describe "#is_filled_below?" do
it "check last row cell if the \'cells\' below it are filled" do
Player.empty()
user = Player.new('X')
expect(user.is_filled_below?(3,5)). to eq(true)
end
it "check a cell... | true |
de378755027fbba668278c4a2a675b4a0b12b7e7 | Ruby | ATMartin/maildump | /lib/email_processor.rb | UTF-8 | 572 | 2.53125 | 3 | [] | no_license | class EmailProcessor
def initialize (email)
puts "**********INIT THE EMAIL**********"
@email = email
end
def process
puts "******TRYING TO GET #{@email.to[0][:token]}!******"
if !Inbox.pluck(:slug).include? @email.to[0][:token].to_s
puts "******NO INBOX FOUND FOR #{@email.to[0][:token]}!**... | true |
a3898399f21386617ba9445aca34f83a1dfe220b | Ruby | mejialvarez/reto5 | /store_question.rb | UTF-8 | 443 | 3.3125 | 3 | [] | no_license | require 'csv'
require_relative 'question'
class StoreQuestion
attr_reader :questions
def initialize
@questions = []
build_questions
end
def take!
@questions.shift
end
def length
@questions.length
end
private
def build_questions
store = CSV.read('store-questions.txt').shuf... | true |
c7a011ddc88018ed186d996893b7907337b8f8eb | Ruby | dstodolny/chess | /lib/chess.rb | UTF-8 | 1,650 | 3.09375 | 3 | [
"MIT"
] | permissive | require_relative "chess/version"
require 'open-uri'
require 'pstore'
module Chess
module ChessHelper
def get_xy(san)
coordinates = {
"A" => 0, "B" => 1, "C" => 2, "D" => 3,
"E" => 4, "F" => 5, "G" => 6, "H" => 7,
"1" => 0, "2" => 1, "3" => 2, "4" => 3,
"5" => 4, "6" => 5, "7... | true |
d2028f5820946b03b27ef0a7ee57b911e59ea34c | Ruby | lekan20/Rails-Bodega | /app/models/user.rb | UTF-8 | 502 | 2.5625 | 3 | [
"MIT"
] | permissive | class User < ActiveRecord::Base
has_secure_password
has_many :user_items
has_many :items, :through => :user_items
accepts_nested_attributes_for :user_items
def cart_quantity
# Gives the total quantity of items of a user
self.user_items.sum do |user_item|
user_item.quantity
end
end
de... | true |
9f319ca2b19b67f33609712d0affc2a109ed25ce | Ruby | tommydangerous/cracking | /2/4.rb | UTF-8 | 316 | 3.59375 | 4 | [] | no_license | # Write code to partition a linked list around a value x,
# such that all nodes less than x come before all nodes
# greater than or equal to x.
require_relative "linked_list"
ll = LinkedListFactory.linked_list
nodes = ll.nodes
node = nodes[nodes.size / 2]
ll.print
p node.data
ll.partition node.data
ll.print
| true |
927cc1f89440da7caa941092a76e0f32b9f55130 | Ruby | wincent/wincent-on-rails | /app/models/tag.rb | UTF-8 | 3,825 | 2.71875 | 3 | [] | no_license | class Tag < ActiveRecord::Base
has_many :taggings
has_many :taggables, :through => :taggings
validates_presence_of :name
validates_format_of :name,
:with => /\A[a-z0-9]+(\.[a-z0-9]+)*\z/i,
:message => 'may only contain words (letters and numbers) separated by ' +
... | true |
4e34118d7e16ffd76e155e485f976cbb886fbabc | Ruby | Aerithe77/ruby | /exo_11.rb | UTF-8 | 200 | 3.375 | 3 | [] | no_license | puts "Choisi un nombre !"
print "=>"
nombre_choisi = gets.chomp.to_i
if nombre_choisi > 0
nombre_choisi.times do
puts "Salut, ça farte ?"
end
else
puts "Tu es un malin toi !"
end
| true |
d08c2c5210f742d222524d6e45cbcb76895d659d | Ruby | ChrisZou/programmingruby | /chapter18/fibonacci_sequence.rb | UTF-8 | 175 | 3.078125 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
def fibonacci_sequence
Enumerator.new do |generator|
i1, i2 = 1, 1
loop do
generator.yield i1
i1, i2 = i2, i1+i2
end
end
end
| true |
320df7abc751f1a2c991a038ca24bbac6ceb4eb7 | Ruby | FiveYellowMice/labrat | /lib/labrat/twitter_sync.rb | UTF-8 | 8,023 | 2.703125 | 3 | [] | no_license | require 'cgi'
require 'json'
require 'concurrent'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/numeric/time'
require 'twitter'
##
# Sync Twitter with Telegram channel.
class LabRat::TwitterSync
attr_reader :api
include LabRat::Util
def initialize(bot)
setup_instance_v... | true |
a821f2e939a7ed7226f974cd29eb932652e1d20e | Ruby | mevdschee/AdventOfCode2018 | /day11/part2.rb | UTF-8 | 935 | 2.953125 | 3 | [] | no_license | input = IO.read('input').chomp.to_i
size = 300
field = {}
(1..size).each do |x|
(1..size).each do |y|
rid = x + 10
num = (rid * y + input) * rid
field[[x, y]] = (num / 100) % 10 - 5
end
end
summed = {}
(1..size).each do |x|
col = 0
(1..size).each do |y|
col += field[[x, y]]
left = (summed... | true |
24d46b08a2b9f88a35c8777d8854d40f71072a55 | Ruby | spilth/l8 | /lib/l8/smartlight.rb | UTF-8 | 1,860 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'rubyserial'
module L8
class Smartlight
CMD_L8_DISP_CHAR = 0x7f
CMD_L8_LED_SET = 0x43
CMD_L8_MATRIX_OFF = 0x45
CMD_L8_MATRIX_SET = 0x44
CMD_L8_POWEROFF = 0x9d
CMD_L8_SET_LOW_BRIGHTNESS = 0x9a
CMD_L8_SET_ORIENTATION = 0x80
CMD_L8_STATUSLEDS_ENABLE = 0x9e
CMD_L8_SUPERLED_SET... | true |
336aa6e3d6d6da4ad990c535fe5fd9196168e474 | Ruby | kyletolle/everything-blog | /lib/everything/blog/source/site.rb | UTF-8 | 1,739 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'forwardable'
require_relative 'index'
require_relative 'posts_finder'
require_relative 'stylesheet'
require_relative 'page'
require_relative 'media'
module Everything
class Blog
module Source
class Site
include Everything::Logger::LogIt
def files
info_it("Reading blog so... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.