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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
0bf84cd293e335640c1998500b7a345868748e6f | Ruby | Azure/fluent-plugin-snmptrapalert | /lib/fluent/plugin/in_snmptrapalert.rb | UTF-8 | 5,563 | 2.515625 | 3 | [
"LicenseRef-scancode-generic-cla",
"MIT"
] | permissive | # snmptrapalert input plugin for fluentd.
# Plugin is specifically designed snmp traps that are generated by VLI.
# With this plugin installed, SNMP traps that are generated by VLI can be
# recieved by fluentd listener. The traps recieved by fluentd are formatted
# into a json output.
# @type ===> type of input plugin ... | true |
315d8850a429f84cd95f23cc285f346f2dca1ac2 | Ruby | ryankinderman/bookshelf | /app/extensions/rails/active_record/active_record_validates_capitalization_of.rb | UTF-8 | 920 | 2.75 | 3 | [] | no_license | module ActiveRecord
module ValidatesCapitalizationOf
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def validates_capitalization_of(*method_names)
options = method_names.pop
configuration = {:on => (options[:on] || :save)} || {}... | true |
12d6702bf1b1e4102eee17eceba33eccf64dbbb3 | Ruby | cmaher92/launch_school | /coursework/books/intro_to_programming/arrays/answers.rb | UTF-8 | 1,583 | 4.375 | 4 | [] | no_license | # 1.
# An array is an ordered list of elements that can be of any type.
# 2.
array = [1, "team", []]
# 3.
array.first
# 4.
array.last
# 5.
# Each element in an array is numbered
# 6.
array.pop
# 7.
# yes
# 8.
array.push
# 9.
array <<
# 10.
# not mutating
array.map { |n| n**2 }
# 11.
array.delete_at(3)
# 12.
... | true |
ffad90bde830b4bd35537d7c2efc0d6979b67d4d | Ruby | denis-singh/ruby | /ex-calcmethod.rb | UTF-8 | 477 | 4.125 | 4 | [] | no_license | print("Enter the 1st number: ")
num1 = Float(gets)
print("Enter the 2nd number: ")
num2 = Float(gets)
print("Enter operator (+, -, *, /)")
operator = gets
operator = operator.chomp
def calc (*args)
case args[args.length - 1]
when "+" then return args[0] + args[1]
when "-" then return args[0] - args[1]
when... | true |
1c31b59b6fb77a5043ae2ef28cfa3b0b067d55a5 | Ruby | lambdai/iyxzone | /lib/task_requirement.rb | UTF-8 | 2,793 | 2.75 | 3 | [] | no_license | class TaskRequirement
attr_accessor :val
def initialize val
@val = val
end
def init_achievement achievement, user
end
def satisfy?
end
def notify_create resource, achievement
return unless resource.is_a? @@expect_class
end
def valid?
true
end
end
class BlogMoreThanRequirement ... | true |
fefdcd906f08eea0ecd556da83a88e05fe2f4a34 | Ruby | ngLawrence2/Study-Guide | /Algorithms/Chapter_1_Arrays/string_rotation.rb | UTF-8 | 363 | 4.03125 | 4 | [] | no_license | # Assume you have a method isSubstring which checks if one word is a substring
# of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one
# call to isSubstring (e.g., "waterbottle" is a rotation of"erbottlewat").
#erbottlewaterbottle
def string_rotation(s1,s2)
return tr... | true |
2c53ed0a2a8fae565b77699a8718879be0234305 | Ruby | maxfriedrich/danger-junit | /lib/junit/plugin.rb | UTF-8 | 5,404 | 2.65625 | 3 | [
"MIT"
] | permissive | module Danger
# Report, or inspect any JUnit XML formatted test suite report.
#
# Testing frameworks have standardized on the JUnit XML format for
# reporting results, this means that projects using Rspec, Jasmine, Mocha,
# XCTest and more - can all use the same Danger error reporting. Perfect.
#
# You ca... | true |
7809d10aeeffc8bf1ef11e9c3d14114e81483e66 | Ruby | astrails/sun-ror-demo-java-image | /app/models/photo.rb | UTF-8 | 1,507 | 2.703125 | 3 | [] | no_license | class Photo < ActiveRecord::Base
include Java
BI = java.awt.image.BufferedImage
BA = java.io.ByteArrayInputStream
validates_presence_of :description
def validate
errors.add(:image_file, "Please upload image") unless binary_data
end
def image_file=(input_data)
if input_data.blank?
self.b... | true |
931c1dd1d6d49bab97b4d05e733db27994a9ba47 | Ruby | fjuribe/Repaso-Ruby | /demo_ruby/00miselanios.rb | UTF-8 | 1,203 | 3.5625 | 4 | [] | no_license | #ARRAY
# rangos
# a=(1..7).to_a
# print a
# b=(1..200)
# puts b
# for i in 0..100
# next if i%2==0
# puts i
# end
# arr = []
# arr<<"hola"
# puts arr
# arr = ["chao","bye"]
# arr.push("hola")
# arr<<"mundo"
# arr<<"good bye"
# arr.insert(0,"ciao")
# #arr.pop
# arr.delete_at(2)
# print arr
# a=[6,4,5,7,8,10,2... | true |
5b37212ad0d46a405123e4ce28a66197a4756f91 | Ruby | gniquil/mw_dictionary_api | /lib/mw_dictionary_api/client.rb | UTF-8 | 2,180 | 2.734375 | 3 | [] | no_license | # encoding: UTF-8
require 'cgi'
require 'open-uri'
module MWDictionaryAPI
class Client
class << self
def cache
@cache ||= MemoryCache
end
def cache=(cache)
@cache = cache
end
def parser_class
@parser_class ||= Parsers::ResultParser
end
def par... | true |
c2078b0948e21c0d0b1404a9d4705b56cf22605b | Ruby | stussy446/phase-0-tracks | /ruby/puppy_methods.rb | UTF-8 | 1,083 | 4.375 | 4 | [] | no_license | class Puppy
def initialize()
puts "Initializing new puppy instance..."
end
def fetch(toy)
puts "I brought back the #{toy}!"
toy
end
def speak(number)
number.times { puts "Woof!"}
end
def roll_over()
puts "*rolls over*"
end
def dog_years(human_years)
7 * human_years
end... | true |
1bd16d34f1977f8923d7e330cac11b02d691d864 | Ruby | LindaKadz/interest_calc | /app/models/calculator.rb | UTF-8 | 312 | 2.59375 | 3 | [] | no_license | class Calculator < ApplicationRecord
before_save :get_total
validates :principle, presence: true, numericality: true
validates :year, presence: true, numericality: true
validates :rate, presence: true, numericality: true
def get_total
self.total = principle * ( 1 +((rate/100) * year))
end
end
| true |
c0a5463469437ec02eef965a3726b02378a45255 | Ruby | lamronby/learning | /ruby/FORPC101/l3ex4_leap_year_mins.rb | UTF-8 | 625 | 4.34375 | 4 | [] | no_license | =begin
Exercise4. Write a method leap_year. Accept a year value from the user, check whether it's a leap year and then display the number of minutes in that year - program p017leapyearmtd.rb.
=end
def leap_year
print "Enter the year: "
STDOUT.flush
year = gets.chomp.to_i
isLeap = case
wh... | true |
dca8a5429b5823dff21f7fb57a9442bd67dc36a7 | Ruby | masonwaller/programming-univbasics-4-square-array-austin-web-102819 | /lib/square_array.rb | UTF-8 | 185 | 2.984375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
# your code here
counter=0
arrayy=[]
while counter<array.length do
arrayy<< array[counter]**2
puts arrayy
counter += 1
end
return arrayy
end
| true |
57b482a4179b09bfc27c633182dcac27ff738778 | Ruby | kuma3/Ruby-Practice | /13章/loop.rb | UTF-8 | 416 | 3.65625 | 4 | [] | no_license | list = %w(a b c d)
for i in 0..3
puts list[i]
end
list = [1, 3, 5, 7, 9]
sum = 0
for i in 0..4
sum += list[i]
end
puts "sum = #{sum}"
list = [1, 3, 5, 7, 9]
sum = 0
list.each do |i|
sum += i
end
puts "sum = #{sum}"
list = [1, 3, 5, 7, 9]
list.each_with_index do |item, i|
puts "list[#{i}] = #{item}"
end
list... | true |
bd52b48258418bd658a51523b3caff7203ffa46d | Ruby | krystal/apia-ruby-client | /lib/apia_client/request_proxy.rb | UTF-8 | 679 | 2.515625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module ApiaClient
class RequestProxy
METHOD_MAP = {
get: ApiaClient::Get,
post: ApiaClient::Post,
patch: ApiaClient::Patch,
put: ApiaClient::Put,
delete: ApiaClient::Delete
}.freeze
attr_reader :route
attr_reader :request
def initiali... | true |
8b2f44fb0c35ba06841cdde151cd16284a087b6b | Ruby | sdkraemer/foosball_app | /app/models/team.rb | UTF-8 | 2,413 | 2.671875 | 3 | [] | no_license | class Team < ActiveRecord::Base
belongs_to :game
has_many :positions, :dependent => :destroy
has_many :goals, :through => :positions
accepts_nested_attributes_for :positions, :allow_destroy => true
enum color: {blue: 0, red: 1}
scope :winner, -> {where(winner: true)}
scope :loser, -> {where.not(winner:... | true |
702c077da0433d44168311d524535ae9bc532c63 | Ruby | nekonabesan/Fundamental-Programming | /lec009/fp09_01.rb | UTF-8 | 587 | 3.140625 | 3 | [] | no_license | require 'benchmark'
require 'bigdecimal'
require 'bigdecimal/util'
require __dir__ + '/../modules/fp_module.rb'
require __dir__ + '/app/models/dog.rb'
=begin
演習 1 この例題を打ち込み動かせ。次に「ほえる」メソッド bark(引数無) と、「ほえる回数」を設
定するメソッド setcount(回数を渡す) を追加せよ。最初は 3 回ほえるものとする。
=end
def main
a = Dog.new('pochi')
b = Dog.new('tama')
p... | true |
0505cf2da5838bef95730ba2ff2d8752657d1a83 | Ruby | great-h/hirohata-reporter | /lib/hirohata/reporter.rb | UTF-8 | 4,197 | 2.640625 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require "hirohata/reporter/version"
require 'yaml'
require 'rss'
require 'date'
require 'fbgraph'
FBGraph.config # Rails HTML SanitizerのせいでRailsプロジェクトと冠ちがいしてしまうので対策
require 'active_support/all'
require 'rails-html-sanitizer'
module Hirohata
class Reporter
def self.config
YAML.load_f... | true |
fc3265260ef90934bffab7ef1f4fd653188d1052 | Ruby | btbam/pricing-tool | /app/services/importer_helper/csv.rb | UTF-8 | 1,543 | 2.703125 | 3 | [] | no_license | module ImporterHelper
# ImporterHelper::CSV
class CSV < ImporterHelper::Base
require 'csv'
def import(&block)
csv = ::CSV.open(filename, 'r:ISO-8859-15:UTF-8')
csv.shift if skip_headers
total_elapsed_time = Benchmark.realtime do
csv.each do |row|
@iterator += 1
... | true |
a52f5f3ffd29ef8eb3c967b53280a48ee17fd85c | Ruby | zooliet/daas_worker | /file_transfer/consumer.rb | UTF-8 | 1,868 | 2.75 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
require 'bunny'
require 'eventmachine'
module DAAS
class Consumer
attr_reader :broker_ip, :sleep_count
def initialize(options)
puts "Creating a consumer instance"
@broker_ip = options[:ip]
@sleep_count = options[:sleep]
end
def ... | true |
2367c9d6c98978899485227d876177baeabf6d14 | Ruby | pawelduda/codeeval-ruby-solutions | /easy/83.rb | UTF-8 | 778 | 3.65625 | 4 | [] | no_license | # https://www.codeeval.com/browse/83/
def get_string_beauty(str)
letters = Hash.new { |h, k| h[k] = 0 }
str.downcase.gsub(/[^a-z]/, '').split('').each do |l|
letters[l] += 1
end
beauty_sum = 0
beauty_inc = 26
letters.sort_by { |key, val| -val }.each do |key, count|
beauty_sum += beauty_inc * co... | true |
f04bf4a750529a1aa5648f26e23cf98da75641f6 | Ruby | jacqueline-lam/oo-meowing-cat-online-web-pt-090919 | /lib/meowing_cat.rb | UTF-8 | 316 | 4.09375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Cat
# Use attr_accessor macro to create a setter and getter method for a cat's name
attr_accessor :name
# .meow method to output "meow!" when called on an instance of Cat
def meow
puts "meow!"
end
end
maru = Cat.new
maru.name = "Maru"
maru.name
# => "Maru"
maru.meow
# "meow!"
# => nil | true |
905a8b20e7802c41b662c3cda34c41fab7ca4719 | Ruby | dan335/realms | /commands/realms.rb | UTF-8 | 1,929 | 2.703125 | 3 | [] | no_license | require './commonFunctions.rb'
def command_realms(bot, event, mongo)
str = "-] **REALMS** [- "
# find page number
page = 0
msg = event.message.content
msg.slice!(0)
arr = msg.split
if arr.length > 1
t = arr[1].to_i
if t == 0
event.respond "Page "+arr[1]+" is... | true |
02524b09630cae1e291ddc90d611427bf1df2314 | Ruby | JustinData/GA-WDI-Work | /w09/d05/Mihran/Life/lib/life.rb | UTF-8 | 428 | 3.515625 | 4 | [] | no_license | require 'pry'
class Game
def initialize
@board = Board.new
end
def board
@board
end
end
class Board
def initialize
@grid = [[],[],[],[]]
for i in 0..3 do
4.times {@grid[i].push(Cell.new)}
end
end
def grid
@grid
end
end
class Cell
def initialize
@value = [true... | true |
732e46edc320934e7a4a6d6c00f7e27b7d761490 | Ruby | vineethsubbaraya/coding_challenge | /helper/app_helper.rb | UTF-8 | 1,145 | 2.796875 | 3 | [] | no_license | module AppHelper
## Get the exclude words array
def get_exclude_words(text)
text_arr = text.downcase.split
text_arr = text_arr.uniq
arr_len = text_arr.length
exclude = []
if arr_len >1
rand_no = rand(1..arr_len)
exclude = text_arr.sample(rand_no)
end
return exclude
... | true |
2c24949eb552dd09096aef9adc7bb89132f042bd | Ruby | jbedley/SiblingRivalry | /gin_rummy/sort_network/SortNetworkTest.rb | UTF-8 | 328 | 3.421875 | 3 | [] | no_license | require "./sort10"
arr = Array.new(10)
arr.each_index {|i| arr[i] = i}
def isSorted(a)
for i in 1..a.size - 1
if a[i] < a[i-1]
return false
end
end
return true
end
perm = arr.permutation.to_a
t1 = Time.now
perm.each{ |p|
sort10(p)
puts p unless isSorted(p)
}
t2 = Time.now
puts ... | true |
190de23bdd23908ccb1bd79bbb658d028c4ee61b | Ruby | YasHartung/silicon-valley-code-challenge-nyc-web-career-042219 | /app/models/venture_capitalist.rb | UTF-8 | 1,071 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class VentureCapitalist
attr_accessor :name, :worth
@@all = []
def initialize(name, worth)
@name = name
@worth = worth
@@all << self
end
def self.all
@@all
end
def self.tres_commas_club
self.all.select do |vc|
vc.worth > 1000000000
end
end
def offer_contract (startu... | true |
6d96534f111bcd1f70a426892fe4e65c0f3c3e47 | Ruby | AugustoPedraza/TheHappyLittleBook | /lib/populator/publisers.rb | UTF-8 | 356 | 2.609375 | 3 | [] | no_license | module Populator
class Publisers
def initialize
Publiser.delete_all
end
def create!(q=25)
q.times do |i|
Publisher.create!(name: [Faker::Company.name, " publisher", i + 1].join(" "))
end
end
def self.sample
Publishers.new.create! unless Publisher.count > 0
Pu... | true |
76820ffdacc21ad30f7ae46c6f7af4601eecf3ae | Ruby | cwkarwisch/RB100_intro_to_programming | /arrays/exer_08.rb | UTF-8 | 68 | 3.359375 | 3 | [] | no_license | arr1 = [1, 2, 3]
arr2 = arr1.map { |elem| elem + 2 }
p arr1
p arr2 | true |
13c7ec3823e5aa3d7ba6ef42928fc10d5525a009 | Ruby | jmbruel/sysmlpapyrusbook | /test/checkURLs.rb | UTF-8 | 1,504 | 2.59375 | 3 | [] | no_license | require "net/http"
def url_exist?(url_string)
if (url_string != 'https://hudson.eclipse.org/papyrus/job/papyrus-sysml16-master/lastSuccessfulBuild/artifact/releng/org.eclipse.papyrus.sysml16.p2/target/repository/') && (url_string != 'https://git-scm.com')
url = URI.parse(url_string)
req = Net::HTTP.new(url.h... | true |
bd81a635c39f0de8ecc9e8ac97e88e93b41ac067 | Ruby | castromon95/bowling_scoring | /lib/bowling_line.rb | UTF-8 | 1,271 | 3.03125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Model to represent a users bowling line
class BowlingLine < Parent::Bowling
def initialize
@chances = []
end
def add_attempt(player_name, score, line)
chance = detect_chance
if finished_line(chance)
raise Error::FinishedLineError.new(line, player_name)
end
... | true |
b97278410caf542199eda09a2ee6e67601a6571f | Ruby | gabebw/refactoring-practice-metis-week-7 | /poker/deck.rb | UTF-8 | 363 | 3.484375 | 3 | [] | no_license | require "./card"
class Deck
SUITS = %w[Clubs Diamonds Hearts Spades]
NUMBERS = (1..13)
def initialize
@cards = new_batch_of_cards.shuffle
end
def take(number)
@cards.shift(number)
end
private
def new_batch_of_cards
SUITS.flat_map do |suit|
NUMBERS.map do |number|
Card.new(... | true |
f3d7e33fba5057e011487feb52596b69839fa699 | Ruby | attenbl19/ruby-oo-object-relationships-has-many-through-nyc04-seng-ft-071220 | /lib/customer.rb | UTF-8 | 833 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Customer
attr_accessor :name, :age
@@all = []
def initialize(name, age)
@name = name
@age = age
@@all << self
end
def self.all
@@all
end
def new_meal(waiter, total, tip=0)
Meal.new(self, waiter, total, tip) # creating a new me... | true |
e5727ad50450099ceaacc4e138bb5eb664cc7e0f | Ruby | jacobpatton/synchronisable | /lib/synchronisable/model.rb | UTF-8 | 2,013 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'synchronisable/model/methods'
require 'synchronisable/model/scopes'
require 'synchronisable/synchronizers/synchronizer_default'
module Synchronisable
module Model
extend ActiveSupport::Concern
module ClassMethods
SYNCHRONIZER_SUFFIX = 'Synchronizer'
# Declare this on your model class t... | true |
d7d369bb89b9d08c9830e5e9926ebb4c59e55670 | Ruby | gfx/querly | /lib/querly/script_enumerator.rb | UTF-8 | 1,557 | 2.625 | 3 | [] | no_license | module Querly
class ScriptEnumerator
attr_reader :paths
def initialize(paths:)
@paths = paths
end
def each(&block)
if block_given?
paths.each do |path|
case
when path.file?
load_script_from_path path, default_loader: Loader::Ruby, &block
... | true |
3a847e2a89604c685fac5ba262d6c2e859024c7f | Ruby | mnegesse/Bakery | /cookies.rb | UTF-8 | 479 | 3.375 | 3 | [] | no_license | class Cookies
attr_accessor :image, :name, :discription ,:price
def initialize(image, name, discription, price)
@image = image
@name = name
@discription = discription
@price = price
end
def show_Cookies
# puts "Price: "+ @price
return "Name: "+@name +"\n"+"Discription:... | true |
d16e5989264d9fd43878b5b66b26edf904c733a5 | Ruby | lavertyaf/cc_wk3_day2_hw | /console.rb | UTF-8 | 842 | 2.78125 | 3 | [] | no_license | require('pry')
require_relative('models/bounty')
options_hash1 = { 'name' => 'Laura', 'species' => 'Lizard', 'homeworld' => 'Zorg', 'fave_weapon' => 'Nunchucks'}
bounty1 = Bounty.new( options_hash1 )
options_hash2 = { 'name' => 'Ann', 'species' => 'Shark', 'homeworld' => 'Mars', 'fave_weapon' => 'Firepoi'}
bounty2 = ... | true |
86bf83070c9565eb5d660ad50657516469cc4548 | Ruby | jatranscendentalne/code_sensei_course | /pierwszy_zjazd/silnia.rb | UTF-8 | 307 | 3.984375 | 4 | [] | no_license | def silnia(n)
n == 0 ? 1: n*silnia(n-1)
end
puts "Podaj liczbę, obliczę silnię"
n = gets.chomp.to_i
puts silnia(n)
# def factiorial(n)
# result = 1
# n.times {|i| result *= i+1}
# result
# end
#
# def factiorial2(n)
# if n ==0
# 1
# else
# reutrn n*factiorial2(n-1)
# end
# end
| true |
0478b802c74dbb9f6f365becb0ee2ef15fa315d0 | Ruby | dleard/jungle-rails | /spec/models/user_spec.rb | UTF-8 | 4,447 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
describe User, type: :model do
describe 'Validations' do
it 'should save if all validations pass (first_name, last_name, email, password, password_confirmation presence = true && email uniqueness = true' do
pre_save_count = User.count
@user = User.new(:first_name => 'test', :... | true |
e2f4dd91bcba9852816d5ed2d3a9bcae57952a3b | Ruby | JesperGreen/my_group.rb | /my_group.rb | UTF-8 | 327 | 3.5625 | 4 | [] | no_license | my_group = Array.new
person_1 = {name:"Jesper", age: 22, gender: "male"}
person_2 = {name:"Jesper2", age: 33, gender: "male"}
person_3 = {name:"Jesper3", age: 44, gender: "female"}
my_group.push person_1, person_2, person_3
my_group.each do |person|
puts "#{person[:name]} is a #{person[:age]} old #{person[:gender]... | true |
2586f64e259202595c02a458d833641542c783b8 | Ruby | SebasBeen/RubyProgs | /fibonnaci.rb | UTF-8 | 161 | 3.921875 | 4 | [] | no_license | def fib(n)
x = 1
y = 1
while x <= n
puts x
y, x = x, x+y
end
end
puts fib(ARGV[0].to_i) | true |
0594aa2f8bff7b56843e86a921c75b574e39508f | Ruby | MDes41/exercism | /ruby/acronym/acronym.rb | UTF-8 | 412 | 2.953125 | 3 | [] | no_license | class BookKeeping
VERSION = 4
end
class Acronym
def self.abbreviate(phrase)
phrase.get_abbr_letters.join
end
end
class String
def get_abbr_letters
self.tr('-',' ').split.map { |word| word[0].upcase }
end
end
# class Acronym
# def self.abbreviate(string)
# require 'pry';binding.pry
# str... | true |
57757ef709e73867751347aaf730798f7cf48161 | Ruby | pfranciskoe/pk_aa_cw | /w4d5/big_o_projects/two_sum.rb | UTF-8 | 294 | 3.25 | 3 | [] | no_license |
def two_sum?(arr,target)
hash = Hash.new(false)
arr.each do |ele|
if hash[target - ele] == true
return true
else
hash[ele] = true
end
end
false
end
# arr = [1,3,4,-8,5,6,7,3,2,1]
# target = -1
# p two_sum?(arr,target)
| true |
7c1165bb60b823434f615dde32058c4a61089211 | Ruby | YukalatasKaslet/MVC_example | /Control.rb | UTF-8 | 846 | 3.203125 | 3 | [] | no_license | require_relative 'model'
require_relative 'view'
class Control
def initialize(argv_copy)
@command = argv_copy[0]
@string = argv_copy[1..-1].join(" ")
@list = List.new
@view = View.new
master
end#initialize
def master
case @command.downcase
when "index" then index
when "delete... | true |
f33cab76995a92c3ac1768b4020d7039b42ddd73 | Ruby | BJSummerfield/Projecteuler | /problem5.rb | UTF-8 | 1,480 | 4.15625 | 4 | [] | no_license | # 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
# def smallest_multiple(z)
# x = 0
# complete = false
# while complete == false
# p "#{x} = x"
# ... | true |
b94f8320fd8cdface18a59b06e773d354d986ded | Ruby | saschakala/ruby-music-library-cli-onl01-seng-ft-081720 | /lib/genre.rb | UTF-8 | 755 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre
extend Concerns::Findable
@@all = []
attr_accessor :name
attr_reader :artist
def initialize (name)
@name = name
@songs = []
end
def self.all
@@all
end
def self.destroy_all
self.all.clear
end
def save
@@all << self
... | true |
75c8c6088c6145f8d339e59a31e7e05745babed9 | Ruby | cabrerabywaters-zz/serverpp | /app/models/api/cmr/category.rb | UTF-8 | 649 | 2.71875 | 3 | [] | no_license | # Modulo que encapsula la API
module Api
# Clase para manejar las categorías como un tipo de dato valido para la API
class Cmr::Category < WashOut::Type
# Definicion de un nombre valido para la clase que pueda ser interpretado por la API
type_name 'category'
# List of attributes returned by this Class
... | true |
a1e28102dfd5e651bc84e3dac53522f5e8321419 | Ruby | white1033/ProjectEuler | /Ruby/038.rb | UTF-8 | 185 | 2.734375 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative 'euler'
(9123 .. 9876).reverse_each do |num|
if (num.to_s << (num * 2).to_s).pandigital?
puts num.to_s << (num * 2).to_s
break
end
end
| true |
1e9d58df321e5498bbc0b957a59ea2b8e803ac1b | Ruby | sarayutpea/learnrails | /udemy/13block/block.rb | UTF-8 | 742 | 4.09375 | 4 | [] | no_license | def block
#Do something in method
yield
# read all yield name
end
block do
puts "This in a first block"
end
block do
puts "THis is a decond block"
end
def add(a,b)
yield a+b
end
add(3,4){ |sum| puts sum}
def multiply(a,b)
yield a,b
end
multiply(3,5) {|a,b| puts a*b.to_f}
def run_bloc... | true |
d18d0cfaa2526fcf9b9a05d194d8791e2941449e | Ruby | irevived1/oo-cash-register-wdf-000 | /lib/cash_register.rb | UTF-8 | 612 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
class CashRegister
attr_accessor :total, :discount, :items
def initialize ( discount=0 )
@total = 0
@discount = discount
@last = 0
@items = []
end
def add_item (title , price , quantity = 1 )
#@last = ( price * quantity)
@total += @last =( price * quantity)
quantity.times do
@items << title
... | true |
f85276e59b4a9bdd71dcc33d5661df64ce954c21 | Ruby | simonovich88/arrays-challenges-program---ruby | /filtro_procesos.rb | UTF-8 | 213 | 2.6875 | 3 | [] | no_license | data = File.open('procesos.data').readlines.map(&:chomp)
data.map! {|x| x.to_i}
filter_number = ARGV[0].to_i
output = data.select {|x| x > filter_number}
File.write('procesos_filtrados.data',output.join("\n")) | true |
d0894248b3974a396210688793d68724a639fa57 | Ruby | jamesjefferies/energy-sparks_analytics | /lib/dashboard/data_sources/area_names.rb | UTF-8 | 2,636 | 2.640625 | 3 | [
"MIT"
] | permissive | class AreaNames
def self.key_from_name(name)
AREA_NAMES.each do |key, area_data|
return key if name.downcase.include?(key.to_s)
end
nil
end
def self.check_valid_area(area)
AREA_NAMES.each_value do |area_data|
return true if area_data[:name] == name
end
end
def self.temperatur... | true |
f41fbc05f687d0833ea350e33cf1eb7859861216 | Ruby | dvanetten03/rbnd-toycity-part3 | /lib/transaction.rb | UTF-8 | 711 | 3 | 3 | [
"MIT"
] | permissive | class Transaction
attr_reader :id, :customer, :product
@@id = 1
@@purchases = []
def initialize(customer, product)
@id = @@id
@@id += 1
@customer = customer
@product = product
add_transaction
end
def self.all
@@purchases
end
def self.find(id)
@@purchases.find {|t| t.id ==... | true |
f1bb6a803e1814f7a6b98cff4f301e23e8b38d20 | Ruby | snejku/codility-solutions | /NumberOfDiscIntersections.rb | UTF-8 | 560 | 3 | 3 | [] | no_license | def solution(a)
# write your code in Ruby 1.9.3
segments = []
result = 0
a.each_with_index do |e, i|
segments << [i-e, i+e]
end
segments.sort! { |a,b| a[0]<b[0] ? -1 : 1 }
segments.each_with_index do |e, i|
l = i + 1
r = a.length
while l<r do
m = (... | true |
12b6469c51a3efed8d6f86b682392f21f1d741ca | Ruby | darrin-wortlehock/dorb | /lib/dorb/core_ext/hash.rb | UTF-8 | 341 | 2.671875 | 3 | [
"MIT"
] | permissive | class Hash
def stringify_keys
dup.stringify_keys!
end
def stringify_keys!
keys.each do |key|
self[key.to_s] = delete(key)
end
end
def symbolize_keys
dup.symbolize_keys!
end
def symbolize_keys!
keys.each do |key|
self[(key.to_sym rescue key) || key] = delete(key)
end... | true |
23da5c12d8921accaf9313cdfcb334a7e1652401 | Ruby | foberleitner/advent-of-code | /2016/puzzle03/puzzle03-step01.rb | UTF-8 | 476 | 3.625 | 4 | [] | no_license | #!/usr/bin/env ruby
if ARGV.size.zero?
puts 'Please provide path to input file'
exit 1
end
def tri_valid?(tri)
if (tri[0] + tri[1]) > tri[2] &&
(tri[0] + tri[2]) > tri[1] &&
(tri[1] + tri[2]) > tri[0]
return true
end
false
end
valid_tris = 0
total = 0
open(ARGV[0]) do |file|
file.readlines.... | true |
889a4c9ebb46e9bf3e82bcc2592f124d61e1a636 | Ruby | sienna-kopf/market_2005 | /lib/vendor.rb | UTF-8 | 488 | 3.40625 | 3 | [] | no_license | class Vendor
attr_reader :name,
:inventory
def initialize(name)
@name = name
@inventory = Hash.new(0)
end
def check_stock(item)
@inventory[item]
end
def stock(item, amount)
@inventory[item] += amount
end
def potenital_revenue
@inventory.reduce(0) do |total_price, (i... | true |
bdba94fab29ec99c25cd9762373f825b76af2040 | Ruby | afifsohaili/mcd-cosi | /lib/time_formatter.rb | UTF-8 | 456 | 3.1875 | 3 | [] | no_license | module TimeFormatter
def formatted_current_time current_time
"#{current_hour(current_time)}:#{current_minute(current_time)}:#{current_second(current_time)}"
end
def current_hour current_time
current_time / (Restaurant.MINUTES * Restaurant.SECONDS)
end
def current_minute current_time
(current_tim... | true |
79915e93a22db3c9a299a397db400da11873e2fa | Ruby | kristynp/regex-lab-online-web-sp-000 | /lib/regex_lab.rb | UTF-8 | 667 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def starts_with_a_vowel?(word)
scan = word.scan(/\b[aeiouAEIOU]\w*/)
if word == scan[0]
true
else
false
end
end
def words_starting_with_un_and_ending_with_ing(text)
scan = text.scan(/(\b[uning][ing]\w*)/)
scan.flatten
end
def words_five_letters_long(text)
scan = text.scan(/(\b\w{5... | true |
e1b678e79a843461e6cc5a456d311692821f1d76 | Ruby | pixulainen/programming-univbasics-nds-nds-to-insight-understand-lab-london-web-010620 | /lib/nds_explore.rb | UTF-8 | 481 | 2.890625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | $LOAD_PATH.unshift(File.dirname(__FILE__))
#require 'ç'
# Call the method directors_database to retrieve the NDS
require 'pp'
require 'directors_database'
require 'pry'
def pretty_print_nds(nds)
# Change the code below to pretty print the nds with pp
pp nds
end
def print_first_directors_movie_titles
spielberg_m... | true |
f48e6df9fa08700a4e073eaccc1171c2d472476a | Ruby | iamYPD/todo_list | /spec/features/todo_lists/edit_spec.rb | UTF-8 | 1,946 | 2.796875 | 3 | [] | no_license | require 'spec_helper'
describe "Editing todo lists" do
let!(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery list.") }
def update_todo_list(options={})
options[:title] ||= "New title"
options[:description] ||= "New description"
todo_list = options[:todo_list]
visit "/todo_lists"
... | true |
285a500a6caf4770d196cb2184e6da5b0a541546 | Ruby | walerian777/dice | /lib/dice/roller.rb | UTF-8 | 366 | 3.0625 | 3 | [
"MIT"
] | permissive | module Dice
class Roller
attr_reader :count, :faces
def initialize(args = {})
args = defaults.merge(args)
@count = args[:count]
@faces = args[:faces]
end
def call
count.times do
puts roll
end
end
def roll
rand(1..faces)
end
def defaults
... | true |
cb936bd65c2e772a419ef8c5e555ad7a36a3cfc3 | Ruby | ytti/netcrawl | /lib/netcrawl/dns.rb | UTF-8 | 1,446 | 2.890625 | 3 | [] | no_license | require 'resolv'
class NetCrawl
class Resolve
# @param [String] name DNS name which we try to resolve to IP
# @return [String, nil] string if name resolves to IP, otherwise nil
def getip name
if @cacheip.has_key? name
@cacheip[name]
else
ip = nil
begin
if CFG... | true |
98d8f196c6b019415fa11a2a85d32bf0e5439ca5 | Ruby | morgoth/saps | /app/models/round.rb | UTF-8 | 464 | 2.5625 | 3 | [] | no_license | class Round < ActiveRecord::Base
belongs_to :league
has_many :matches, :dependent => :destroy, :order => :hour
validates :name, :presence => true, :uniqueness => {:scope => :league_id}
def pause_team
if league.with_pause? && all_matches_in_round?
(league.teams - matches.map { |m| [m.home_team, m.vis... | true |
b4bd281976c35dbace99c6aadc6daba9ab7fbea9 | Ruby | wellenteng/ruby_note | /class.rb | UTF-8 | 2,337 | 3.578125 | 4 | [] | no_license | # -*- coding: utf-8 -*-
#类型首字母大写
class Song
#对象创建后,用于初始化对象的值
def initialize name, artist, duration
#实例变量前面加@, 局部变量和参数变量首字母小写
@name = name
@artist = artist
@duration = duration
end
#覆盖默认的to_s方法
def to_s
# ‘#'可以把实例变量插入字符串
"Song: #@name--#@artist(#@duration)"
end
end
#-------------... | true |
b4039f59dcffcee6ee05ee5ae276430265ba4a22 | Ruby | youmts/depot | /app/models/cart.rb | UTF-8 | 461 | 2.671875 | 3 | [] | no_license | class Cart < ApplicationRecord
has_many :items, -> { order "id" }, class_name: "CartItem", foreign_key: :cart_id, dependent: :destroy
def add_product(product_id)
current_item = items.find_by_product_id(product_id)
if current_item
current_item.quantity += 1
else
current_item = items.build(pr... | true |
28d90b6c32b21242d8efd780cd4116458efd9218 | Ruby | wenbo/rubyg | /sample/CHAPTER05/054/unicode.19.rb | UTF-8 | 185 | 2.5625 | 3 | [] | no_license | # -*- coding: utf-8 -*- # nodisp
"\u3042\u3044" # => "あい"
"\u{3042}\u{3044}" # => "あい"
s = "\u{3042 3044}" # => "あい"
s.encoding # => #<Encoding:UTF-8>
| true |
ce3fdc17aff2a092079026cdabe5d52eb38bf844 | Ruby | endymion/flatbot | /lib/flatbot/inspect.rb | UTF-8 | 5,340 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'csv'
require 'awesome_print'
require 'google_maps_service'
require 'daybreak'
require 'liquid'
class Flatbot
def inspect(start, finish)
route_name =
@options['name'] ||
"#{Flatbot::Coordinate.filename_from_string(start)}-to-" +
"#{Flatbot::Coordinate.filename_from_string(finish)}"
... | true |
ef70eef68a442dbb573de4871670e8965721b0e1 | Ruby | Putterhead/Code-Wars | /CW_plural.rb | UTF-8 | 1,018 | 4.40625 | 4 | [] | no_license | # Description:
# We need a simple function that determines if a plural is needed or not.
# It should take a number, and return true if a plural should be used
# with that number or false if not. This would be useful when printing
# out a string such as 5 minutes, 14 apples, or 1 sun.
# You only need to worry about... | true |
1a8d46202ef41694fdec54a2336b3cba404ec5e3 | Ruby | atalasluis/fizzbuzz_sinatra-Ruby | /app.rb | UTF-8 | 230 | 2.546875 | 3 | [] | no_license | require 'sinatra'
require './lib/fizzbuzz.rb'
get '/' do
erb :principal
end
post '/generar' do
numero_ingresado = params[:numero_ingresado]
@resultado_fizzbuzz = fizzbuzz(numero_ingresado.to_i)
erb :resultado
end | true |
324c2a673ef9fe184279e3df73f02b1b185cd771 | Ruby | apicollective/apibuilder | /script/upload | UTF-8 | 4,775 | 2.515625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Uploads all of the API Json files in this repo to API Builder. By default,
# we upload the json files in the 'spec' directory
#
# Usage:
#
# Upload latest development versions based on git tag. This works by
# finding the next version (using sem-info tag next),
#
# upload
#
# Upload specifi... | true |
c4be722341b0b4962fb80e0985ef59229d3f3f61 | Ruby | audramatar/daily_programming | /metro_trip_planner/tree.rb | UTF-8 | 1,053 | 3.6875 | 4 | [] | no_license | require 'byebug'
class Node
attr_accessor :value, :left, :right, :name
def initialize(options={})
@value = options[:value]
@name = options[:name]
end
def children
[@left, @right].compact
end
def children?
@left && @right
end
def no_children?
!children?
end
end
class BinaryTre... | true |
03c724f8234da3f0edb483d1f9f726efa85c17e0 | Ruby | qtlwlv/precourse | /Chap6b.rb | UTF-8 | 630 | 3.609375 | 4 | [] | no_license | #My rendition
line_width=40
puts 'Table of Contents'.center(line_width)
puts
puts ('Chapter 1: Getting Started'.ljust(line_width) + 'page 1'.rjust( line_width))
puts ('Chapter 2: Numbers'.ljust(line_width) + 'page 9'.rjust( line_width))
puts ('Chapter 3: Letters'.ljust(line_width) + 'page 13'.rjust( line_width))
... | true |
4654ba7b026660e17646b08ca0e3b621973efa55 | Ruby | cmu-is-projects/uif2013 | /app/models/household.rb | UTF-8 | 2,064 | 2.875 | 3 | [] | no_license | require 'uri'
require 'net/http'
require 'net/https'
require 'json'
class Household < ActiveRecord::Base
attr_accessible :active, :church, :city, :insurance_company, :insurance_number, :lat, :lon, :name, :street, :street2, :zip
before_save :create_map_link
# Relationships
has_many :guardians
has_many :stud... | true |
3144ba7d640ba4d9997ed60c716624e5f5f606d5 | Ruby | MahmoudAgamy/sql-library-lab-nyc-web-111918 | /lib/querying.rb | UTF-8 | 1,347 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
"
SELECT books.title, books.year
FROM books
JOIN series
ON books.series_id = series.id
WHERE series_id = (SELECT MIN(ID) FROM series)
ORDER BY series.id
;"
end
def select_name_and_motto_of_char_with_longest_motto
"
SELECT name, motto
... | true |
5f5f50fa9f615fadbc2102c970f89a44c9f47fbc | Ruby | HOAP/esbi | /app/helpers/report_helper.rb | UTF-8 | 2,798 | 2.703125 | 3 | [] | no_license | module ReportHelper
@@audit_ranges = [(0..7), (8..14), (15..19), (20..40)]
def audit_class(score, level)
if @@audit_ranges[level].include?(score)
"audit_level a#{level}"
else
"audit_other"
end
end
def ldq_suggestion(score)
case score
when 0
"…you have control over ... | true |
43df3c1d8f3941e399a1c21c7aa60e207cfb1430 | Ruby | rayning0/codility | /07-4-nesting.rb | UTF-8 | 271 | 3.390625 | 3 | [] | no_license | # like 7-1, but don't need stack
def solution(s)
parens = 0
s.split('').each do |char|
if char == '('
parens += 1
else
parens -= 1
return 0 if parens < 0 # fails without this line
end
end
if parens == 0
1
else
0
end
end | true |
5f5de12329dc1fcca20e308428391728f4b18b78 | Ruby | trn-malyy/ita | /hw_23/lib/script_23_06_A.rb | UTF-8 | 1,350 | 3.65625 | 4 | [] | no_license | # ========================================================================
# Script = script_23_06_A.rb
# ========================================================================
# Description = "The script in accepting path as an argument, reads through file
# collects numeric values an... | true |
21672f52998ed35c96e422fb8a5d72816b5a3da5 | Ruby | jenn-jenn/AppAcademyPrep | /AppAcademy/iterationExercises.rb | UTF-8 | 1,737 | 4.8125 | 5 | [] | no_license | # Loop through all the numbers, stopping when you encounter a number that is (a) >250 and (b) divisible by 7. Print this number down!
def loopingNumbers
i = 251
while i > 250
if i % 7 == 0
puts i.to_s
break
end
i += 1
end
end
# Print out all the factors for each of the numbers 1 through ... | true |
9448383691df88ceb3e8d2b896388ec49514a854 | Ruby | kirkland/simple_todo | /commands.rb | UTF-8 | 1,330 | 2.984375 | 3 | [] | no_license | class Commands
class << self
def process(global_opts, cmd_opts, cmd, rest)
@global_opts = global_opts
@cmd_opts = cmd_opts
@cmd = cmd
@rest = rest
case @cmd
when 'list', 'l'
list
when 'add', 'a'
add
when 'complete', 'c'
complete
... | true |
93cee9fa2ddf1746bcb63e5b4d3d64b0bf55b4c8 | Ruby | muhammedimtiyaz/W2D1 | /Chess/Piece.rb | UTF-8 | 723 | 3.328125 | 3 | [] | no_license | require_relative "Board"
class Piece
attr_accessors :color, :board, :pos
def initialize(color, board, pos)
@color = color
@board = board
@pos = pos
end
def empty?
color.nil?
end
def valid_moves
# x1, y1 = pos
# x2, y2 = diff
# new_pos = ... | true |
1126bfb073ef7b00958b03a8125501f38026e2b7 | Ruby | abroccoli/wdi_10_ruby_enumerable | /lib/enum/nested.rb | UTF-8 | 1,180 | 3.59375 | 4 | [] | no_license | # Don't modify the Person class
class Person
attr_accessor :name, :age, :gender, :years_language_experience, :favorite_foods
def initialize(name:, age:, gender:, years_language_experience:{}, favorite_foods:[])
@name = name
@age = age
@gender = gender
@years_language_experience = years_language_exp... | true |
c93c00647f6a746dd58684c617b5df887cc9ea7e | Ruby | bangn/family-tree | /spec/program/presenter_spec.rb | UTF-8 | 3,201 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
require "faker"
require "models/person"
require "program/command"
require "program/presenter"
RSpec.describe Presenter do
describe "#present" do
context "when present #{Command::ADD_CHILD} result" do
context "when succeeded" do
it "outputs CHILD_ADDITION_SUCCEED" do
... | true |
54f948e96ec923b1690225e3250164282ea33b1c | Ruby | jdreiser1/ShortcutsApp | /app/models/user.rb | UTF-8 | 619 | 2.640625 | 3 | [] | no_license | class User < ApplicationRecord
has_many :favorites
has_many :hotkeys, through: :favorites
def get_sorted_favorites
@sort_favorites = {}
programs = []
self.favorites.each do |favorite|
if !(programs.include?(favorite.hotkey.program))
programs << favorite.hotkey.program
end
end
... | true |
84018c892c07bf4e628bf5d2c2c75f00ddea3d87 | Ruby | matt-thomson/tdd-raspberry-pi | /lib/cash_register.rb | UTF-8 | 234 | 3 | 3 | [] | no_license | class CashRegister
def initialize(display, coin_slot)
@display = display
@coin_slot = coin_slot
end
def tick
coin = @coin_slot.inserted_coin
if coin > 0
@display.show("Credits: #{coin}")
end
end
end | true |
9f5bfd3cbdbc771444654a7fe39bf845fe25f018 | Ruby | rintaronakamura/LightningTalks | /encryption_decryption/sample_2.rb | UTF-8 | 1,078 | 3.921875 | 4 | [] | no_license | #
# Sample code to encrypt with inputed_key
#
# plaintext : 平文.
# cryptogram : 暗号文.
# calculation_result : 足し算した後のascii_codeの値を一時的に格納.
#
# TODO: unpack/pack の c* について調べる.
# 入力.
puts "平文を入力して下さい (例. OLIVA)"
plaintext = gets.chop # 文字列の最後に打ったキャリッジリターンが入るので chop で取り除く.
puts "鍵を入力して下さい (例. 345)"
secret_key = gets.chop.sp... | true |
9f239786fd5f8c872cd9e1e8905f0eab8582d52e | Ruby | CheukLeung/FlogReporter | /work/jobs/Ruby_test/workspace/sigpa/linx4py/sigpa.rb | UTF-8 | 1,680 | 2.640625 | 3 | [] | no_license | #!/bin/env ruby
$: << File.dirname(__FILE__)
$: << File.join(File.dirname(__FILE__), "..", "lib")
require 'pp'
require 'user'
require 'front'
require 'back'
# This a C-to-Python signal parser.
#
# Expected input is signal description files written in C (usually with
# .h and .sig extensions).
#
# The output is a fil... | true |
ba83fe2cb68b3d24ad3585734c2dea2e07f658c5 | Ruby | terrybu/AlgorithmsCodingPractice | /Ruby/findcowandbull.rb | UTF-8 | 770 | 4.5625 | 5 | [] | no_license | =begin
-There are two arrays of integers. Try to find cow and bull.
Bull here means the same two numbers which are at the same index in those two arrays.
And cow means the same two numbers which are not at the same index.
For instance,
array1 = [1,4,9]
array2 = [1,9,6]
so the bull is [1]
and the cow is [9]
=... | true |
276c905addbd06f4aeddf455f2e8aed12b9262a7 | Ruby | bdurand/active_record_query_counter | /lib/active_record_query_counter.rb | UTF-8 | 5,565 | 2.546875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Everything you need to count ActiveRecord queries and row counts within a block.
#
# Usage:
#
# ActiveRecordQueryCounter.count_queries do
# yield
# puts ActiveRecordQueryCounter.query_count
# puts ActiveRecordQueryCounter.row_count
# end
module ActiveRecordQueryCounter
clas... | true |
622ff5bf3cb0b9268c9ab4a358153e646a01f6e7 | Ruby | crest-cassia/oacis_module | /lib/OACIS_module_base.rb | UTF-8 | 1,291 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'json'
class OacisModule
WAIT_INTERVAL = 5
def initialize(input_data)
raise "IMPLEMENT ME"
end
def run
@num_iterations ||= 0
loop do
$stdout.puts "Iteration: #{@num_iterations}"
wait_runs( generate_runs )
evaluate_runs
@num_iterations += 1
dump_serialized_da... | true |
a5df11fc484f15b04c1108092f72e42c954d5a70 | Ruby | nibynic/draftable | /test/logger_test.rb | UTF-8 | 1,125 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
require "spy"
module Draftable
class LoggerTest < ActiveSupport::TestCase
test "it logs messages only if loggin is enabled" do
debug_spy = Spy.on(Rails.logger, :debug)
format_spy = Spy.on_instance_method(Draftable::Logger, :format_message).and_return("formatted message")
... | true |
b6dd78d098cd61a15beeeab29a1af7bd0fa9f5de | Ruby | garethdevans/markupmorphic | /lib/repository/repository.rb | UTF-8 | 511 | 2.796875 | 3 | [] | no_license | require 'rubygems'
require 'couchrest'
require 'log4r'
require File.join(File.dirname(__FILE__), '..', '..','env')
class Repository
def initialize(logger = Log4r::Logger['MainLogger'])
@logger = logger
@db = CouchRest.database($env[:couchdb_url])
end
def setup_database!
@db.create!
end
def dele... | true |
74e8dea6596e4947c67ad073d74b3848310c5004 | Ruby | mzabala1/244smzabala1 | /seguimiento/clase28/gets02.rb | UTF-8 | 85 | 3.34375 | 3 | [] | no_license |
print "Escribe su nombre: "
nombre = gets.chomp
puts "Buenos dias " + nombre + "."
| true |
0d3438b92930b122b33c895e5f18c1e8489972c0 | Ruby | couchrest/couchrest_extended_document | /lib/couchrest/mixins/properties.rb | UTF-8 | 4,568 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | require 'time'
require File.join(File.dirname(__FILE__), '..', 'property')
require File.join(File.dirname(__FILE__), '..', 'casted_array')
module CouchRest
module Mixins
module Properties
class IncludeError < StandardError; end
def self.included(base)
base.class_eval <<-EOS, __F... | true |
76d640f561ddb085e8255354dcae036b530ef5b1 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/rna-transcription/1e326ca940334e88988a59055f0702cd.rb | UTF-8 | 404 | 3.4375 | 3 | [] | no_license | class Complement
@@dna_to_rna = {
"G" => "C",
"C" => "G",
"T" => "A",
"A" => "U"
}
def self.of_dna(strand)
strand_complement(strand, @@dna_to_rna)
end
def self.of_rna(strand)
strand_complement(strand, @@dna_to_rna.invert)
end
def self.strand_complement(strand, translation_table)
strand.cha... | true |
b4f297192af12cf095b881f31fab2e81bc1a51cc | Ruby | robt1019/introduction-to-programming | /hashes/hash_contains.rb | UTF-8 | 130 | 3.0625 | 3 | [] | no_license |
person = {
name: 'David',
occupation: 'Welderer'
}
puts person.has_value?('Welderer')
puts person.has_value?('Carpenteuse') | true |
9ea3a8ebf7954bdb4128592bd35432121a4d4ba3 | Ruby | dakshapatel/parrot-ruby-v-000 | /parrot.rb | UTF-8 | 163 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Create method `parrot` that outputs a given phrase and
# returns the phrase
def parrot(default_phrase= "Squawk!" )
puts default_phrase
default_phrase
end
| true |
f20d6d0d13208589ec1d1aa17496271b0a133166 | Ruby | thomasvds/flaresights | /db/dev_seeds.rb | UTF-8 | 3,241 | 2.53125 | 3 | [] | no_license | Agent.destroy_all
Event.destroy_all
# Generate random employees
url = "https://randomuser.me/api/"
uri = URI.parse(url)
50.times do |i|
response = Net::HTTP.get(uri)
results = JSON.parse(response)["results"]
name = "#{results[0]["name"]["first"].capitalize} #{results[0]["name"]["last"].capitalize}"
picture_ur... | true |
52cc5d61a38aab66807705447e4d47fec434aaee | Ruby | kellyfelkins/team_effort | /lib/team_effort.rb | UTF-8 | 1,656 | 2.65625 | 3 | [
"MIT"
] | permissive | require_relative "team_effort/version"
module TeamEffort
def self.work(enumerable, max_process_count = 4, progress_proc: nil)
pids = []
arg_sets = []
previous_proc_result = nil
max_count = enumerable.count
completed_count = 0
enumerable.each do |arg_set|
while pids.size == max_process... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.