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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e3da7f180b44e326e48b6bb8df07b395952c1eef | Ruby | kmcgrevey/backend_module_0_capstone | /day_7/caesar_cipher.rb | UTF-8 | 758 | 3.90625 | 4 | [] | no_license | # caesar_cipher.rb
# user inputs
print "Enter your message: "
message = gets.chomp.upcase
print "Enter the shift: (+ or -) "
shift = gets.chomp
@shift = shift.to_i
puts "#{message} <-- your original message"
# turn messsge into array of all capitals
message_array = message.upcase.split("")
# establishing the a... | true |
29d482302eb2bcded2a97dcd96c0014c2b2393b1 | Ruby | DanielSLew/Ruby_Small_Problems | /Foundations/Easy8/convert_num_to_rev_array.rb | UTF-8 | 672 | 4.15625 | 4 | [] | no_license | # Write a method that takes positive int as an arg
# Returns that num with digits reversed
# No leading 0's
# Initialize a result_num
# Initialize a count start from 0
# Call Integer#digits on the number to get a reversed array
# Iterate through the digits backwards
# If the number is 0 and the count is 0, next
# Else... | true |
fe24d92e88e7b7e6b5781a32020b9e965c99aa1f | Ruby | KrakenHH/ruby | /rubyBuildBlocks/stockPicker/stockPicker.rb | UTF-8 | 374 | 3.4375 | 3 | [] | no_license | def stock_picker(stocks)
max_difference = 0
for n in 0..stocks.length-1
differences = []
for z in 0...n
differences << (stocks[n] - stocks[z])
end
unless differences.max.nil?
if differences.max > max_difference
max_difference = differences.max
end
end
end
return max_difference
e... | true |
c9b25e7ab2cf6587fc0d0ddc8dfd983bbbeedc62 | Ruby | sittercity/bureaucrat | /lib/bureaucrat/fields/currency_field.rb | UTF-8 | 1,865 | 2.75 | 3 | [
"MIT"
] | permissive | #--
# @copyright This file is copyright (C) 2000-2012 by Sittercity, Inc.
# All rights reserved.
# All Sittercity source code is CONFIDENTIAL and
# not for distribution or unauthorized use.
# For license information contact Sittercity, Inc.
#++
require 'bureaucrat'
requi... | true |
0b6557d8642935c5b999eae331719c9152fd0d3e | Ruby | everaldobass/cursos-digitalinnovation.one | /curso-ruby/Tipo-variaveis/2.1-string.rb | UTF-8 | 234 | 3.3125 | 3 | [] | no_license | # String em Ruby
nome = "Everaldo"
sobrenome = "Nascimento"
menssagem1 = "Bem vindo! #{nome} "
puts menssagem1
menssagem2 = <<~ TXT
é uma menssagem.
TXT
puts menssagem2
menssagem3 = %q( bem vindos ao meu programa #(nome) ) | true |
a2c0bfdb90489255a256e7febf9f4c3397da8413 | Ruby | lishulongVI/leetcode | /ruby/36.Valid Sudoku(有效的数独).rb | UTF-8 | 12,401 | 3.3125 | 3 | [
"MIT"
] | permissive | =begin
<p>Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits <co... | true |
eb2450f29ca76145be89403a61c93e4757913616 | Ruby | wil310031/thp_ruby | /day2/exo_5.rb | UTF-8 | 101 | 3.296875 | 3 | [] | no_license | puts "Entrer un nombre : "
number = gets.chomp.to_i
number.times do
puts "Salut, Ca farte ?"
end | true |
a5e80b4494e19e36c71741ad561c8ae378a11b3a | Ruby | mindplace/reddit_comments_gem | /lib/reddit_comments.rb | UTF-8 | 1,890 | 2.9375 | 3 | [
"MIT"
] | permissive | require "reddit_comments/version"
require 'net/http'
require 'open-uri'
require 'json'
module RedditComments
class IncorrectLinkFormat < StandardError; end
def self.retrieve(link)
comments = GetComments.new(link)
comments.retrieve
end
class GetComments
attr_accessor :url, :comments, :request, :po... | true |
68fc33b2ee3718acb5e827b699dd271d33dad358 | Ruby | KyleDorseyDBC/phase-0-tracks | /ruby/hangman.rb | UTF-8 | 3,239 | 4.125 | 4 | [] | no_license | # HANGMAN
class Hangman
attr_reader :remaining_guesses
attr_accessor :correct_answer
def initialize
@correct_answer = ''
@guess_count = 0
@guessed_array = []
@remaining_guesses = 0
end
def word_to_guess(word)
@correct_answer = word.split('')
@remaining_guesses = @... | true |
749043956526516fd4dbcfcd58bced4fe6fbc465 | Ruby | elbereth007/et-c9-flixter | /app/models/section.rb | UTF-8 | 747 | 2.828125 | 3 | [] | no_license | # firehose track 4, lesson 17 - file created 16 jun 17 for sections
class Section < ApplicationRecord
belongs_to :course
# added 17 jun 17 for lessons
has_many :lessons
# next 2 lines added 5 jul 17 for reordering sections (lesson/challenge 32)
include RankedModel
ranks :row_order, with_same: :course_id
... | true |
4a111062098d48394d0fcd869305dc1c43412efe | Ruby | sherryptk/oxford-comma-v-000 | /lib/oxford_comma.rb | UTF-8 | 202 | 3.03125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def oxford_comma(array)
if array.size > 2
last = array.pop
array.each do |fruit|
fruit << (", ")
end
array << "and " + last
array.join
else array.join(" and ")
end
end
| true |
cc4768422df0a8bcee78f9b4f8bd22bb01f36dbf | Ruby | nbdavies/phase-0 | /week-5/calculate-mode/my_solution.rb | UTF-8 | 2,767 | 4.0625 | 4 | [
"MIT"
] | permissive | # Calculate the mode Pairing Challenge
# I worked on this challenge with Sean Massih
# I spent 0.75 hours on this challenge.
# Complete each step below according to the challenge directions and
# include it in this file. Also make sure everything that isn't code
# is commented.
# 0. Pseudocode
# What is the input?... | true |
59a9ff9307db65c90a2601c9cc7de67acd5b364a | Ruby | arirusso/alsa-rawmidi | /lib/alsa-rawmidi/input.rb | UTF-8 | 3,979 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module AlsaRawMIDI
# Input device class
class Input
include Device
attr_reader :buffer
#
# An array of MIDI event hashes as such:
# [
# { :data => [144, 60, 100], :timestamp => 1024 },
# { :data => [128, 60, 100], :timestamp => 1100 },
# { :data... | true |
3f28dd8cd43b992874a99e16fb247cf6e6103cac | Ruby | sergioazevedo/argentum-ruby | /lib/argentum/indicador.rb | UTF-8 | 1,078 | 2.640625 | 3 | [] | no_license | module Argentum
module Indicador
#simples
#---------------------------------------------------------------
FECHAMENTO = Proc.new{ |posicao,serieTemporal,block| serieTemporal[posicao].fechamento }
ABERTURA = Proc.new{ |posicao,serieTemporal,block| serieTemporal[posicao].abertura }
VOLUME = P... | true |
d4500fd16bbfb27038ca8d9b1757a9156c9995f6 | Ruby | Salsa-Dude/review-flatiron | /Mod-1/Enumerables/bonus-collection-2.rb | UTF-8 | 816 | 3.59375 | 4 | [] | no_license |
array = ["rat", "fang", "yo", "rat"]
def begins_with_r(array)
array.all? {|word| word.start_with?("r")}
# flag = true
# array.each do |element|
# flag = false if element[0] != "r"
# end
# flag
end
p begins_with_r(array)
def contain_a(array)
array.find_all {|word| word.include?("a")}
# container =... | true |
2a92d1d3160233dbcc8f61e11cb966b6dc7e7356 | Ruby | hage/uschemer | /test/test_let.rb | UTF-8 | 885 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
require 'test-unit'
require __dir__ + '/../let'
class TestLet < Test::Unit::TestCase
def test_let?
assert_true Let.let?([:let])
assert_false Let.let?([])
assert_false Let.let?([:hello])
end
def test_let_to_params_args_body
params, args, body = Let.let_to_params_arg... | true |
56f4d8c90059176ba58d205da59ce326c0a4e03d | Ruby | envygeeks/simple-ansi | /lib/simple/ansi.rb | UTF-8 | 1,168 | 2.90625 | 3 | [
"MIT"
] | permissive | # Frozen-string-literal: true
# Copyright: 2015-2016 Jordon Bedwell - MIT License
# Encoding: utf-8
module Simple
module Ansi
extend self
ANSI_MATCH = /\x1b.*?[jkmsuABGKH]/
COLORS = {
:red => 31,
:green => 32,
:black => 30,
:magenta => 35,
:yellow => 33,
:white => 37,... | true |
8a48d7bf4ce94a9d57085b6518b6a3da330c265b | Ruby | knudmoeller/ckan_json_dump | /dump_ckan.rb | UTF-8 | 1,842 | 2.765625 | 3 | [
"MIT",
"CC-BY-4.0"
] | permissive | # coding: utf-8
require 'json'
require 'logger'
require 'net/https'
require 'optparse'
require 'time'
require 'uri'
# Send an HTTP request, interprete response as JSON
# and return as Ruby object.
#
# +uri+:: Where to send the request
def get_data(uri)
uri = URI(uri)
http = Net::HTTP.new(uri.host, uri.port)
htt... | true |
a88a3ef8616dd1b147a1b02636a2867a2d4c9a61 | Ruby | caitlinlikesrobots/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 1,942 | 4.25 | 4 | [
"MIT"
] | permissive | def encrypt(string)
index = 0
encrypt_string = string
while index < string.length
#I added the conditional logic for edge cases
if string[index] == "z"
string[index] = "a"
elsif string[index] == " "
encrypt_string[index] = string[index]
else
encrypt_string[index] = string[i... | true |
771ffcd35c3b02be8dd476b02b1e6e113e3ba104 | Ruby | RostomH/ruby-event-oop | /lib/event.rb | UTF-8 | 943 | 3.359375 | 3 | [] | no_license | require 'pry'
require 'time'
class Event
attr_accessor :start_date, :duration, :title, :attendees
@@all_events = []
def initialize(start_date_to_save, duration_to_save, title_to_save, attendees_to_save)
@start_date = Time.parse("#{start_date_to_save}")
@duration = duration_to_save.to_i
@title = title... | true |
c4d3891a3708a1c3de63ffc63e523d7d7636899b | Ruby | bluepostit/725-cookbook | /lib/test.rb | UTF-8 | 316 | 2.546875 | 3 | [] | no_license | require_relative 'recipe'
require_relative 'cookbook'
cheesecake = Recipe.new('cheesecake', 'delicious dessert')
puts "#{cheesecake.name} - #{cheesecake.description}"
cookbook = Cookbook.new('lib/recipes.csv')
p cookbook.all
cookbook.add_recipe(cheesecake)
p cookbook.all
cookbook.remove_recipe(0)
p cookbook.all
| true |
1209334dfced4ddef1c61d449c260198ecde61c6 | Ruby | arthurtofani/footprint-ruby | /lib/footprint/observer.rb | UTF-8 | 941 | 2.578125 | 3 | [
"MIT"
] | permissive | module Footprint
module Observer
def self.included base
base.send :include, InstanceMethods
base.extend ClassMethods
end
module InstanceMethods
def receive_notification(event)
observers = self.class.callback_blocks[event.name]
return if observers.nil?
observers.... | true |
41e43c69b54ad71d517ae95433ada904b7c89759 | Ruby | billylam/yt-playlisterapp | /app/helpers/videos_helper.rb | UTF-8 | 655 | 2.515625 | 3 | [] | no_license | module VideosHelper
def embed(youtube_id, options = {})
autoplay = "?autoplay=1" unless options[:autoplay].nil?
raw %Q{<iframe title="YouTube video player" width="560" height="315" src="http://www.youtube.com/embed/#{ youtube_id }#{ autoplay }" frameborder="0" allowfullscreen></iframe>}
end
def get_thu... | true |
45c5233e2f8667b18b9aa9b72fae1117f3bd8cdc | Ruby | darren9897/programming-univbasics-3-build-a-calculator-lab-nyc04-seng-ft-041920 | /lib/math.rb | UTF-8 | 418 | 3.3125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def addition(num1, num2)
sum = num1 + num2
return sum
end
def subtraction(num1, num2)
difference = num1 - num2
return difference
end
def division(num1, num2)
quotient = num1/num2
return quotient
end
def multiplication(num1, num2)
product = num1*num2
return product
end
def modulo(num1, num2)
a... | true |
0f8b9977c0191cc9bc7022bb3f05bbab5e981e74 | Ruby | fontcuberta/Week2 | /OnlineCalculator/lib/calcoperations.rb | UTF-8 | 777 | 3.609375 | 4 | [] | no_license | class Calculator
def get_result first, second, operation
if operation == 'add'
result = first + second
elsif operation == 'sub'
result = first - second
elsif operation == 'mul'
result = first * second
elsif operation == 'div'
result = first / second
end
end
def get_... | true |
80c98da4a01cb033ac659120aa26650ff140b395 | Ruby | dylanconnolly/enigma | /test/enigma_test.rb | UTF-8 | 1,596 | 3.203125 | 3 | [] | no_license | require './test/test_helper'
require './lib/shift'
require './lib/key_generator'
require './lib/offset_generator'
require './lib/enigma'
class EnigmaTest < Minitest::Test
def setup
@enigma = Enigma.new
end
def test_it_exists
assert_instance_of Enigma, @enigma
end
def test_it_initializes_with_chara... | true |
10914a996a9018bff71bca34c99f022f6d320607 | Ruby | Scottishbuffalo/blocmetrics | /Blocmetrics/db/seeds.rb | UTF-8 | 967 | 2.5625 | 3 | [] | no_license | Application.destroy_all
Event.destroy_all
User.destroy_all
u = User.new(email: 'test@bloc.com', password: 'password')
u.skip_confirmation!
u.save
u = User.new(email: 'mikemacadam87@gmail.com', password: 'password')
u.skip_confirmation!
u.save
5.times do
title_parameter = Faker::Company.name
Application.creat... | true |
69ffdc51022a024955c3ae513a631548df55aa2c | Ruby | brshpl/idecon | /lib/idecon.rb | UTF-8 | 1,849 | 3.375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'idecon/version'
require 'digest'
require 'chunky_png'
module Idecon
class Error < StandardError; end
class Identicon
SQUARE_SIZE = 250
PIXEL_SIZE = SQUARE_SIZE / 5
DEFAULT_PATH = 'default.png'
BACKGROUND_COLOR = [255, 255, 255].freeze
def initialize(use... | true |
e6b24dfda48ffcf4e2bc39ae4b4b971c12f41cbd | Ruby | daphneaugier/comp348_a3 | /Q6.rb | UTF-8 | 3,030 | 3.859375 | 4 | [] | no_license | puts "\nThis is Q6, a modified version of Q5\n==========\n\n"
class Shape
def initialize
@status = nil
end
def print
if @status.nil?
p = perimeter().nil? ? "undefined" : perimeter().to_s
a = area().nil? ? "undefined" : area().to_s
puts "#{se... | true |
114c38ba094fe13bab91564200e3e84cd33d5bee | Ruby | KasiaCat/Ruby | /ruby/def.rb | UTF-8 | 73 | 3.09375 | 3 | [] | no_license | def puts_1_to_10
(1..10).each { |i| puts i }
end
puts_1_to_10
----
| true |
79ad5339f5ec677dcfbe857001a35c1960a0dcc6 | Ruby | kgraves/codewars-kata | /solutions/ruby/formatNames.rb | UTF-8 | 143 | 2.828125 | 3 | [
"MIT"
] | permissive | def list names
names.collect! { |n| n[:name] }
last = names.pop || ''
return last if names.empty?
names.join(', ') + " & #{last}"
end
| true |
c89c6437bf5fbf29e17d6ef48da861127df1dfe0 | Ruby | aktowns/rio | /lib/rio/rio.rb | UTF-8 | 1,672 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | class RIO
attr_reader :ioself
attr_reader :scope
attr_reader :state
def initialize
@ioself = Io.IoState_new
@state = Io::IoState.new(@ioself)
@scope = {}
end
def run (str = "")
if block_given?
yield(self)
else
result = Io.IoState_doCString_(@ioself, str)
io_to_ruby(result)
end
end
def []... | true |
37dcf8c5f63438e5c7d5702076c897ec30fdf0fa | Ruby | whatalnk/cpsubmissions | /atcoder/ruby/agc024/agc024_a/3132883.rb | UTF-8 | 402 | 3.296875 | 3 | [] | no_license | # Contest ID: agc024
# Problem ID: agc024_a ( https://atcoder.jp/contests/agc024/tasks/agc024_a )
# Title: A. Fairness
# Language: Ruby (2.3.3)
# Submitted: 2018-09-04 02:21:01 +0000 UTC ( https://atcoder.jp/contests/agc024/submissions/3132883 )
a, b, c, k = gets.chomp.split(" ").map(&:to_i)
if k.even?
ans = a - b... | true |
c347fa9ebd2cc5dbeffdb192f0b370818d3cf3cc | Ruby | czytom/nask_epp | /spec/acceptance/01_access_and_password_management_spec.rb | UTF-8 | 2,949 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
#
#
# 1. Dostęp i zarządzanie hasłem
#
#
describe "01_access_and_password_management", :vcr do
include_context "accounts"
before { cleanup }
#
#1.1 Logowanie <login>
#
it "login" do
nask = Nask.new(login1, password1, prefix1) # zestawienie połączenia https
#1. UŜyj kome... | true |
e95d97baabea9aeb4ed5ea1e28106342b92b7a65 | Ruby | MonashBioinformaticsPlatform/bio-ansible | /scripts/other/brew2lmod.rb | UTF-8 | 2,105 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
require 'fileutils'
require 'json'
require "optparse"
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Create an Lmod module definition from an installed brew formula.\nUsage #{$0} [options] <formula>"
opts.on("-m", "--module_dir DIRECTORY", "Directory to write Lmod module")... | true |
ef81a7f81e1ab4f70a348b6f89916cf14a0718ea | Ruby | aska-g/200121_food_delivery_1 | /room.rb | UTF-8 | 427 | 3.234375 | 3 | [] | no_license | class Room
attr_reader :number, :capacity, :patients
attr_accessor :id
def initialize(attr={})
@number = attr[:number]
@capacity = attr[:capacity] || 0
@patients = attr[:patients] || []
@id = attr[:id]
end
def full?
@patients.size == @capacity
end
def add_patient(patient)
raise ... | true |
b30bc490002ef1ab5d29f09e0016ee12d19adeb5 | Ruby | nuancesb/Exercises-for-programmers | /madlib/madlib.rb | UTF-8 | 669 | 3.796875 | 4 | [] | no_license | class MadLib
def self.show(output, message)
output.puts(message)
end
def self.get_input(input)
input.gets.chomp
end
def self.format_response(verb, adjective, noun, adverb)
"Do you #{verb} your #{adjective} #{noun} #{adverb}? That's hilarious!"
end
def self.run(input, output)
show(outpu... | true |
d403b4c045c21aa0c9b887d6dc5245755da292b3 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz73_sols/solutions/James Edward Gray II/tc_digraph.rb | UTF-8 | 2,477 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'test/unit'
require 'rubyquiz73'
DiGraph = RubyQuiz73.class_under_test("james@grayproductions.net")
class TestDiGraph < Test::Unit::TestCase
def test_construction
graph = nil
assert_nothing_raised(Exception) { graph = DiGraph.new }
assert_not_nil(graph)
assert_kind_of(DiGraph, graph)
as... | true |
f4f298cbd47e650940452cc4048df1cd3921693b | Ruby | zangzing/server | /lib/deferred_completion_manager.rb | UTF-8 | 3,184 | 2.890625 | 3 | [] | no_license | # This class wraps code that executes in a deferred manner
# We use this class because it encapsulates the various operations
# that run deferred into one place and also handles nesting
# of the call within the same thread. It is called via an
# around filter in the application controller as well as before
# the perfo... | true |
7ff5e565fee3385354f51664082522ebc9bc2f7f | Ruby | prashantGyeser/urbanzeak-leads-processor | /spec/lib/keyword_checker_spec.rb | UTF-8 | 519 | 2.59375 | 3 | [] | no_license | require 'rails_helper'
require 'keyword_checker'
RSpec.describe KeywordChecker do
it "should return true when the tweet has the word" do
tweet = "This is a tweet test"
word_to_check = "test"
expect(KeywordChecker.word_in_tweet?(tweet, word_to_check)).to eq true
end
it "should return false if ther... | true |
817ceaef7a41ba7a2f7d83f5581fd4c6bd0d259c | Ruby | 18F/micropurchase | /app/presenters/default_deadline_date_time.rb | UTF-8 | 278 | 2.6875 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | class DefaultDeadlineDateTime
attr_reader :start_time, :day_offset
def initialize(start_time:, day_offset:)
@start_time = start_time
@day_offset = day_offset
end
def dc_time
day_offset.business_days.after(DcTimePresenter.new(start_time).convert)
end
end
| true |
8a3feb95906bce8b09d671705a201424765cc578 | Ruby | shaistaabidd/ror-training | /Forty_Problems_Ruby/count_digits.rb | UTF-8 | 178 | 3.625 | 4 | [] | no_license | #Write ruby program to count the number of digits in a number
puts "Enter the number:"
num=gets.chomp.to_i
temp=num
count=0
while (temp>0)
count+=1
temp=temp/10
end
puts count
| true |
e493e2d1a301b06beeb5af5eb81444d4e81032fd | Ruby | helloklow/climb_catalog | /lib/climb_catalog/cli.rb | UTF-8 | 2,462 | 3.25 | 3 | [
"MIT"
] | permissive | class ClimbCatalog::CLI
def call
puts ""
puts "...loading climbs..."
ClimbCatalog::Scraper.scrape_climbs
puts ""
puts "===== Welcome, Colorado Climber! ====="
puts ""
puts "We're here to share Mountain Project's classic climbs for Northern Colorado!"
puts "Enter 'list' to see types ag... | true |
1ace476530487fe9512510822a252612b16ccd09 | Ruby | catrionameriel/Week02_Day03_Snowman_Lab | /specs/hidden_word_spec.rb | UTF-8 | 1,335 | 3.234375 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../hidden_word.rb")
require_relative("../game.rb")
require_relative("../player.rb")
class TestHiddenWord < MiniTest::Test
def setup
@player1 = Player.new("Catriona")
@hidden_word1 = HiddenWord.new("laptop")
@hidden_word2 = HiddenWord.n... | true |
79d778fdf4f5fb95bca256452f70ae77ace825ab | Ruby | zinncognito/euler | /euler_problem_49.rb | UTF-8 | 760 | 3.671875 | 4 | [] | no_license | =begin
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330,
is unusual in two ways: (i) each of the three terms are prime, and,
(ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibitin... | true |
82933611c054c0ad039a16801dc49ac337d483a8 | Ruby | aherve/ReverseMatrixWebApp | /import_script/import_pop.rb | UTF-8 | 248 | 2.5625 | 3 | [] | no_license | ARGF.each do |line|
ll = line.chomp.split("\t")
pop = ll.last.strip.to_i * 100
codename = ll[1]
t = Town.find_by(codename: codename)
if t
puts t.update_attribute(:population, pop)
else
puts "NOT FOUND: #{codename}"
end
end
| true |
ba6ec901f22e095aecb2bbde3b0ff5681b97cff2 | Ruby | elagos/Pinkunozo | /app/helpers/application_helper.rb | UTF-8 | 852 | 2.546875 | 3 | [] | no_license | module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title)
base_title = "Pinkunozo"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
def flash_class(level)
case level
when :notice then "alert alert-info"
... | true |
7e91ee41234d73d6977e896e778ec920cea2be36 | Ruby | ensallee/my-collect-prework | /lib/my_collect.rb | UTF-8 | 231 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(collection)
new_collection=[]
if block_given?
i=0
while i < collection.length
new_collection << yield(collection[i])
i+=1
end
new_collection
else
"No block was given."
end
end
| true |
0bfbcb8cf9be4a01e601cbe6af4e1fbb1a8f837a | Ruby | kmbhuvanprasad/ruby_set2 | /modules/add.rb | UTF-8 | 138 | 3.40625 | 3 | [] | no_license | module Addition
def add
puts "Enter 2 nums to perform addition"
num1 = gets.to_i
num2 = gets.to_i
add = num1 + num2
puts add
end
end
| true |
0b08a455cb07ddee5964773a064668eabdb442ae | Ruby | azhi/BSUIR_labs | /9sem/IP/lab1/linear_contrast.rb | UTF-8 | 1,344 | 2.65625 | 3 | [] | no_license | require 'RMagick'
require 'slop'
require_relative '../utils/image'
require_relative '../utils/chainer'
require_relative '../utils/histogramm_plotter'
require_relative '../utils/processors/grayscale'
require_relative '../utils/processors/linear_contrast'
opts = Slop.parse(help: true) do
banner "Usage: linear_contras... | true |
a1080b27ad0aadd459c0f47d4f1f1d1d2929408a | Ruby | LinuxGit/Code | /ruby/ProgrammingRuby/array.rb | UTF-8 | 35 | 2.640625 | 3 | [] | no_license | a = [ 3.14, "ruby", 99 ]
puts a[1]
| true |
8973820850d6227b339d2a1c9e8b1baedd8012f8 | Ruby | noscripter/launchbar-emoji-lookup | /script/extract-emojis | UTF-8 | 2,320 | 2.765625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Developed with Ruby 2.2.3
require 'json'
require 'pathname'
require 'ttfunk' # v1.4.0
# Extracts emoji images from OS X's emoji font.
#
# Credit: The majority of this script comes from the github/gemoji gem.
# https://github.com/github/gemoji/blob/be21f6e/lib/emoji/extractor.rb
module Emoji
cl... | true |
a102059a87a6be3fedaeeafdf0c2a9c06d08c979 | Ruby | mutsey/programming-univbasics-3-build-a-calculator-lab-online-web-prework | /lib/math.rb | UTF-8 | 339 | 3.046875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def addition(num1, num2)
1+2
end
a_method(1,2) #=> 3
def subtraction(num1, num2)
1-2
end
a_method(1,2) #=> -1
def division(num1, num2)
4/2
end
a_method(4,2) #=> 2
def multiplication(num1, num2)
1*2
end
a_method(1,2) #=> 2
def modulo(num1, num2)
5mod3
end
a_method(5,3) #=> 2
def square_root(num)
4=|4|
end
a... | true |
26b547bf6a48349f62d97f454c1473e729a5253c | Ruby | snaggled/dukkha | /dukkha.rb | UTF-8 | 1,249 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'sinatra'
require 'hpricot'
class Cell
@@attrs = [:x, :y, :image, :text, :color, :background, :url, :tooltip]
@@attrs.each {|a| attr_accessor a }
def initialize(cell)
@@attrs.each do |a|
self.send("#{a}=", (cell/a).inner_html)
end
[:x, :y].each {|a| self.send("... | true |
0c329c53a4eb4ea652acf28fca66b8b817ebe78f | Ruby | Y0UNGEUN/coderbyte | /PowersofTwo.rb | UTF-8 | 279 | 3.671875 | 4 | [] | no_license | def PowersofTwo(num)
# code goes here
while num!=2 do
if(num.modulo(2) == 1)
return false
end
num = num/2
end
return true
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
PowersofTwo(STDIN.gets)
| true |
2e7fdc1bda2f34a883eee1a05eaa9f8a98444c1e | Ruby | asharma414/ruby-oo-object-relationships-has-many-through-wdc01-seng-ft-042020 | /lib/customer.rb | UTF-8 | 468 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Customer
attr_reader :name, :age, :meals, :waiters
@@all = []
def initialize(name, age)
@name, @age = name, age
@meals = []
@waiters = []
@@all << self
end
def self.all
@@all
end
def new_meal(waiter, total, tip)
newMeal = Meal.new(wai... | true |
8e3660493c0959145369a2be79beb604a0b1b8d5 | Ruby | irevived1/ttt-with-ai-project-wdf-000 | /lib/players/computer.rb | UTF-8 | 2,030 | 3.71875 | 4 | [] | no_license | require_relative '../player.rb'
require 'pry'
module Players
class Computer < Player
WIN_COMBINATIONS = [[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[6,4,2]]
attr_reader :tracker , :mytok , :entok
#gets extra variable here
def initialize(token)
... | true |
f7b2093cc7bc7dd5ff351f0f8257e5802d2b47bc | Ruby | jonathansayer/clothing_retailer | /app/services/cart_total.rb | UTF-8 | 201 | 2.734375 | 3 | [] | no_license | class CartTotal
def self.total_calculation
total = 0
products = OrderedProduct.all
products.each do |product|
total += product.price * product.quantity
end
total
end
end
| true |
8e34e9ea06c3d2120666a90eeb704f1e25bec948 | Ruby | omardelarosa/project_euler_ruby | /009_pythagorean_triplet/pyth_triplet.rb | UTF-8 | 1,158 | 3.578125 | 4 | [] | no_license | array_of_triplets = []
c = 0
b = 0
a = 0
# def check_triplet(hash)
# sum_all = hash[:a] + hash[:b] + hash[:c]
# sum_two_squared = hash[:a]**2 + hash[:b]**2
# if sum_all == 1000 and sum_two_squared == hash[:c]**2
# return true
# else
# return false
# end
# end
numbers = (1..1000).t... | true |
5e7918e2294a5cedfc5d86a4259f1dd410346a15 | Ruby | piyali1988/RubyScripts | /get_files_no_spa_cate.rb | UTF-8 | 931 | 2.796875 | 3 | [] | no_license |
input_folder = 'Y:\New Reorganization\Research\TMW\TMW Longitudinal\CHILDES material\Transcription\Completed Transcripts\Completed Transcripts for Coding\Session 5'
require 'Datavyu_API.rb'
begin
# Get list of opf files
infiles = get_datavyu_files_from(input_folder)
# Init an empty list to store lines of data
dat... | true |
dbfc0c5115b88fe2022954c20104f7de28027d40 | Ruby | KeeToblog/BookSharing | /spec/models/book_spec.rb | UTF-8 | 1,755 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Book, type: :model do
before do
@user = FactoryBot.create(:user)
@book = FactoryBot.create(:book, user: @user)
end
# @bookが有効かどうかテスト
describe "validation" do
it "has a valid factory" do
expect(@book).to be_valid
end
end
# 存在性のテスト
describe "pr... | true |
d031ca053f11959088497e0fbeb2a08782503df4 | Ruby | sammyhenningsson/shaf | /lib/shaf/helpers/json_html.rb | UTF-8 | 2,238 | 3 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Shaf
module JsonHtml
STRUCTURAL_PATTERN = /^[\[\]\{\}:,]$/.freeze
def json2html(json)
as_html JSON.parse(json)
end
def as_html(obj)
"<pre><code>#{to_html(obj)}</code></pre>"
end
private
def to_html(obj, indent: 0, pre_indent: "")
... | true |
b1106ec3ce61c6d49d467dca8577a7387638b724 | Ruby | rickymclaren/projecteuler | /07.rb | UTF-8 | 177 | 3.65625 | 4 | [] | no_license | #! /usr/bin/ruby
# The 6th prime number is 13. What is the 10,001st?
require 'mathn'
# Use built in Prime
prime = 0
p = Prime.new
10001.times { prime = p.succ() }
puts prime
| true |
6608c7085aaab72993234b6b744692865c9b2539 | Ruby | jakehow/googlecharts | /lib/gchart/theme.rb | UTF-8 | 1,114 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'yaml'
module Chart
class Theme
class ThemeNotFound < RuntimeError; end
THEME_FILES = ["#{File.dirname(__FILE__)}/../themes.yml"]
attr_accessor :colors
attr_accessor :bar_colors
attr_accessor :background
attr_accessor :chart_background
def self.load(theme_name)
th... | true |
9b00a2b3d6439ed844ad6b7fc200d48e8b35f404 | Ruby | 1625081/first | /2.rb | UTF-8 | 153 | 2.546875 | 3 | [] | no_license | include Math
i = 2
j = 2
x=1
while(j<=100)
while j>i
if j%i==0 then
x=0
end
i=i+1
end
if x==1 then
print(j,"\n")
end
x=1
i=2
j=j+1
end | true |
1b3fa740011688c8b9c893c9735794f7b92dbbef | Ruby | greybutton/learnenough_ruby | /6/ex/6.1.1.rb | UTF-8 | 324 | 3.390625 | 3 | [] | no_license | states = ["Kansas", "Nebraska", "North Dakota", "South Dakota"]
# Returns a URL-friendly version of a string.
# Example: "North Dakota" -> "north-dakota"
def urlify(string)
string.downcase.split.join('-')
end
def urls(states)
states.map { |state| "https://example.com/#{urlify(state)}" }
end
puts urls(states).insp... | true |
84c0d9bad3fc5fa02bdefc2332763f99e7ed0c7b | Ruby | sean-duffy/flippd | /app/helpers/general_utils.rb | UTF-8 | 1,066 | 2.921875 | 3 | [] | no_license | require 'open-uri'
require 'json'
require 'sinatra/base'
module GeneralUtils
def get_user_id(session)
# Returns the user id of the signed in user or nil if no user is signed in
if session.has_key?(:user_id)
session[:user_id]
else
nil
end
end
def is_user_logged_in(user_id)
# Returns true if t... | true |
9bf99d73a543d36f94a8377a68f0b65c870934c6 | Ruby | ldodds/pho | /lib/pho/store.rb | UTF-8 | 19,801 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | module Pho
require 'pho/sparql'
#TODO:
#
# Conditional deletions
# If-Modified-Since support
# Robustness in uri fetching
# Etag Testing
# The Store class acts as a lightweight client interface to the Talis Platform API
# (http://n2.talis.com/wiki/Platform_API). The class provides methods for interacting... | true |
7a7d891b81727a1b1b21a4c7fe30576342d9800d | Ruby | yamitcar/matrix_groups | /problem.rb | UTF-8 | 564 | 3.640625 | 4 | [] | no_license | # Given a n*n matrix of zeros and ones, return an array [a,b] where "a" is the number of 1 groups and "b" is the number of 0 groups.
# A group is defined by adjacent(horizontally and/or vertically, but not diagonally) numbers of the same value.
# Some examples are given below:
input = [
[1, 0, 1, 1],
[0, 1, 0, 0... | true |
9a3f38387c128ba1fde21fb4ae393f0f4e01a67c | Ruby | p60/red_alert | /lib/red_alert/notification.rb | UTF-8 | 666 | 2.859375 | 3 | [
"BSD-3-Clause"
] | permissive | require 'erb'
module RedAlert
class Notification
attr_reader :subject, :body
def initialize(subject, body)
@subject = subject
@body = body
end
class << self
def build(subject_template, body_template, exception, data = {})
subject = compile_subject subject_template, excepti... | true |
e514e4fd26d06b4a441a3bf8d055587b573f5eb7 | Ruby | tsuka/exercism | /ruby/robot-name/robot_name.rb | UTF-8 | 336 | 3.390625 | 3 | [] | no_license | class Robot
attr_accessor :name
def self.forget
@@pointer = 0
@@stocked_name = ("AA000".."ZZ999").to_a.shuffle
end
def initialize
self.reset
end
def next_name
@@stocked_name[@@pointer]
end
def reset
self.name = next_name
raise "Limit exceeded." unless self.name
@@pointer... | true |
c32b66f04542077bf37d844ab4df734dfd33e95e | Ruby | gocardless/atum | /lib/atum/core/schema/parameter.rb | UTF-8 | 545 | 2.515625 | 3 | [
"MIT"
] | permissive | module Atum
module Core
module Schema
class Parameter
attr_reader :resource_name
def initialize(resource_name, name, description)
@resource_name = resource_name
@name = name
@description = description
end
def name
[@resource_name, @na... | true |
b48034bfd19116467d6ac3afbb5724e4ad96d523 | Ruby | rae1/euler-on-ruby | /test/extend/test_integer.rb | UTF-8 | 371 | 2.6875 | 3 | [] | no_license | require 'test/unit'
require_relative '../../lib/extend/integer'
class TestInteger < Test::Unit::TestCase
def test_divisible_by_should_return_boolean
result = 4.divisible_by?(2)
assert_equal(true, result)
end
def test_divisible_by_should_return_false_when_number_is_not_divisible
result = 4.divisibl... | true |
98b683a43946b9ef3b5fdb9daf7f1f284e580437 | Ruby | Wordybird/week3day3lab | /console.rb | UTF-8 | 1,595 | 2.828125 | 3 | [] | no_license | require ("pry-byebug")
require_relative("models/albums")
require_relative("models/artists")
require_relative("models/songs")
Song.delete_all
Album.delete_all
Artist.delete_all
artist1=Artist.new({"name"=>"David Bowie"})
artist1.save()
artist2=Artist.new({"name"=>"Lid Zeppelin"})
artist2.save()
artist3=Artist.new({"na... | true |
154f3623b13206371d1ad33fa4c52548d0190fa4 | Ruby | bjorngylling/TDP007 | /sem3/sql_dsl.rb | UTF-8 | 2,712 | 2.921875 | 3 | [] | no_license | require 'rubygems'
require 'sqlite3' # gem install sqlite3-ruby
# Deep Cloning by Andrew L. Johnson
# http://www.siaris.net/index.cgi/Programming/LanguageBits/Ruby/DeepClone.rdoc
class Object
def dclone
case self
when Fixnum,Bignum,Float,NilClass,FalseClass,
TrueClass,Continuation
... | true |
3eaaea3af95ecd8a5f3a6623ab8e9aaf50586367 | Ruby | AlwaysBCoding/arabicio | /app/controllers/pages_controller.rb | UTF-8 | 1,840 | 2.640625 | 3 | [] | no_license | class PagesController < ApplicationController
def homepage
end
def parse_stem
arabic_word = params[:arabic_word]
candidates = StemParser.parse_stem(arabic_word)
render json: candidates
end
def parse_word
character_array = params[:word].split("")
ascii_array = character_array.map { |letter| letter.ord ... | true |
f3e3dcf6223c2198c90addcf15f644dd83e8c9c4 | Ruby | mattvperry/groupme-ruby | /lib/groupme/api/bots.rb | UTF-8 | 1,544 | 2.75 | 3 | [
"MIT"
] | permissive | require 'groupme/bot'
require 'groupme/api/utils'
module GroupMe
class API
module Bots
include GroupMe::API::Utils
# List bots that you have created
#
# @see https://dev.groupme.com/docs/v3#bots_create
def bots
objects_from_response(GroupMe::Bot, :get, '/bots')
end
... | true |
ab671613f94fbacde5fb600f91666c7b30783833 | Ruby | yodel-cms/yodel | /lib/yodel/models/core/fields/change_sensitive_array.rb | UTF-8 | 2,054 | 3.5 | 4 | [] | no_license | # Notify the record owning this value whenever the underlying array
# changes. Records rely on assignment to determine when a value has
# changed, so mutable objects need to notify the record when they are
# updated. This is not an exhaustive list of ways to mutate an array,
# just some common methods used in Yodel alr... | true |
e2736055415d2e560fe17a9711d508c1b673e20c | Ruby | key92/clase_ruby | /variable.rb | UTF-8 | 334 | 3.203125 | 3 | [] | no_license | # Variable
s = 'Hola mundo'
x = 10
puts s.class
puts x.class
numero_grande = 1234567891011121314151617181920
puts numero_grande.class
punto_decimal = 1.5
puts punto_decimal.class
variable_dinamica= 'hola'
puts variable_dinamica.class
variable_dinamica = 7
puts variable_dinamica.class
# Variables globales
# tiene q... | true |
e969d3417c32c7da7bc1c22c763fa3bfdaaf7a62 | Ruby | aohibbard/gleam | /app/models/user.rb | UTF-8 | 1,370 | 2.578125 | 3 | [
"MIT"
] | permissive | class User < ApplicationRecord
has_secure_password
has_and_belongs_to_many :products
has_many :reviews
has_many :manufacturers, through: :products
has_many :received_follows, foreign_key: :followed_user_id, class_name: "Follow" #return array of follows for given user
has_many :followers, throu... | true |
c444a49c187408ab1b36643aa4626bb9fa9d6264 | Ruby | juanluiscontreras/entregable4 | /sales.rb | UTF-8 | 1,230 | 3.421875 | 3 | [] | no_license | class Item
attr_accessor :id, :sku, :description, :stock, :price
def initialize (id, sku, description, stock, price)
@id = id
@sku = sku
@description = description
@stock = stock
@price = price
end
def as_json(options={})
{
id: @id,
sku: @sku,
description: @description,
... | true |
c95679845f41d85f193f1295ed29a80e0d9c8cd4 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/652ebb8d776c4f2ca8bd19f231966455.rb | UTF-8 | 514 | 3.40625 | 3 | [] | no_license | class SpecialCharacterRemover
def self.call(str)
str.gsub(/\W+/, ' ')
end
end
class PhraseWordDivider
def self.call(phrase)
phrase.split(/\s+/).map do |word|
word.downcase
end
end
end
class Phrase
attr_reader :words
def initialize(phrase)
@words = PhraseWordDivider.call(
... | true |
4f38d34f035576a35e27ea36ebd767074d530094 | Ruby | StevenMeiklejohn/ubiquitous-guide | /class_notes/cx3-4-master/week_2/day_1/multiple_classes/end_code/specs/bank_spec.rb | UTF-8 | 1,097 | 3.1875 | 3 | [] | no_license | require('minitest/autorun')
require_relative('../bank')
require_relative('../bank_account')
class TestBank < MiniTest::Test
def setup
bank_account_1 = BankAccount.new('Jay',5000,'business')
bank_account_2 = BankAccount.new('Rick',1,'personal')
bank_account_3 = BankAccount.new('Kat',7500,'business')
... | true |
087172c3fe29af52241090452c8b88780774ba44 | Ruby | framallo/character-encodings | /specifications/to_i.rb | UTF-8 | 1,207 | 3.3125 | 3 | [] | no_license | # contents: Specification of String#to_i.
#
# Copyright © 2006 Nikolai Weibull <now@bitwi.se>
require 'encoding/character/utf-8'
context "An empty string" do
setup do
@string = u""
end
specify "should raise an ArgumentError when sent #to_i with an illegal base" do
[-2, -1, 0, 1, 37, 38].each{ |base| pr... | true |
b065dd8045d9df1813008008ff47a77cd82a28dd | Ruby | nysol/doc | /olddoc/mcmd/jp/examples/mchgstr.rb | UTF-8 | 2,758 | 3.015625 | 3 | [] | no_license | #!/usr/bin/env ruby
# coding: utf-8
require "./mkTex.rb"
File.open("dat1.csv","w"){|fpw| fpw.write(
<<'EOF'
id,item
1,01
2,02
3,03
4,04
5,05
EOF
)}
File.open("dat2.csv","w"){|fpw| fpw.write(
<<'EOF'
id,item
1,0111
2,0121
3,0231
4,0241
5,0151
EOF
)}
File.open("dat3.csv","w"){|fpw| fpw.write(
<<'EOF'
id,city
1,奈良市
2,下... | true |
b6f2b895a43409bd770d97880b5447aaa28142d3 | Ruby | 9cc9/hotel_reservation | /lib/hotel_reservation/estate/fee/toll.rb | UTF-8 | 452 | 3.046875 | 3 | [
"MIT"
] | permissive | module Estate
module Fee
class Toll
attr_reader :weekday,
:weekend
def initialize(params)
params.each { |name, value| instance_variable_set("@#{name}", value) }
end
# @param [Integer] wday the day of week (0-6, Sunday is zero).
def price(wday)
work... | true |
d7c0a73785e7de93988d6aad9ce7e6792c0ea1ad | Ruby | Petherson-Erasmo/automacao-em-ruby | /rocklov/web/Rakefile | UTF-8 | 1,529 | 2.65625 | 3 | [] | no_license | # Neste arquivo vamos criar uma "semente" para cadastrar os usuários das massas de teste
require "digest/md5" # O mongo criptografa a senha com o tipo md5 com essa biblioteca conseguimos criptografar a string da senha
require_relative "features/support/libs/mongo"
def to_md5(pass) # recebo a senha no formato string
... | true |
906774d0ac782d290c6d87739b32ad91b17ac266 | Ruby | aionarae/bobross | /lib/models/canvas_course.rb | UTF-8 | 1,562 | 2.84375 | 3 | [
"MIT"
] | permissive | class CanvasCourse < Forgery
attr_reader :name, :uid, :sis_id, :description
@@local_dictionaries = File.absolute_path("lib")
def initialize(opts = {})
@name = opts[:name] if opts[:name]
@uid = opts[:uid] if opts[:uid]
@sis_id = "#{opts[:sis]}" if opts[:sis]
@description = opts[:desc] if opts[:des... | true |
4ab5bd8240f7aa7a197887b46a6f9bc29ded402c | Ruby | SandoBP13049/rails_test | /test5/lib/solver/dic/extract.rb | UTF-8 | 767 | 3.40625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
#ひらがなと漢字からなる単語を抽出、漢字はひらがなに直し濁点を取り除く
require './word_converter.rb'
if ARGV.size != 2
puts "extract source out"
exit(2)
end
source = ARGV[0]
out = ARGV[1]
wc = WordConverter.new
count=0
fout = open(out,"w")
open(source){|f|
while line = f.gets
count += 1
line.chomp!
... | true |
116c697342ed54995430c880e5f22803a01bc354 | Ruby | Krafalski/GA-NYC-Bowie | /w10/d04/classwork/happytails/shelter.rb | UTF-8 | 598 | 3.234375 | 3 | [
"MIT"
] | permissive | class Shelter
attr_reader:clients
attr_reader:animals
def initialize (name)
@name = name
@clients = []
@animals = []
end
def add_a (animal)
@animals.push(animal)
end
def add_c (client)
@clients.push(client)
end
def save (animal, client)
@animals.push (animal)
client.give... | true |
3044312e105c76dce5807f18d02b68f1524133fd | Ruby | diazruy/recipe_converter | /src/mail_wrapper.rb | UTF-8 | 392 | 2.578125 | 3 | [] | no_license | require 'gmail'
class MailWrapper
attr_reader :gmail
def initialize
@gmail = Gmail.connect!(ENV['GMAIL_USER'], ENV['GMAIL_PASSWORD'])
gmail.login
end
def count
all_mail.count
end
def logged_in?
gmail.logged_in?
end
def search(*args)
all_mail.emails(*args)
end
private
def... | true |
46ce7ca25156bcc75b30a2c4882163a3c355abbb | Ruby | vpsfreecz/haveapi-fs | /lib/haveapi/fs/worker.rb | UTF-8 | 1,632 | 3.21875 | 3 | [
"MIT"
] | permissive | require 'thread'
module HaveAPI::Fs
# Base class for classes that perform some regular work in a separate thread.
class Worker
attr_reader :runs
# @param [HaveAPI::Fs::Fs] fs
def initialize(fs)
@fs = fs
@run = true
@pipe_r, @pipe_w = IO.pipe
@runs = 0
@mutex = Mutex.new
... | true |
93a59a5818e489ad37a2e6e777bb8ec5f766ccea | Ruby | niklasb/kitbot | /lib/ircbot/throttle.rb | UTF-8 | 710 | 2.6875 | 3 | [] | no_license | module IrcBot::Throttling
protected
def init_throttling(config = {})
@config = {
delay: 0.1,
throttle_threshold_time: 2,
throttle_threshold_messages: 5,
throttle_factor: 10,
throttle_time: 10,
}.merge(config)
@send_times = []
@throttle_end = Time.now
end
def throt... | true |
bb7f74b41d9e65ec135369546b7999231febdc5e | Ruby | jacobwgillespie/archive | /firehose/linked_list_example.rb | UTF-8 | 581 | 3.9375 | 4 | [] | no_license |
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node)
@value = value
@next_node = next_node
end
end
class Stack
def initialize
@data = nil
end
def push(value)
@data = LinkedListNode.new(value, @data)
end
def pop
return nil if @data == nil
va... | true |
1c25d471ebc61dec6d9e2fca6622a563a35a678a | Ruby | akmalkhadir/prime-ruby-london-web-091718 | /prime.rb | UTF-8 | 114 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(n)
if n < 2
return false
else
(2..n-1).to_a.all? do |i|
n % i != 0
end
end
end
| true |
ea4ada111ee5f99e4724f2256cc2da6e3a625769 | Ruby | lhpdev/books-api | /app/serializers/api/v1/collection_serializer.rb | UTF-8 | 784 | 2.546875 | 3 | [] | no_license | module Api
module V1
class CollectionSerializer < ActiveModel::Serializer
attributes :id,
:title,
:author,
:books
delegate :id,
to: :object
def books
return [] if object.books.nil?
serialized_books = []
obj... | true |
ff713e4c015e5b04188a3cb7b006a982cce82abb | Ruby | Vempati89/VSM_October_2017 | /features/step_definitions/Xml_steps.rb | UTF-8 | 961 | 2.6875 | 3 | [] | no_license | When(/^I open my shows xml$/) do
the_file = File.open('shows.xml')
@xml = Nokogiri::XML(the_file)
the_file.close
end
Then(/^I should see (\d+) sitcoms$/) do |num|
expect(@xml.xpath('//sitcom').length).to eql num.to_i
end
And(/^I should see (\d+) drama$/) do |num_2|
expect(@xml.xpath('//drama').length).to eq... | true |
b7b822d4ca1f99e09529bf05cab30f731ac46fc9 | Ruby | syenze/paize | /text.rb | UTF-8 | 411 | 3.28125 | 3 | [] | no_license | count = gets.chomp.to_i
count.times do |i|
moji = gets.chomp.to_s
if md = moji.match(/(\d+)\.(\d+)\.(\d+)\.(\d+)/)
if md[0].to_i >= 0 && md[0].to_i <= 255 && md[1].to_i >= 0 && md[1].to_i <= 255 && md[2].to_i >= 0 && md[2].to_i <= 255 && md[3].to_i >= 0 && md[3].to_i <= 255
print "True\n"... | true |
59766a7bed1f3d0688d47579347f81f7d48e6ab0 | Ruby | sealink/ruby_core_extensions | /spec/filename_spec.rb | UTF-8 | 453 | 2.75 | 3 | [
"MIT"
] | permissive | describe File do
it "remove bad characters" do
expect(safe("john*test.jpg")).to eq "john-test.jpg"
expect(safe(" Betty Boop-*StarHyphen")).to eq "-Betty-Boop-StarHyphen"
expect(safe("What The Hotel?")).to eq "What-The-Hotel-"
end
it "should prittify & to and" do
expect(safe("Guns & Roses")).to eq... | true |
632ff55fff8f31f4963939c8bf66287365a63d39 | Ruby | hvasoares/monografia | /implementacao/lib/ecp/double_range_semantic.rb | UTF-8 | 678 | 2.953125 | 3 | [] | no_license | require 'module_def'
require File.dirname(__FILE__)+'/semantic_model'
class CucumberFTC::ECP::DoubleRangeSemantic < CucumberFTC::ECP::SemanticModel
INTERVAL = 0.1
def self.regex
/float from (\d+\.\d+) to (\d+\.\d+)/
end
def initialize lower_bound, upper_bound
@lower_bound, @upper_bound = lower_bound.to_f,upp... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.