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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
827cc34b6114a51236589fa72e08a260292c64cf | Ruby | bbfsdev/bbfs | /bin/run_in_background/daemon_wrapper | UTF-8 | 3,616 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
# Wrapper script, that can receive commands from Windows Service Control and run user script,
# provided as it's argument.
# NOTE This wrapper script doesn't intended to be run from command line,
# rather be started and controlled by Windows Service Control.
# For more information see documentations... | true |
b841090c55b7ecfbb270616d50787c434aab5ec7 | Ruby | manishchaks/payback-service | /spec/user_spec.rb | UTF-8 | 1,959 | 2.953125 | 3 | [] | no_license | require 'user.rb'
describe User do
before :each do
@user = User.new('user1', 'user@gmail.com', 500)
end
context 'Initialization' do
it 'is possible to create a valid user object' do
expect(@user).to respond_to(:name)
expect(@user).to respond_to(:email)
expect(@user).to respond_to(:credi... | true |
10d9146484bb22f32696876ec6f46af443264a44 | Ruby | kocsenc/kchung | /Ruby/AdvancedLevel/DietManager/LogItemUnitTest.rb | UTF-8 | 1,541 | 3.609375 | 4 | [] | no_license | # Kocsen Chung
# LogItem Class Unit test.
# simple unit tests that willt test for the LogItem object functionality
require "test/unit"
require "./LogItem"
require "date"
class LogItemUnitTest < Test::Unit::TestCase
def setup
#puts "LogItem Unit Test Setup"
end
# Make sure that a LogItem Object can be intantiat... | true |
c0af64d08cc3291422f83f3c82fdfa62952941bb | Ruby | luprz/runa-access-control | /client/app/services/authentication.rb | UTF-8 | 675 | 2.90625 | 3 | [] | no_license | class Authentication
SIGN_IN = '/api/v1/users/sign_in'
SIGN_OUT = '/api/v1/users/sign_out'
def initialize(user = {}, headers={})
@email = user[:email]
@password = user[:password]
@headers = headers
end
def sign_in
api.post do |req|
req.url SIGN_IN
req.body = {
email: @ema... | true |
33edc466d0f8b16ece0e0801b53874c66ab17cbb | Ruby | cstrynatka/ruby_fundamentals1 | /p004strings.rb | UTF-8 | 630 | 3.609375 | 4 | [] | no_license | # Defining a constant
PI = 3.14156
puts PI
# Defining a local variable
my_string = "I love the city of Rome"
puts my_string
=begin
Conversions
.to_i, .to_f, .to_a
=end
var1 = 5;
var2 = "2"
puts var1 + var2.to_i
# << appending to a string
a = "hello"
a<<"world.
I love this world..."
puts a
=begin
<< marks the sta... | true |
b5be2ecf6f4d60787466bd2292146aabcb70faf1 | Ruby | tmaczukin/simple_backup | /lib/simple_backup/utils/disk_usage.rb | UTF-8 | 1,322 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module SimpleBackup
module Utils
class Disk
@@high_usage_treshold = 0.9
@@paths = []
def self.high_usage_treshold=(value)
@@high_usage_treshold = value.to_f
raise ArgumentError.new "Backuper::Utils::Disk::high_usage_treshold must be a float greater than zero" if @@high_usage_tr... | true |
5597ac7b445d8dc8ea370749f32b12a9c6b567ef | Ruby | adamsanderson/palm | /test/waba_db_test.rb | UTF-8 | 4,286 | 2.5625 | 3 | [] | no_license | require File.dirname(__FILE__) + '/test_helper.rb'
class TestCollectionPointRecord < Palm::WabaRecord
class_id 072
field :corridor, :string
field :site, :string
field :direction, :byte
field :lanes, :byte
field :hov_lane, :byte
field :ramp_type, :string
field :express, :boolean
field :cp_id, :int
e... | true |
6c1def0e1ec52e05efaad748bf65c0ad954fd655 | Ruby | tebatalla/Blocks-Recursions | /recursion.rb | UTF-8 | 2,269 | 3.75 | 4 | [] | no_license | def range(start, ending)
return [] if ending < start
[start] + range(start + 1, ending)
end
def sum_recursive(array)
return array.first if array.length == 1
array.first + sum_recursive(array.drop(1))
end
def sum_iterative(array)
array = array.dup
sum = 0
until array.empty?
sum += array.shift
end
... | true |
bcb44a0f8888b517a64f5cbc7d05a81df68bc749 | Ruby | blumaa/OO-mini-project-chicago-web-82619 | /app/models/Recipe.rb | UTF-8 | 1,452 | 3.09375 | 3 | [] | no_license | class Recipe
attr_reader :name
@@all = []
def self.all
@@all
end
def initialize(name)
@name = name
self.class.all << self
end
def self.most_popular
recipes = RecipeCard.all.map { |card| card.recipe }
recipes.sort_by { |recipe| recipes.count(recipe) ... | true |
0a58421a9c21a49e33ebe37f56aafa260f587a26 | Ruby | HGouin/operators-onl01-seng-pt-032320 | /lib/operations.rb | UTF-8 | 136 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def unsafe?(speed)
if speed <40 || speed>60
true
else false
end
end
def not_safe?(speed)
speed>60 || speed<40 ? true : false
end
| true |
88144bddefa1600012ae3ee6102e646673bc5f91 | Ruby | KarthikVenkatraman/artifactory-ami-build | /rakelib/environment/packer_copy_template.rb | UTF-8 | 1,956 | 2.671875 | 3 | [] | no_license | require 'json'
require 'erb'
require 'ostruct'
require 'securerandom'
require 'fileutils'
module Environment
class PackerCopyTemplate
RHEL_TEMPLATE = File.dirname(__FILE__) + '/templates/copy_rhel_template.erb'
WIN_TEMPLATE = File.dirname(__FILE__) + '/templates/copy_win_template.erb'
@os_type
def i... | true |
4b9f0eca8c5a5fe3d335aa13b9de92be170ee9cd | Ruby | adamnoto/lab | /rb/import-app/app/models/concerns/company_informer.rb | UTF-8 | 1,219 | 2.984375 | 3 | [] | no_license | module CompanyInformer
class InformationFetcher
attr_reader :company
def initialize(company)
@company = company
end
def number_of_operations
company.operations.count
end
def number_of_accepted_operations
company.operations.where(status: 'accepted').count
end
def a... | true |
4a3bc47595192c20a871e558810a995aaa58cda4 | Ruby | Mani082/RubyFiles | /firstClass.rb | UTF-8 | 351 | 3.375 | 3 | [] | no_license | class Greeter
def initialize(name = "Boss")
@nameInstance = name
end
def sayHi
puts "Hi #{@nameInstance}!!"
end
def sayBye
puts "Bye #{@nameInstance}, come back soon!!"
end
end
greeter1=Greeter.new("MAaaniii")
greeter2=Greeter.new("Mounica")
greeter1.sayHi
greeter1.sayBye... | true |
0e20acce02e4fbbf6140dd0e944c97ffe93c4066 | Ruby | fraterrisus/advent2018 | /day18/part1.rb | UTF-8 | 1,271 | 3.203125 | 3 | [] | no_license | #!/usr/bin/env ruby
require './grid.rb'
iters = ARGV[1].to_i || raise
lines = IO.readlines(ARGV[0]).map(&:rstrip)
dim = lines[0].length
this_grid = Grid.new(dim)
next_grid = Grid.new(dim)
lines.each_with_index do |row,y|
row.split(//).each_with_index do |sq,x|
case sq
when '.'
val = :open
when '|'... | true |
f205f0d270d75ef82da254369f1c824b687b1646 | Ruby | LinuxGit/Code | /ruby/Metaprogramming/object_model/alphanumberic.rb | UTF-8 | 579 | 2.984375 | 3 | [] | no_license | def to_alphanumberic(s)
s.gsub(/[^\w\s]/, '')
end
p to_alphanumberic('hello# ruby!')
require 'test/unit'
class ToAlphanumbericTest < Test::Unit::TestCase
def test_strip_non_alphanumberic_characters
assert_equal '3 the Magic Number', to_alphanumberic('#3 the *Magic, Number*!')
end
end
class String
def t... | true |
52987b4a55c1560d5e9d53c97ec9d6ef5c3d3193 | Ruby | ymek/spree_test | /lib/domain_constraint.rb | UTF-8 | 668 | 2.8125 | 3 | [] | no_license | class DomainConstraint
def initialize(domain)
@domains = [domain].flatten
end
def matches?(request)
request.subdomain.present? ? domain_to_match = request.subdomain + "." + request.domain : domain_to_match = request.domain
@domains.include? domain_to_match
end
end
# # This class allows use of a r... | true |
90688ce8bffaa7f144dacc79ea2e606dbc2a9b8e | Ruby | appium/ruby_lib_core | /lib/appium_lib_core/element.rb | UTF-8 | 5,219 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, ... | true |
2e4822cf0f320cf175671805f04228efbcf62f46 | Ruby | ckccameron/sweater_weather_api | /spec/facades/road_trip_facade_spec.rb | UTF-8 | 1,625 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
describe RoadTripFacade do
it "returns road trip summary that includes forecast and travel time" do
response1 = File.read("spec/fixtures/denver_to_san_diego_mapquest_route.json")
stub_request(:get, "http://www.mapquestapi.com/directions/v2/route?from=denver,%20co&key=#{ENV["MAPQUEST_K... | true |
f4f82caca5e148eaa70d0c78862d33ea8d7ef07f | Ruby | yshen901/AAClasswork | /W5D4/aa_questions/questions.rb | UTF-8 | 5,369 | 2.828125 | 3 | [] | no_license | require 'sqlite3'
require 'singleton'
class QuestionsDatabase < SQLite3::Database
include Singleton
def initialize
super('questions.db')
self.type_translation = true
self.results_as_hash = true
end
end
class Question
attr_accessor :id, :body, :author_id, :title
def self.find_by_id(id)
quest... | true |
be7317325feabda0f5b0920ba2c967a809c6c1cc | Ruby | SoundWavesHello/bowdoin_web_crawler | /webCrawl.rb | UTF-8 | 4,010 | 2.78125 | 3 | [] | no_license | =begin
Web Crawler
Author: Kevin Lane
Last Modified: 11/22/19
=end
load "open-uri.rb" # get the URI library
class WebCrawler
attr_accessor :visited, :broken, :start, :allLinks, :badExtensions,
:noAccess, :domain
def initialize(domain)
@visited = Array.new
@broken = Array.new
@start = "... | true |
aabb6cdc517ae8eb0f0b797211f3232ba32b88d2 | Ruby | RealEstateWebTools/property_web_scraper | /app/services/property_web_scraper/listing_retriever.rb | UTF-8 | 1,293 | 2.75 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'open-uri'
require 'faraday'
module PropertyWebScraper
class ListingRetriever
# TODO - add logic to retrieve
# from db or scraper depending on expiry
attr_accessor :import_url
def initialize(import_url)
@import_url = import_url
end
def retrieve
result ... | true |
d6b76d42f521d8ffd00cf58dcfcb89e53f58d077 | Ruby | bellycard/middleman-blog-authors | /lib/author.rb | UTF-8 | 618 | 2.578125 | 3 | [
"MIT"
] | permissive | module Middleman
class BlogAuthors
class Author
attr_accessor :attributes, :articles
def initialize(name, local_data = nil)
@articles = []
@attributes = {
"name" => name,
"permalink" => BlogAuthors::AuthorPages.permalink(name)
}
if local_data.try(:a... | true |
40ac06b15d90d4f1512628d5b417548f4dc22b42 | Ruby | vic/mrT | /lib/mrT/rb_compat.rb | UTF-8 | 492 | 2.5625 | 3 | [
"BSD-3-Clause"
] | permissive | # Backport some ruby-1.9 features to ruby-1.8
module Kernel
def singleton_class
(class << self; self; end)
end unless method_defined?(:singleton_class)
def spawn(*args)
args.reject! { |item| item.instance_of? Hash }
Kernel.fork { Kernel.exec(*args) }
end unless method_defined?(:spawn)
end
class C... | true |
3f02aeb9a69ee1d50ae3767c9211fbd3ca6830a3 | Ruby | kazunetakahashi/atcoder-ruby | /0709/ARC033_B.rb | UTF-8 | 337 | 2.8125 | 3 | [
"MIT"
] | permissive | n = gets.chomp.split(" ").map{|i| i.to_i}
a = []
a << gets.chomp.split(" ").map{|i| i.to_i}
a << gets.chomp.split(" ").map{|i| i.to_i}
s = {}
bunbo = 0
bunshi = 0
2.times{|i|
n[i].times{|j|
if s.has_key?(a[i][j])
bunshi += 1
else
s[a[i][j]] = 0
bunbo += 1
end
}
}
printf("%.9f\n", bu... | true |
45355fe7540066154e500eb385129cb27544b2d3 | Ruby | Neve/Pr1 | /app/controllers/pure_ruby.rb | UTF-8 | 1,426 | 3.9375 | 4 | [] | no_license | class Base_class
# To change this template use File | Settings | File Templates.
def self.main
puts "hello" + " ruby version is " + `/usr/bin/ruby -v`
end
def arrays
a = [ 1, 'cat', 3.14 ] # array with three elements
a[0] # access the first element (1)
a[2] = nil # set the third element
... | true |
a7e79eaf025c37a847c3fa4bb85f05265164cdef | Ruby | PreservedKillick/Prime-Numbers-in-Ruby | /spec/prime_numbers_spec.rb | UTF-8 | 401 | 3.28125 | 3 | [] | no_license | require("rspec")
require("prime_numbers")
describe("prime_numbers") do
it ('returns the prime number 2 when given two') do
prime_numbers(2).should(eq([2]))
end
it ('returns an array of [2, 3, 5] when given 5') do
prime_numbers(5).should(eq([2, 3, 5]))
end
it ('returns an array of [2, 3, 5, 7, 11] whe... | true |
33c7fea062f9db2c0fae1b49b51bbf9ad448f814 | Ruby | dougpotter/controlcenter | /trunk/lib/pixel_generator.rb | UTF-8 | 3,794 | 2.671875 | 3 | [] | no_license | module PixelGenerator
# event types hash
EVENT_TYPES = HashWithIndifferentAccess.new({
:impression => "imp",
:imp => "imp",
:engagement => "eng",
:eng => "eng",
:click => "clk",
:clk => "clk",
})
# pixel type hash
PIXEL_TYPES = HashWithIndifferentAccess.new({
:ae => "ae",
:... | true |
b6b2fd1832605935ad5d7730d7b4e5880d1da686 | Ruby | rsnorman/julysoundcheck | /app/value_objects/rating.rb | UTF-8 | 1,231 | 3.28125 | 3 | [] | no_license | class Rating
SCORES = {
'0-' => 0,
'0' => 1,
'0+' => 2,
'1-' => 3,
'1' => 4,
'1+' => 5,
'2-' => 6,
'2' => 7,
'2+' => 8,
'3-' => 9,
'3' => 10,
'3+' => 11
}.freeze
DESCRIPTIONS = {
0 => 'Painful',
1 => 'Unlistenable',
2 => 'Almost unlistenable',
... | true |
d654b160de9e146b423591852c826d5a66d0f110 | Ruby | faiweiner/wdi-5 | /02-web.1.0/receipt/main.rb | UTF-8 | 1,712 | 2.71875 | 3 | [] | no_license | require 'pry'
require 'pry-debugger'
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
get '/' do
@receipts = query_db "SELECT * FROM receipts"
erb :receipts
end
get '/new' do
erb :new_receipt
end
post '/' do
# "INSERT INTO receipts (service, cost) VALUES ('Do some service', '12')"
sql = "INSER... | true |
efe403725f78dc5dc3de0303183dce81a2e30008 | Ruby | PetronellaSimonsbacka/library-challenge | /lib/library.rb | UTF-8 | 762 | 2.921875 | 3 | [] | no_license | require 'yaml'
class Library
attr_accessor :jane_library, :exp_date, :lend, :title, :author, :published
def initialize
@jane_library = YAML.load_file('./lib/data.yml')
@exp_date = Date.today.next_month(1).strftime("%m/%y")
end
def lend(item, titel)
case
when book_is_not_available(available) ... | true |
bc87231a02cb305d46785c44141a4fa06ea119df | Ruby | burke/rulebook | /test/test_chevy.rb | UTF-8 | 1,633 | 2.796875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'helper'
class TestChevy < Test::Unit::TestCase
class Engine
attr_accessor :state
def initialize
@state = "off"
end
rules do
rule(/is_(.*)/) do |state|
@state = state.gsub(/_/, " ")
end
end
end... | true |
fb6159e28a148b9424733e51c215ab5bc55ceb1e | Ruby | ChrisQ97/ProyectoRuby | /src/task.rb | UTF-8 | 332 | 2.671875 | 3 | [] | no_license | class Task
@name = ''
@state = ''
@task ={
name: '',
state: ''
}
def create (name, state)
@name = name
@state = state
@task = {
name: @name,
state: @state
}
$manager.append(@task)
end
def show
$manager
... | true |
c5239c082f6891f50addac8ccc33ad1d1902cc34 | Ruby | lewhitley/w2d3 | /poker/spec/card_spec.rb | UTF-8 | 618 | 3.015625 | 3 | [] | no_license | require 'rspec'
require 'card'
describe Card do
subject(:card) { Card.new(:two, :hearts) }
let(:bad_card) { Card.new(:twelve, :yellow) }
describe "#initialize" do
it "has a value and suit" do
expect(card.value).to_not be_nil
expect(card.suit).to_not be_nil
end
it "correctly assigns the ... | true |
cac3499314a068b728ace4fdd41782dfe7af5c50 | Ruby | alephtwo/screensbot | /lib/commands/gatherer.rb | UTF-8 | 1,126 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../util/twitter_util'
require_relative '../util/collectable'
require 'set'
# Gather them metrics
module Gatherer
include Collectable
LOGGER = Logger.new(STDOUT)
LOGGER.level = Logger::INFO
CLIENT = TwitterUtil.client
MAX_TWEETS = Twitter::REST::Timelines::MA... | true |
c31eca71dc83676bf50aee4f58821975644302e2 | Ruby | avocade/nested_accessors | /spec/nested_accessors_spec.rb | UTF-8 | 6,913 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require 'minitest/spec'
require 'simple_mock'
require_relative '../lib/nested_accessors'
# STUBBING OUT active_record "serialized" class method
class Person #< ActiveRecord::Base # must inherit from activerecord to get "serialize" class method
# Stubs out the "serialize :name, Hash" met... | true |
0ef0cc7f7bf0cea3e6363baa679b0b4876f0522d | Ruby | ChunAllen/sample_prog | /floyd_triangle.rb | UTF-8 | 418 | 3.640625 | 4 | [] | no_license | class FloydTriangle
attr_reader :number
def initialize(number)
@number = number
end
def run
pascal_calc(number - 1)
end
private
def pascal_calc(row_num)
if row_num == 0
return [1]
end
previous = pascal_calc(row_num - 1)
ret = []
(previous.length - 1).times do |i|
... | true |
030d01fce2ee28258859a8cba49a16010b7ba041 | Ruby | pgoos/clark-app | /features/support/page_object/components/list.rb | UTF-8 | 606 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
module Components
# This component provides methods for interactions with lists of web elements
module List
# Method asserts that a list of objects exists and (optional) contains provided entities
# DISPATCHER METHOD
# Custom method MUST be implemented. Example: def assert... | true |
f8d9b71a460300b312f967debadd2236428fc4b2 | Ruby | ollie/wallet | /app/models/search.rb | UTF-8 | 699 | 2.828125 | 3 | [] | no_license | class Search
attr_accessor :query, :date_from, :date_to, :page
def initialize(query: nil, date_from: nil, date_to: nil, page: nil)
self.query = query.to_s.strip
self.date_from = date_from.to_s.strip
self.date_to = date_to.to_s.strip
self.page = (page || 1).to_i || 1
end
def results
... | true |
f7eab8e8f4ee73a71f81b00ef56d300ad69963ad | Ruby | Brianpantoja33/digiramp | /app/classes/error_notification.rb | UTF-8 | 934 | 2.53125 | 3 | [] | no_license | module ErrorNotification
def errored(error, obj)
ap '--------------------------------------------'
message = "#{error}: #{obj.inspect}"
ap 'ERROR: ' + message if Rails.env.development?
Opbeat.capture_message( message )
end
def post_error(error)
ap '---------------------------------------... | true |
bf8106e4c7003f0a24a325075d72e2846e04b060 | Ruby | jtrtj/battleshift | /db/seeds.rb | UTF-8 | 1,133 | 2.65625 | 3 | [] | no_license | player_1_board = Board.new(4)
player_2_board = Board.new(4)
player_1 = User.create(email: "brickstar@gmail.com", name: 'matt', password: '123', status: 'active', user_token: ENV['BATTLESHIFT_API_KEY'])
player_2 = User.create(email: "jtr022@gmail.com", name: 'john', password: '123', status: 'active', user_token: ENV['B... | true |
cbd6bddb8c16e6efd097de8a8d38ad90f0aa00a1 | Ruby | harvard-library/STLee-blacklight | /lib/harvard/library_cloud/collections.rb | UTF-8 | 2,345 | 2.515625 | 3 | [] | no_license | module Harvard::LibraryCloud::Collections
require 'faraday'
require 'json'
include Harvard::LibraryCloud
# Logic for adding an item to a collection,
def add_to_collection_action (collection, item)
api = Harvard::LibraryCloud::API.new
path = 'collections/' + collection
connection = Faraday.new... | true |
2295e0aca3c0884a4dbd6ac8f8c40cb1e1188b80 | Ruby | samvaughn/courseproject | /new_roman.rb | UTF-8 | 1,169 | 3.75 | 4 | [] | no_license | def new_roman numeral
thousands = (numeral / 1000)
hundreds = (numeral % 1000 / 100)
tens = (numeral % 100 / 10)
ones = (numeral % 10)
roman = 'M' * thousands
if hundreds == 9
roman = roman + 'CM'
elsif hundreds == 4
roman = roman + 'CD'
else
roman = roman + 'D' * (numeral... | true |
6850c327f846ac524d95f62ae3d3ffddd674d47a | Ruby | NEU-DSG/tapas_rails | /app/models/content/concerns/filename.rb | UTF-8 | 443 | 2.53125 | 3 | [] | no_license | # The use of the content datastream label to store the basename of the
# file held in that stream has been historically controversial, but I keep
# doing it because so far no better solution has come along.
#
# To ease the eventual migration away from this use this filename method to
# access the filename of a conten... | true |
34cb9ffe304910ab8db64b8407ae7ec0d46a3a58 | Ruby | crayolapancake/Animal_Shelter_Project | /animal_shelter/models/animal.rb | UTF-8 | 2,223 | 3.40625 | 3 | [] | no_license | require_relative('../db/sql_runner')
class Animal
attr_accessor :image_url, :name, :species, :age, :adoptable, :owner_id
attr_reader :id
def initialize(options)
@id = options['id'].to_i if options['id']
@image_url = options['image_url']
@name = options['name']
@species = options ['speci... | true |
f03ed7f83e18835d2f5c0af8f831a4b299ed8b1a | Ruby | judofyr/rcpu | /test/test_emulator.rb | UTF-8 | 7,345 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'helper'
module RCPU
class TestEmulator < TestCase
def test_parse
ins = []
rcpu(false) do
block :main do
SET a, 1
ins << @ins.last
ADD [a], 0x1000
ins << @ins.last
SUB (a+1), [0x10]
ins << @ins.last
SET push, o
... | true |
9d5770ade0854abe62f9c06e42740bdbbeb1317f | Ruby | 04alexklink/student-directory | /step8exercise11.rb | UTF-8 | 1,551 | 4 | 4 | [] | no_license | # STEP 8 EXERCISE 11
# Once you have completed the "Asking for user input" section,
# open this file. It's Ruby code but it has some typos. Copy it
# to a local file and open it in Atom without syntax highlighting.
# To do this, select "Plain Text" in the lower right corner of the window.
# Now, find all typos in tha... | true |
c10572285de5003bc46729008e73bdd7192b9848 | Ruby | sdexter91/chatbot | /pingpong.rb | UTF-8 | 1,520 | 2.6875 | 3 | [] | no_license | require 'socket'
server = 'cherryh.freenode.net'
port = 6667
socket = TCPSocket.open(server, port)
nickname = 'SkillcrushBotOMG'
channel = '#turquoise1591'
socket.puts "NICK #{nickname}"
socket.puts "USER #{nickname} 0 * #{nickname}"
socket.puts "JOIN #{channel}"
socket.puts "PRIVMSG #{channel} :I am so happy to be... | true |
4a89e23ae3d613064fb5654f7fcb50d5ba7ef211 | Ruby | heshf/learn-to-program | /chap08/ex1.rb | UTF-8 | 477 | 3.09375 | 3 | [] | no_license | =begin
puts 'Hello there, please enter some text (one word only per line'
responses = []
while true
responses = gets.chomp
if responses ==""
break
end
responses.push
end
puts "Thank you. Now here are your words"
puts responses.sort
=end
puts 'Hello there, please enter some text (one word only per line)'
responses ... | true |
4440f6d9e1b99ed28f71ca3450414e14cdd69c63 | Ruby | laurengordonfahn/phase-0-tracks | /ruby/santa.rb | UTF-8 | 3,896 | 3.859375 | 4 | [] | no_license | #Initalizeing class Santa
class Santa
attr_reader :ethnicity
attr_accessor :gender, :age
#Creating two instances of class Santa
# Instance Methods for class Santa
def speak(number_of_times)
index = 0
until number_of_times == index
puts "Ho, ho, ho!, Haaaappy holidays!"
index +=1
end
end
def eat_m... | true |
34ecaba67a17fc2771d01dd1c1de2fddafb79d18 | Ruby | JaimeVRodriguez/RubyOnRailsIntro | /Week1/Debug1.rb | UTF-8 | 608 | 3.71875 | 4 | [] | no_license | #--------------------------------------------------------------------------
#
# Script Name: Debug1.rb
# Version: 1.3
# Author: Jaime V. Rodriguez
# Date: 10 June 2020
# Assignment #: Assignment 1.3
#
# Description: This Ruby script has purposely inserted "bugs" in order
# for fellow stu... | true |
87ca35104060e81ea75c3d73f8b07be0d504c354 | Ruby | deltapurna/intro_to_ruby_and_sinatra | /code/monkey_patch.rb | UTF-8 | 122 | 2.65625 | 3 | [] | no_license | #!/home/delta/.rbenv/shims/ruby
class String
def shout!
"#{self.upcase}!!!"
end
end
puts "Tech Talk JDV".shout!
| true |
20adac3e4befb1a89364fcca283a40c661f58d29 | Ruby | sergewhite/faye_demo | /faye.rb | UTF-8 | 704 | 2.53125 | 3 | [] | no_license | #!/usr/env ruby
BASE_DIR = File.expand_path("../", __FILE__)
if ARGV[1]
PID="#{BASE_DIR}/pids/#{ARGV[1].match(/(\w+)(.ru)/)[1]}.pid"
COMMAND="bundle exec rackup -s thin -E production #{BASE_DIR}/#{ARGV[1]}"
case ARGV[0]
when "start"
puts ">>Starting"
pid = fork do
Dir.chdir(BASE_DIR)
exec... | true |
377288eddf31f7aa94f22a99cd1bb8b6433b5d2a | Ruby | ang3lkar/pact_broker | /lib/pact_broker/hash_refinements.rb | UTF-8 | 407 | 2.5625 | 3 | [
"MIT"
] | permissive | module PactBroker
module HashRefinements
refine Hash do
def deep_merge(other_hash, &block)
block_actual = Proc.new {|key, oldval, newval|
newval = block.call(key, oldval, newval) if block_given?
[oldval, newval].all? {|v| v.is_a?(Hash)} ? oldval.merge(newval, &block_actual) :... | true |
9bd6b0a01902204b82c020b9fd9875ade2952635 | Ruby | hhoopes/exercism | /ruby/robot-name/robot_name.rb | UTF-8 | 545 | 3.21875 | 3 | [] | no_license | class Robot
@@name_repository = []
attr_reader :name
def initialize
@name = generate_name
end
def reset
generate_name
end
private
def generate_name
new_name = ""
2.times do
new_name << ("A".."Z").to_a.sample
end
3.times do
new_name << ("0".."9").to_a.sample
e... | true |
f5e8b51ce80f422d5a1ebe8d153e3e622b7764ca | Ruby | KGan/appacc | /algo/euler/integer partition.rb | UTF-8 | 946 | 3.4375 | 3 | [] | no_license | require 'colorize'
def integer_partition(set)
set
set_sum = set.inject(:+)
mat = DpArray.new(set.length + 1) { DpArray.new(set_sum / 2 + 1) }
mat[0].map! { 0 }
mat.each do |row|
row[0] = 0
end
mat[0][0] = 1
mat[1..-1].each_with_index do |row, ri|
row.each_with_index do |sum, si|
prev_sum ... | true |
44ad6997b9aefcac6fbe76fe738384e570fea3f5 | Ruby | ppawel/openstreetmap-watch-list | /lib/tiler/test/utils_test.rb | UTF-8 | 836 | 2.78125 | 3 | [] | no_license | $:.unshift File.absolute_path(File.dirname(__FILE__) + '/../lib/')
require 'test/unit'
require 'utils'
class UtilsTest < Test::Unit::TestCase
def test_bbox_to_tiles
tiles = bbox_to_tiles(18, [-95.2174366, 18.4330814, -95.2174366, 18.4330814])
assert_equal(61736, tiles.to_a[0][0])
assert_equal(117411, ti... | true |
19148dbbe52b0e9bc77434d03dbe82034f36615d | Ruby | at90/flatlane-app-rails | /app/helpers/application_helper.rb | UTF-8 | 860 | 2.515625 | 3 | [] | no_license | module ApplicationHelper
def numeralify (val)
if val <=9000000
val=val/100000
numer="#{val} lacs"
end
if val >=9000000.0
val=val/10000000.0
fl_val=number_with_precision(val, :precision => 1)
numer="#{fl_val} Cr"
end
return numer
end
def curr_city
curr_city=@city
end
def... | true |
e2640ce3a92d7aa9043cbf3234e76aa365f1daa3 | Ruby | Kkelly22/pokemon-scraper-v-000 | /lib/pokemon.rb | UTF-8 | 669 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_accessor :name, :type, :db, :id, :hp
@@all = []
def initialize(name: name, type: type, db: db, id: id, hp: hp)
@name = name
@type = type
@db = db
@id = id
@hp = hp
@@all << self
end
def self.all
@@all
end
def self.save(name, type, db)
db.execute("INSER... | true |
348ceec79ef3f054fca9d14d846670dfb7c085b5 | Ruby | brunofaboci/Rails_TimeToAnswer | /app/models/user_statistic.rb | UTF-8 | 552 | 2.734375 | 3 | [] | no_license | class UserStatistic < ApplicationRecord
belongs_to :user
def total_questions
self.right_question + self.wrong_question
end
def self.set_statistic(answer, current_user)
if !!current_user # ! é negação | uma ! nega a resposta, que seria true, transformando em um New, e a segunda ! nega novamente, voltan... | true |
56b6a1a894284b94f5fe4831df1f40975833e83f | Ruby | superr4y/hacks | /spotify/spotify_ad_blocker_linux.rb | UTF-8 | 3,352 | 2.75 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pty'
# This script scans the output from 'strace spotify' and search for ads
# If it finds one it will mute the master channel and umute it if the ad is over.
# The script was developed for the Spotify Linux Client.
#
#
# Usage: sudo ./spotify_ad_blocker_linux.rb
class SpotifyAdBlocker
... | true |
4956a9fd8b0b38ba0700367eb58ee2c537c33c3b | Ruby | michelsmonthe/ruby-test | /tests-ruby/lib/02_calculator.rb | UTF-8 | 154 | 3.109375 | 3 | [] | no_license | def add(x, y)
return x + y
end
#add(a, b)
#def subtract(a, b)
puts a - b
end
#subtract(a, b)
#a = gets.chomp.to_i
#b = gets.chomp.to_i
#def (a)
| true |
2463dab25981a9f57472b449fad2f2130d537b31 | Ruby | roselynemakena/RB | /logger/log.rb | UTF-8 | 323 | 2.734375 | 3 | [] | no_license | require 'logger'
$LOG = Logger.new($stderr)
def run_me
begin
eval(3/0)
rescue Exception => e
$LOG.warn "Caught something:: #{e}"
$LOG.info "Caught something:: #{e}"
$LOG.fatal "Caught something:: #{e}"
$LOG.error "Caught something:: #{e}"
$LOG.debug "Caught something:: #{e}"
end
end
run... | true |
3859cdb6173be65a5e55985b83a60b9b96cb4555 | Ruby | twrodriguez/duct_tape | /spec/ext/hash_spec.rb | UTF-8 | 2,638 | 2.765625 | 3 | [
"BSD-2-Clause"
] | permissive | require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")
#
# Hash#deep_merge
#
describe Hash, "#deep_merge" do
it "should have the method defined" do
expect(Hash.method_defined?(:deep_merge)).to be(true)
end
pending "More tests"
end
#
# Hash#deep_merge!
#
describe Hash, "#deep_merge!" do
it "sho... | true |
ca69ca4e50390b0941373275f6c59f81e00349d6 | Ruby | Marcus893/W1D4-minesweeper | /tile.rb | UTF-8 | 372 | 3.5625 | 4 | [] | no_license | class Tile
attr_reader :val
def initialize(bomb = false)
@bomb = bomb
@revealed = false
@val = nil
end
def self.make_bomb
Tile.new(true)
end
def reveal
@revealed = true
end
def set_val(num)
@val = num
end
def revealed?
@revealed
end
def is_bomb?
@bomb
end
... | true |
0d1b7e4e9996da0b23a152212cdc09e48f8abb5a | Ruby | bytheway875/shakespeare_analyzer | /macbeth_analyzer.rb | UTF-8 | 1,185 | 3.5 | 4 | [] | no_license | #There are many speeches. Each speech has a speaker. Each speech has many lines.
class MacbethAnalyzer
require 'nokogiri'
require 'open-uri'
require 'active_support/inflector'
attr_accessor :macbeth
# Initializing a MacbethAnalyzer object will load the document
def initialize
@macbeth = Nokogiri::XML(... | true |
eb45bfb70dcaf4162b50e0368b30bf83d4535ecf | Ruby | nzmoore/BillsRuby | /logic.rb | UTF-8 | 346 | 3.640625 | 4 | [] | no_license | number = rand(1..6)
puts "You rolled a #{number}"
puts "You are a winner rolling the highest number" if number == 6
puts "You are a loser rolling the lowest number" if number == 1
if (number != 1 and number != 6) then puts "You are not a winner but you did not roll the lowest number" end
if ( number < 5 ) then puts "Yo... | true |
41c6981d4354fca49fbe41e569d9101a92f85979 | Ruby | dcastroeyss/wikirate | /mod/csv_import/lib/csv_row/normalizer.rb | UTF-8 | 250 | 2.53125 | 3 | [] | no_license | class CSVRow
# common methods to be used to normalize values
module Normalizer
def comma_list_to_pointer str
str.split(",").map(&:strip).to_pointer_content
end
def to_html value
value.gsub "\n", "<br\>"
end
end
end
| true |
7cbb17cfbc540311558943a757598034387818df | Ruby | wordtreefoundation/bomdb | /lib/bomdb/import/verses.rb | UTF-8 | 1,459 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'json'
require 'bomdb/models/verse'
module BomDB
module Import
class Verses < Import::Base
tables :books, :verses
# Expected data format is:
# [
# {
# "range_id": Int, # the mericope range ID
# "book": String, # the name of the book, e.g. 1 Nephi
# ... | true |
a5e5ee59402bbdc9e5faecc202a5e4225e184772 | Ruby | himdel/warciv | /ruby/Unit.rb | UTF-8 | 3,886 | 2.96875 | 3 | [] | no_license | require './AttackMapItem.rb'
require './Map.rb'
require './Player.rb'
require './UI.rb'
require './buildings.rb'
require './enums.rb'
# not ruby yet!
class Unit < AttackMapItem
Unit(popis, p) : AttackMapItem(popis, p) {
self.stop()
end
bool move(x, y)
virtual bool gather(x, y)
virtual bool build(x, y, b)
vo... | true |
0af0865bbabd36cd0f9d2895fd74314352a773c1 | Ruby | WeWantEdTR/MineField | /lib/mine_field/score.rb | UTF-8 | 169 | 2.78125 | 3 | [
"MIT"
] | permissive | module MineField
class Score
attr_reader :total
def initialize
@total = 0
end
def increment(score = 1)
@total += score
end
end
end
| true |
22846862b94fb980e5e8d98be2afba3173a577ec | Ruby | Adrian5918/weather.rb | /weather.rb | UTF-8 | 276 | 2.828125 | 3 | [] | no_license | require 'http'
response = HTTP.get("http://api.openweathermap.org/data/2.5/weather?q=chicago&appid=#{ENV['OPEN_WEATHER_API_KEY']}&units=imperial")
data = response.parse(:json)
p data
city_name = data['name']
p city_name
temperature = data['main']['temp']
p temperature | true |
8174aeb5cff68d8dc4728da9fc4c9cd88878527b | Ruby | gion-1192/ftp_time | /lib/ftp_time/timer.rb | UTF-8 | 427 | 2.890625 | 3 | [
"MIT"
] | permissive | module FtpTime
class Timer
attr_accessor :exe_time
def start
raise "undefined exe_time" if @exe_time.nil?
differ = min_conversion(@exe_time - time_now)
sleep differ unless differ <= 0
if block_given?
yield
else
"execute method #{differ} ago"
end
end
private
def min_conversio... | true |
eb29fefae33d272271b06f9aa608504462296497 | Ruby | SaturdayAM/mass-assignment-dc-web-031218 | /lib/person.rb | UTF-8 | 311 | 2.84375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Person
#your code here
attr_accessor :name, :birthday, :eye_color, :height, :weight,
:handed, :complexion, :t_shirt_size,
:wrist_size, :glove_size, :pant_length,
:pant_width, :hair_color
def initialize(attr_hash)
attr_hash.each{|key, val| self.send(("#{key}="), val)}
end
end | true |
52fee0c840e49dc73b98bda0fe8b7dbba05bc2b5 | Ruby | anthonygiuliano/launch-school | /120-object-oriented-programming/oo-book/classes-and-objects-2/ex3.rb | UTF-8 | 252 | 3.1875 | 3 | [] | no_license | class Person
attr_accessor :name
def initialize(name)
@name = name
end
end
bob = Person.new("Steve")
bob.name = "Bob" # => undefined method `name='
#error occurs because there's no setter method
# change attr_reader to attr_accessor to fix
| true |
a447735eb09df10c46e48183d0e97470e1c79886 | Ruby | androidgrl/exercism | /ruby/hamming/hamming.rb | UTF-8 | 138 | 3.3125 | 3 | [] | no_license | class Hamming
def self.compute(strand1, strand2)
pairs = strand1.chars.zip(strand2.chars)
pairs.count { |x,y| x!=y }
end
end
| true |
c95cbce13ec76b6f61a47abd074203d0815bc04c | Ruby | rkpop/upcoming-releases-widget | /database.rb | UTF-8 | 737 | 3.03125 | 3 | [
"Unlicense"
] | permissive | # frozen_string_literal: true
require 'sqlite3'
# Database class
# Entry checking, and inserting is done in this class
class Database
def initialize(database_name)
@instance = SQLite3::Database.new database_name
end
def check_entry(artist_name, release_time)
result = nil
@instance.execute('select *... | true |
c69aefe054145bbcb4acdc06b8461790d85b3171 | Ruby | prasann/twza-training | /Steven/romanKata/roman.rb | UTF-8 | 252 | 4.03125 | 4 | [] | no_license |
class Roman
def convert number
#return "I" #Testing for 1
#number == 2? "II" : "I" #Testing for both 1 and 2
#Used to test 1,2 and 3
array = ""
count = number
while count > 0
array = array + "I"
count -= 1
end
array
end
end | true |
a15a755a7b57fbb8409cdf30f0acf8d650e44e54 | Ruby | Kimrowoon/coderbyte | /ArrayAdditionI.rb | UTF-8 | 265 | 3.171875 | 3 | [] | no_license | def ArrayAdditionI(arr)
a=arr.max
sum = arr.reduce (:+)
if a=sum
return "true"
else
return "false"
end
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
ArrayAdditionI(STDIN.gets)
| true |
0402d7a46f0a0880132b0077848e0e1c4f1f31d0 | Ruby | TravisGriffiths/ITR-BOS-01 | /mhondoart/HW1.rb | UTF-8 | 1,915 | 4.1875 | 4 | [] | no_license | # HW 01
#
# Purpose:
#
# Read the taks below and complete the exercises in this file. We will start
# to write the beginnings of our "Secret Number Game" using what we've
# learned in Ruby Lesson 01.
#
###############################################################################
#
# 1. Read an Interview with the Crea... | true |
656111460df33defdac4e45dc8c0759a0ac77449 | Ruby | oourfali/pre-ruby-course | /string_ext.rb | UTF-8 | 183 | 3.296875 | 3 | [] | no_license | class StringExt
def initialize (left, right)
@left = left
@right = right
end
def concat
@left + @right
end
def substract
@left.gsub(@right, '')
end
end
| true |
49d322f4e303e42972bc1a0cff9ba70994a4ade4 | Ruby | patrykwozinski/deployer | /deployer.rb | UTF-8 | 549 | 2.78125 | 3 | [] | no_license | class Deployer
attr_accessor :service, :env, :branch
def initialize(service, env, branch)
@service = service
@env = env
@branch = branch
end
def start
if service_exists?
Object.const_get(@service).new(env, branch).deploy
else
{ message: 'Wrong service name.', status_code: 404 }... | true |
7fe50743a141ba35112d4e705d86196fa189d8ab | Ruby | gatgui/fbpg | /tests/ruby/flow.rb | UTF-8 | 237 | 3.671875 | 4 | [] | no_license |
i = 0
while i < 20 do
puts i
i = i + 1
if i >= 10 then
puts "early exit"
break
end
end
x = 4
y = 4
if x == y then
puts "x equals y"
else
puts "x does not equal y"
end
y = 5
if x != y then
puts "As expected"
end
| true |
8f9781efc5a770e0c38f84cc65d0ebd74187f901 | Ruby | rmagick/rmagick | /spec/rmagick/draw/annotate_spec.rb | UTF-8 | 1,650 | 2.53125 | 3 | [
"MIT"
] | permissive | RSpec.describe Magick::Draw, '#annotate' do
it 'works' do
draw = described_class.new
image = Magick::Image.new(10, 10)
draw.annotate(image, 0, 0, 0, 20, 'Hello world')
yield_obj = nil
draw.annotate(image, 100, 100, 20, 20, 'Hello world 2') do |draw2|
yield_obj = draw2
end
expect(yi... | true |
aa047917bd3c65519e1054ac2daef72503b5a795 | Ruby | meganft/event-reporter | /test/container_test.rb | UTF-8 | 3,488 | 2.875 | 3 | [] | no_license | require_relative 'test_helper'
require './lib/container'
class ContainerTest < Minitest::Test
def test_it_returns_queue_in_an_array
q = Container.new
assert_instance_of Array, q.queue
end
def test_count_returns_number_of_members_in_queue
q = Container.new
expected = {"first_name"=>"Allison"... | true |
87101a4774a379440cc3e7d42b6f30ea95c2a312 | Ruby | pootsbook/elm-log | /app/services/url_cleaner.rb | UTF-8 | 625 | 2.859375 | 3 | [] | no_license | class UrlCleaner
BLACKLIST = %w(
utm_
)
attr_reader :uri
class << self
def clean(url)
self.new(url).clean
end
end
def initialize(url)
@uri = URI(url)
end
def clean
uri.query = clean_encoded_query_params.presence if uri.query
uri.to_s
end
private
def decoded_query... | true |
d251050032470a21a9d69b43abfab11bbb080189 | Ruby | mihotakeyama/ruby_game | /brave.rb | UTF-8 | 324 | 3.359375 | 3 | [] | no_license | require './character'
class Brave < Character
def attack(monster)
puts "勇者が攻撃をした!"
damage = @offense - monster.defense
monster.hp -= damage
puts "モンスターに#{damage}のダメージを与えた!"
puts "モンスターの残りのHPは#{monster.hp}になった!"
end
end
| true |
51b2e4b27f8f96ff8ccee49a82fe6f533151da21 | Ruby | jcwimer/wrestlingApp | /app/services/tournament_services/double_elimination_match_generation.rb | UTF-8 | 500 | 2.765625 | 3 | [
"MIT"
] | permissive | class DoubleEliminationMatchGeneration
def initialize( tournament )
@tournament = tournament
end
def generate_matches
@tournament.weights.each do |weight|
SixteenManDoubleEliminationMatchGeneration.new(weight).generate_matches_for_weight if weight.wrestlers.size >= 9 and weight.wrestlers.s... | true |
c79e6f465d60fd6e54847d3f5ef52a312d49cd02 | Ruby | Vladiid/ruby_on_rails | /Projects/MyApp/test.rb | UTF-8 | 966 | 3.9375 | 4 | [] | no_license | print "(R)rock, (S)scissors, (P)paper? "
s = gets.strip.capitalize
if s == "R"
user_choice = :rock
elsif s == "S"
user_choice = :scissors
elsif s == "P"
user_choice = :paper
else
puts "Can't understand what you want? Sorry."
exit
end
arr = [:rock, :scissors, :paper]
computer_choice = arr[rand(0..2)]
puts ... | true |
53f54e6fa69b44529af8d990f7f51041628a2bb6 | Ruby | TIMBERings/easy_bowling_brackets | /server/app/models/event.rb | UTF-8 | 951 | 2.625 | 3 | [] | no_license | class Event < ApplicationRecord
belongs_to :user
has_many :bracket_groups
validates :name, presence: true
validates :event_date, presence: true
validates :user, presence: true
validates :winner_cut, presence: true, numericality: true
validates :runner_up_cut, presence: true, numericality: true
validate... | true |
739fe70edae16c2e31a6acec5ce419597b9ad40a | Ruby | Gudarien/WIP-Gudarien | /day5_1.rb | UTF-8 | 378 | 4.28125 | 4 | [] | no_license | x = 3 # 1
y = "hello" # 2
if x > 10 # 3
x = x + 1
y = y - x
else # 4
x = x - 1 # 5
y = y * x # 6
end # 7
p x # 8
p y # 9
# 1: x is 3
# 2: x is 3, y is "hello"
# 3: Condition not met
# 4: condition is met
# 5: x is 2
# 6: x is 2, y "hellohello"
# 7: c... | true |
c6213cdb940e42761298a04b3b327093f4b2eea1 | Ruby | davepodgorski/Monday-19th | /shopping cart.rb | UTF-8 | 540 | 3.265625 | 3 | [] | no_license | require '.product.rb'
class ShoppingCart
@@shoppingcart = []
def add_to_cart(product)
@@shoppingcart << product
return @@shoppingcart
end
def remove_from_cart(product)
@@shopping_cart.delete(product)
return @@shoppingcart
end
def add_total
counter = 0
@@shoppingcart.each do |p... | true |
59121d089936144ec4b7bb1589ae2cf47df5ccc9 | Ruby | ktlacaelel/ix | /bin/ix-json-append | UTF-8 | 204 | 2.796875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'json'
key = ARGV[0]
value = ARGV[1]
STDIN.each_line do |line|
begin
hash = JSON.parse(line)
hash[key] = value
puts hash.to_json
rescue => error
end
end
| true |
7ecee98cb0896c00cb264a70417236cb33f3f413 | Ruby | jeffwilliams/Torrentflow | /daemon/config.rb | UTF-8 | 11,063 | 2.703125 | 3 | [
"BSD-3-Clause"
] | permissive | require 'yaml'
require 'logging'
class BaseConfig
# This function searches the RUBY loadpath to try and find the standard config file.
# If it's not found in the load path, the current directory, ../etc, etc/, and /etc/ are searched.
# If found it returns the full path, if not it returns nil.
def self.findConf... | true |
4e1e93cd9e79526c887f906ff7bc48b26a39f439 | Ruby | megamsys/nilavu | /lib/email.rb | UTF-8 | 638 | 2.875 | 3 | [
"MIT"
] | permissive | require 'mail'
module Email
def self.is_valid?(email)
return false unless String === email
parsed = Mail::Address.new(email)
# Don't allow for a TLD by itself list (sam@localhost)
# The Grammar is: (local_part "@" domain) / local_part ... need to discard latter
parsed.address == email && par... | true |
ae8ae190777574dc3c8283296b0c8496cf72db5e | Ruby | railsninja/Smartthumbs | /lib/smartthumbs/thumbable.rb | UTF-8 | 5,220 | 2.53125 | 3 | [
"MIT"
] | permissive | module Smartthumbs
module Thumbable
require 'RMagick'
include Magick
# return the rmagick instance
def rmagick_img
return @rmagick_img unless @rmagick_img.blank?
if self.class.st_config[:blob].present?
@rmagick_img ||= Magick::ImageList.new.from_blob(
self.send(self... | true |
0b8a23c13f15cde32323aa084e8fb4b8d1a46e2f | Ruby | koukisakata/MS2Import | /app/models/wallpaper.rb | UTF-8 | 543 | 2.5625 | 3 | [] | no_license | class Wallpaper < ApplicationRecord
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
# IDが見つかれば、レコードを呼び出し、見つかれなければ、新しく作成
wallpaper = find_by(id: row["id"]) || new
# CSVからデータを取得し、設定する
wallpaper.attributes = row.to_hash.slice(*updatable_attributes)
# 保存する
wall... | true |
cf969c0bf839ccd16f13a49726c449289baa52e6 | Ruby | BigBeardy/name-and-calulator | /calulatormath.rb | UTF-8 | 306 | 3.09375 | 3 | [] | no_license | def math(group,num1,num2)
if group == "addition"
answer = num1.to_i + num2.to_i
elsif group == "subtraction"
num1.to_i - num2.to_i = answer
elsif group == "division"
num1.to_i / num2.to_i = answer
else group == "multiply"
num1.to_i * num2.to_i = answer
end
answer.to_s
end | true |
bfce1c2af38fce2664e77f782846ade0dea51ea9 | Ruby | Easoncyx/Ruby_and_SoftwareEngineering | /w3c_ruby/w3c_ruby variable.rb | UTF-8 | 560 | 4.03125 | 4 | [] | no_license | # Golbal variable
$global_variable = 10
class Class1
def print_global
puts "Global variable in Class1 is #$global_variable"
end
end
class Class2
def print_global
puts "Global variable in Class2 is #$global_variable"
end
end
class1obj = Class1.new
class1obj.print_global
class2obj = Class2.new
class2ob... | true |
d2aaedf373a3c9db51d1393d5acb45d70487f497 | Ruby | iHiD/threaded_in_memory_queue | /test/threaded_in_memory_queue/worker_test.rb | UTF-8 | 777 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class WorkerTest < Test::Unit::TestCase
def setup
@worker = ThreadedInMemoryQueue::Worker.new(Queue.new, timeout: 1)
@worker.start
end
def teardown
end
def test_calls_contents_of_blocks
Dummy.expects(:process).with(1).once
Dummy.expects(:process).with(2).once
job... | true |
ab3969bd69d9229d16e70614150ef25d7578caa4 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/src/2503.rb | UTF-8 | 208 | 3.21875 | 3 | [] | no_license | def compute(foo, bar)
foo, bar = bar, foo if bar.size < foo.size
difference = 0
foo.each_char.with_index do |char, index|
difference += 1 if char != bar[index]
end
difference
end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.