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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
0688aa7a19bac3754f6364980da53c4ea0d76a8a | Ruby | TopWebGhost/Angular-Influencer | /Projects/miami_metro/doakes/code/shopstyle-pull-data-into-db.rb | UTF-8 | 11,627 | 2.546875 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'net/http'
require 'active_record'
# Pseudo-code
# 1. Accept cmd-line arguments: brand/store
# 2. Call shopstyle URL with info, and process received arguments
# 3. Write output to db
def process_pernode_info(pernode, gender_v... | true |
cc0d7b2e93ccd04e8879ff1a583716382f20c568 | Ruby | derrickreimer/mass_assignable | /test/mass_assignable_test.rb | UTF-8 | 3,270 | 2.734375 | 3 | [
"MIT"
] | permissive | $:.unshift File.expand_path('../../lib', __FILE__)
require 'mass_assignable'
require 'minitest/autorun'
require 'shoulda-context'
class MassAssignableTest < Test::Unit::TestCase
class Person
include MassAssignable
attr_accessor :name, :age, :height
attr_mass_assignable :name, :age, :height
end
... | true |
2ee01de8e13fe363478b220d9aecbdc87bd4020c | Ruby | yugawara/MathAssistant | /stuff.rb | UTF-8 | 392 | 3.296875 | 3 | [] | no_license | def f(size)
values = []
var_masks = (0...size).to_a.reverse.map {|i| puts i; 2**i }
puts var_masks
0.upto((2**size) - 1) do |cnt_mask|
puts cnt_mask
values << var_masks.map { |var_mask|
shtuff = var_mask.to_s + ":" + cnt_mask.to_s +
":" + (var_mask & cnt_mask).to_s
r = (var_mask & cnt_mask) == var_m... | true |
b1604c59361361f5c73ca2bfd545b37c8a33110a | Ruby | kolasss/volt-testing | /app/lib/user_authentication/controller.rb | UTF-8 | 1,741 | 2.546875 | 3 | [] | no_license | # аутентификация сделана частично
# по туториалу http://adamalbrecht.com/2015/07/20/authentication-using-json-web-tokens-using-rails-and-react/
# метод user_not_authenticated определен в application_controller
module UserAuthentication
module Controller
extend ActiveSupport::Concern
private
def requ... | true |
9f01289206c64c1df1d89456f5042e3c9bc86c35 | Ruby | ulizko/credit_calculator | /services/annuity.rb | UTF-8 | 692 | 3.703125 | 4 | [] | no_license | class Annuity
def initialize(amount, month_rate, term)
@amount = amount
@term = term
@month_rate = month_rate
@left = amount
end
def calculate
(0...term).each_with_object([]) do |el, obj|
obj << OpenStruct.new(base: base_sum, percents: percents, left: left, month_payment: month_pay... | true |
f22c1384a85fe4193e4d4ae68488100a4ea89111 | Ruby | 58496565/gemifresh | /gemifresh.rb | UTF-8 | 4,975 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'bundler'
require 'time'
require File.dirname(__FILE__) + '/lib/support'
if ARGV.include?('--help')
puts <<-HELP
Usage: gemifresh [GEMFILE] [LOCKFILE]
Both GEMFILE and LOCKFILE will default to "Gemfile" and "Gemfile.lock" in
your current directory. Generally you'll simply invo... | true |
c6ecca3d6e4b03bc885a68b5ba0bdbe776b57415 | Ruby | ReliveRadio/reliveradio-plantasy | /app/app/models/jingle.rb | UTF-8 | 680 | 2.578125 | 3 | [] | no_license | class Jingle < ActiveRecord::Base
before_destroy :ensure_save_destroy
before_destroy :remove_uploaded_audio
has_many :playlist_entries
validates :title, presence: true
validates :duration, presence: true
mount_uploader :audio, AudioUploader
def playcount
self.playlist_entries.count
end
private
def ... | true |
878ce3f002a26062ec89edb7b3c22b5e0b28e966 | Ruby | jgarber/redcloth-treetop | /spec/redcloth/parser/inline_parser_spec.rb | UTF-8 | 5,109 | 3.15625 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + "/../../spec_helper"
require 'redcloth/parser/inline'
module RedCloth
module Parser
describe InlineParser do
before :each do
@parser = InlineParser.new
end
def parse(string)
@parser.parse_or_fail(string)
end
def parsed_s... | true |
f564a635bf4aff9336ed2dfa5be3edc6f8ee7b1e | Ruby | bg/vmsruby | /rubicon_vms/builtin/testmodule.rb | UTF-8 | 9,971 | 2.78125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | $: << File.dirname($0) << File.join(File.dirname($0), "..")
require 'rubicon'
$m0 = Module.nesting
unless defined? ExpectedException
Version.less_than("1.7") do
ExpectedException = NameError
end
Version.greater_or_equal("1.7") do
ExpectedException = NoMethodError
end
end
class TestModule < Rubicon::... | true |
99ca1af4e3b185a112d066119c05f11d22fc9862 | Ruby | jameslvdb/dungeons-and-dragons-srd | /lib/tasks/import/weapons.rb | UTF-8 | 2,324 | 3.078125 | 3 | [] | no_license | require 'json'
def format_description(w, name)
description = ''
entries = w['entries'].first['entries']
if entries.length == 1
description += TextSubstitution.format_entry(entries.first)
else
w['entries'].each do |entry|
description += TextSubstitution.format_entry(entry)
end
end
descript... | true |
2d90cb2e4aa3c4309c1a64a9ad873c191f192c33 | Ruby | doetlingerlukas/crypto | /decode_natural_number.rb | UTF-8 | 611 | 3.46875 | 3 | [] | no_license | #!/usr/bin/env ruby
def decode(number)
len = 3 # Initial length is 3 bits.
i = 0
numbers = []
while i < number.length
raise "#{number} is not a code word." if (i + len) >= number.length
n = number[i...(i + len)].to_i(2)
i += len
if number[i] == '0'
i += 1
numbers << n
len ... | true |
2c1f99c304cc57cc8a79fde8630dfa2215172074 | Ruby | tomxgab/chatango-messenger | /script.rb | UTF-8 | 1,319 | 2.765625 | 3 | [] | no_license | require "./chatango_home.rb"
require "set"
$acc = ["name", "password"]
def lSent
$sent = Set.new(File.read("sent").split(";"))
end
def sSent
File.open("sent", "w") do |f|
f.write($sent.to_a.join(";"))
end
end
lSent
$ch = Chatango_Home.new("c1.chatango.com", "5222", nil, $acc[0], $acc[1])
msg = "",
puts {"Log... | true |
ac292d324b0207027d47b6b3cd2b10648fa1a481 | Ruby | beeblebrox/dax | /dax/lib/db.rb | UTF-8 | 4,904 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'bundler/setup'
require "json"
require "date"
require "digest/sha1"
require 'set'
require 'pathname'
require 'logger'
require 'listen'
class DB < Logger::Application
def initialize(options=nil)
super("Dax::DB")
self.level = Logger::INFO
raise ArgumentError, "Need :db_location... | true |
c1a092b83132e7325f6125eedc5b004b9a6735c1 | Ruby | danpersa/edge-state-machine | /spec/state_spec.rb | UTF-8 | 2,236 | 2.890625 | 3 | [] | no_license | require 'spec_helper'
class StateTestSubject
include EdgeStateMachine
state_machine do
end
end
class Car
include EdgeStateMachine
state_machine do
state :parked
state :running
state :driving
event :turn_key do
transition :from => :parked, :to => :running, :on_transition => :start_en... | true |
77dfde106e6b46b1d00673acb3576a4ab19885df | Ruby | josephchin19293/ruby-kickstart | /session2/3-challenge/3_array.rb | UTF-8 | 378 | 3.9375 | 4 | [
"MIT"
] | permissive | # Write a method named every_other_char for strings that,
# returns an array containing every other character
#
# example:
# "abcdefg".every_other_char # => "aceg"
# "".every_other_char # => ""
class String
def every_other_char
new_string = ""
self.each_char.with_index { |c, index| index.odd? ? new_st... | true |
0407ea1e3782b8cedb4c4232e691c5b8b03b4a34 | Ruby | RumaniKafle/ITSC3155_SPRING2019_800991130 | /ruby_calisthenics1/lib/fun_with_strings.rb | UTF-8 | 1,081 | 3.609375 | 4 | [] | no_license | module FunWithStrings
def palindrome?
letters = self.downcase.scan(/\w/)
letters == letters.reverse
end
def count_words
# your code here
hash = Hash.new
self.downcase.gsub(/[^a-z\s]/ , '').split.each do |word|
if hash[word] != nil
hash[word] +=1
else
hash... | true |
83cc391162fd245a15a33c20f08f7216051bf69e | Ruby | barkerest/barkest_core | /app/controllers/status_controller.rb | UTF-8 | 4,932 | 2.875 | 3 | [
"MIT"
] | permissive |
##
# A fairly simple system status controller.
#
# The status system revolves around the GlobalStatus class and the WorkPath#system_status_file contents.
# When a long running process acquires a lock with the GlobalStatus, then it can update the status freely
# until it releases the lock. This controller simply check... | true |
1a348be21f2df1b047cb05534df7e7fb75d849fc | Ruby | cayblood/sbn | /lib/sbn/variable.rb | UTF-8 | 7,792 | 2.53125 | 3 | [
"MIT"
] | permissive | module Sbn
class Variable
attr_reader :name, :states, :parents, :children, :probability_table, :probabilities
def initialize(net, name = '', probabilities = [0.5, 0.5], states = [:true, :false])
@net = net
@@variable_count ||= 0
@@variable_count += 1
name = "variable_#{@@variable_... | true |
ecdab1d63958be46d5538cc58d0045e9c88b4d2a | Ruby | TeruhisaShibuya/local-scraper | /nokogiricss.rb | UTF-8 | 1,433 | 2.96875 | 3 | [] | no_license | require 'open-uri'
require 'nokogiri'
#スクレイピング先のURLを指定
url = 'https://www.antonia.it/153_christian-louboutin'
#決まり文句登場
charset = nil
html = open(url) do |f|
charset = f.charset #文字種別を取得
f.read #htmlを読み込んで変数htmlに渡す
end
#docというオブジェクトを作成 中身HTML
doc = Nokogiri::HTML.parse(html, nil, charset)
#表示したい内容 doc.○○ で表示
#ba... | true |
7fbeffe14de9c3ae9e9ea66e9b8a62aeb25bb729 | Ruby | Digi-Cazter/easyload | /lib/easyload/singleton_extensions.rb | UTF-8 | 3,496 | 2.828125 | 3 | [] | no_license | # -*- encoding: utf-8 -*-
require 'easyload/helpers'
require 'monitor'
module Easyload
LOAD_LOCK = Monitor.new
# The singleton methods that are defined for a module that includes {Easyload}.
module SingletonExtensions
# The root path that easyload should use when loading a child constant for this module.
... | true |
62d33c3c09840f978b35517636a0399d73de6650 | Ruby | rranelli/git_multicast | /lib/git_multicast/repository_fetcher.rb | UTF-8 | 1,363 | 2.640625 | 3 | [
"MIT"
] | permissive | require_relative 'repository_fetcher/github'
require_relative 'repository_fetcher/bitbucket'
require 'net/http'
require 'json'
module GitMulticast
class RepositoryFetcher
FETCHER_ADAPTER_ZIP = [
[Bitbucket, Adapter::Bitbucket],
[Github, Adapter::Github]
]
FETCHERS, ADAPTERS = FETCHER_ADAPTE... | true |
5ff38a664f6197ad70d87729ebbd53b96f1480da | Ruby | UpSumTech/simple_service_provider | /spec/lib/simple_service_provider/base_spec.rb | UTF-8 | 1,564 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe SimpleServiceProvider::Base do
class TestConsultant < SimpleServiceProvider::Base
attr_reader :bar, :baz
attribute :foo, String
validates :foo, :presence => true
before_work :_set_baz
def run
@bar = @foo.split('_')
end
def run!
raise "foo mus... | true |
28ff4a4be11c6faa2f26482b1e15bdfe2ea49fc1 | Ruby | SawyerMerchant/project_cli_mastermind | /secret.rb | UTF-8 | 508 | 3.125 | 3 | [] | no_license | class Secret
COLORS = %W[r g b y p o]
#initialize
def initialize
#secret
end
# user input for secret
def create_secret
@code = []
4.times { |item| @code[item] = COLORS.sample }
p @code
end
# "close" and "exact" peg logic
def check_guess(guess)
check_close(guess)
#check_exact... | true |
1a06f3f452fb548ac2783bf2b1a58a58161ff11b | Ruby | lothar59/robot_rspec_cucumber | /spec/robotsimulator/game_spec.rb | UTF-8 | 1,900 | 3.03125 | 3 | [] | no_license | require 'spec_helper'
module RobotSimulator
describe Game do
let(:output) { double('output').as_null_object }
let(:game) { Game.new(output) }
describe "#start" do
it "sends a welcome message" do
output.should_receive(:puts).with('Welcome to Robot Simulator!')
game.start
en... | true |
ace7000697f009e16a0235b49820cc655c04a7ee | Ruby | kylesnowschwartz/rails_chess | /app/services/validate_bishop_move.rb | UTF-8 | 616 | 2.75 | 3 | [] | no_license | class ValidateBishopMove < ValidatePieceMove
def potential_moves
all_diagonal_pieces
.reject { |piece| piece.same_color?(@bishop) }
.map { |piece| board.position(piece) }
.uniq
end
private
def all_diagonal_pieces
moves = @bishop.possible_placements(from)
left_to_right = p... | true |
57613fd2cc4d64cbf9d5d8d0a861ad50fba4f895 | Ruby | Manzane/gorillatrip | /app/services/vaccine_progression_constructor.rb | UTF-8 | 926 | 2.578125 | 3 | [] | no_license | class VaccineProgressionConstructor
def initialize(travel_country, travel)
@travel_country = travel_country
@travel = travel
end
def save
country = Country.find(@travel_country.country_id)
vaccines = country.vaccines
# binding.pry
country.vaccines.where('"systematic" = true').each do |vac... | true |
e74ad26c61d2749e8255cd19b1b39c15a3a50e39 | Ruby | soilforlifeforms/forms | /lib/mxit_rails/styles.rb | UTF-8 | 1,745 | 3.015625 | 3 | [
"MIT"
] | permissive | module MxitRails
module Styles
# Not sure whether a Constant is the neatest/nicest way of storing these?
StyleList = {}
def self.get name
StyleList[name.to_sym]
end
def self.add name, content
content.strip!
if content[-1] != ';'
content += ';'
end
StyleList... | true |
5c1e67ed5be03313f8e5c2116d7a881d055fc8be | Ruby | rstawarz/capybara_page_object | /lib/capybara_page_object/class_methods.rb | UTF-8 | 8,414 | 2.96875 | 3 | [
"MIT"
] | permissive | module CapybaraPageObject
module ClassMethods
#
# Set some values that can be used within the class. This is
# typically used to provide values that help build dynamic urls in
# the page_url method
#
# @param [Hash] the value to set the params
#
def params=(the_params)
@params =... | true |
d12547e9b5d4f4331119e56e01dc6f3aef623175 | Ruby | floraison/raabro | /spec/failure_spec.rb | UTF-8 | 2,273 | 2.859375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
#
# specifying raabro
#
# Thu Aug 10 07:52:29 JST 2017
#
require 'spec_helper'
module Sample::ToPlus include Raabro
# parse
def sp_star(i); rex(nil, i, /\s*/);end
def to_space(i); seq(nil, i, :to, :sp_star); end
def to_plus(i); rep(:tos, i, :to_space, 1); end
# rewrite
def rewrite(t)
[ :ok, t.s... | true |
f45e46ed876808d3930f7fc45b2215ba562ec5be | Ruby | hermetique/warbride-engine | /app/main.rb | UTF-8 | 3,843 | 2.9375 | 3 | [
"MIT"
] | permissive | require "app/storybox.rb"
require "app/storyevent.rb"
def quick_reset
$gtk.reset
$gtk.console.animation_duration = 0
end
quick_reset
def setup args
if(args.state.tick_count == 0)
args.state.session_tick = 0
args.state.debug_messages = []
$gtk.console.animation_duration = 0
args.state.layout.di... | true |
9b7523ae03381253ef08d782e7c82e27df9048ec | Ruby | garnieretienne/ant-web | /test/models/user_test.rb | UTF-8 | 1,147 | 2.59375 | 3 | [] | no_license | require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "should not save an user with no name, email nor password" do
user = User.new
assert_not user.save,
"Saved an user with no name nor email address"
assert user.errors.messages[:name].include?("can't be blank"),
"No error mess... | true |
bc01f369a96cc731f504443b2be553cb7a97bd59 | Ruby | dsinn/project_euler | /src/039.rb | UTF-8 | 824 | 3.3125 | 3 | [] | no_license | #!/usr/bin/env ruby
t0 = Time.now
require_relative 'projecteuler'
limit = 10**3
half_limit = limit >> 1
# Euclid's formula
# a = m^2 - n^2, b = 2mn, c = m^2 + n^2 for m > n where (m + n) & 1 == 1 and gcd(m, n) == 1
count = Array.new(half_limit + 1) { 0 } # Perimeter is always even, so save some memory
(1..(-0.5 + Math.... | true |
6c0854229829562d871bde8a74ce7a882b8abea2 | Ruby | sekoudosso82/Ruby_essential | /one_to_many.rb/drink.rb | UTF-8 | 1,819 | 3.828125 | 4 | [] | no_license | # require 'pry'
# RUN RUBY FILE
# ruby file_name.rb
# global var better to define outside the class
# preced with $ sign
# $global = "global"
class Drink
# # GETTER
# attr_reader :alcoholic, :name, :size, :ingredients, :beef
# # SETTER
# attr_writer :alcoholic, :name, :size, :in... | true |
5adddb2478c885ed05a7240eb0e7d0b2490ac38d | Ruby | menor/dbc_flashcards_and_todos | /part2_ruby-flashcards-2-mvc-pattern-challenge/solutions/sample_25.rb | UTF-8 | 2,071 | 3.796875 | 4 | [] | no_license | class FlashModel
attr_reader :contents, :cards
def initialize(file)
@contents = read_from_file(file)
end
def read_from_file(file)
open(file) {|f| f.readlines}
end
def create_cards
cards = []
@contents.each_slice(3) do |qa_pair|
cards << FlashCard.new(qa_pair[0].strip, qa_pair[1].str... | true |
c9981d8b18ecee70a750516c0ae18ea68c0ff523 | Ruby | dst87/Advent-of-Code | /2022/day11.rb | UTF-8 | 2,282 | 3.46875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'colorize'
input = File.read("input/day11.txt")
def generateMonkeys(input)
monkeyStrings = input.split("\n\n")
monkeys = []
monkeyStrings.each do |monkeyString|
items = monkeyString.match(/items: (.+)/)[1].split(", ").map!(&:to_i)
operationMatch = monkeyString.match(/old (?<operator... | true |
39a9a678ea80a1a24d28b63b8704d8b2cbbd19f1 | Ruby | thebravoman/software_engineering_2014 | /class004/Lubomir_Yankov_Class4_2.rb | UTF-8 | 1,186 | 2.765625 | 3 | [] | no_license | hash = Hash.new
exercise = ["2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18"]
i = 0
k = 0
sum = 0
Dir.glob("#{ARGV[0]}/**/*.*") do |myFile|
short_name = myFile.split('/').last
full_name = myFile.split('/').last.split('.').first.split('_')
name = short_name.split('.').first.split('_')
tas... | true |
dd70ba3a2ef865f9aad87ff234dd8a70906b614f | Ruby | jeffreybasurto/CoralMud | /lib/commands/ichannels.rb | UTF-8 | 379 | 2.65625 | 3 | [] | no_license | class Player
### If no argument display all available channels.
def cmd_ichannels command_table_entry, arg
buf = "The following commands are available:" + ENDL
i = 0
$imc_channel_list.each_pair do |k,v|
i += 1
z = "[On]"
buf << v[1] + ("[" + i.to_s + "] " + v[0]).ljust(25) + k.to_s.lju... | true |
30c5a9fa431451f307a4292717be029c93873dc3 | Ruby | tedcheng/flynride | /app/helpers/riders_helper.rb | UTF-8 | 520 | 2.5625 | 3 | [] | no_license | module RidersHelper
def generateMapUrl(rankResults)
@colors = ["black","blue","red","green"]
@base_map_url = "http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=900x300&maptype=roadmap&"
@base_map_url += "markers=color:#{@colors[0]}|label:You|#{current_rider.final_dest}&"
rankResults.each_wit... | true |
bcc6d578c07b6cb364aa5b9d4263391fa2938429 | Ruby | newstime/newstime_web | /app/helpers/format_helpers.rb | UTF-8 | 666 | 2.953125 | 3 | [] | no_license | module FormatHelpers
def format_currency(value)
return unless value
if value <= 0
"FREE"
elsif value < 1.00
"%.f¢" % (value.round(2)*100)
else
"$%.2f" % value.round(2)
end
end
def format_transaction_amount(value)
return unless value
if value.zero?
"$0.00"
... | true |
835beb2f7aa900095f076009c5daef8b3a94d044 | Ruby | hashcrof/Algorithms | /move_zeroes.rb | UTF-8 | 568 | 3.65625 | 4 | [] | no_license | # @param {Integer[]} nums
# @return {Void} Do not return anything, modify nums in-place instead.
def move_zeroes(nums)
n = nums.length
return n if n < 1
#pointer i points to el = 0
#point j points to el != 0
i = j = 0
while j < n
#increments j until nums[j] is not zero
if nums[... | true |
0cfef138fdb273f306bc901e014832473ef99918 | Ruby | ViolaCrellin/chitter-challenge | /spec/features/peeps_feature_spec.rb | UTF-8 | 1,380 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
# require 'timecop'
feature 'Public Peeps' do
scenario 'Users can post a peep to the chitter homepage' do
post_peep
expect(page).to have_content 'Here\'s Johny'
end
scenario 'Users can see everyons\'s in reverse chronological order' do
post_peep
post_peep_2
expect('Ano... | true |
2889b08958e031b5ae72f9500fafa8815af7c97f | Ruby | firaschaabani1/ruby-object-initialize-lab-onl01-seng-pt-120819 | /lib/dog.rb | UTF-8 | 167 | 2.515625 | 3 | [] | no_license | dog.new
def initialize (dog)
if
dog.initialize : @name
puts "name"
if else
dog.initialize : @breed
puts "breed"
else
puts Mutt
end
end
end
| true |
358b03616167bc20eac3a01f639048d381e335ec | Ruby | navychen2003/javen | /release/lightning/current/lib/ruby/shell/commands/user_permission.rb | UTF-8 | 671 | 2.546875 | 3 | [] | no_license |
module Shell
module Commands
class UserPermission < Command
def help
return <<-EOF
Show all permissions for the particular user.
Syntax : user_permission <table>
For example:
bigdb> user_permission
bigdb> user_permission 'table1'
EOF
end
def command(table=nil)
#format_... | true |
675768025888547a8744e17bae7f1f7d7ef78305 | Ruby | Yorickov/railway | /lib/services/service.rb | UTF-8 | 1,194 | 3.125 | 3 | [] | no_license | class Service
def initialize(options)
@station_klass = options[:station_klass]
@train_klass = options[:train_klass]
@carriage_klass = options[:carriage_klass]
@route_klass = options[:route_klass]
end
protected
def input_index(array, name)
puts "enter index of #{name} or X to exit"
arr... | true |
1e6bfb5f75a8d0f6c751edcce02fb04af9cf2387 | Ruby | tlalexan/knife-rackspace-database | /lib/chef/knife/rackspace_database_user_delete.rb | UTF-8 | 1,243 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | require 'chef/knife'
require 'chef/knife/rackspace_base'
require 'chef/knife/rackspace_database_instance_related'
module KnifePlugins
class RackspaceDatabaseUserDelete < Chef::Knife
include Chef::Knife::RackspaceBase
include Chef::Knife::RackspaceDatabaseBase
include Chef::Knife::RackspaceDatabaseInstan... | true |
b87955be02e97f3948c327988f24ff823bc9ce55 | Ruby | angmeng/icode-erp | /app/models/setting.rb | UTF-8 | 643 | 2.546875 | 3 | [] | no_license | class Setting < ActiveRecord::Base
before_save :check_directory, :check_trailing_slash
protected
def check_directory
puts "start checking..."
begin
[backup_path, source_path].each do |folder|
if not File.directory?(folder)
Dir.mkdir(folder)
puts "creating directory... | true |
db140319d530865c8c8f0eb203faa30a1a2c76eb | Ruby | Sborden7/W3D2 | /aa_questions/questions_database.rb | UTF-8 | 11,416 | 2.84375 | 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 User
attr_accessor :fname, :lname
def self.all
users = QuestionsDatabase.instance.... | true |
cc615eca7bb09cf8db149b3ba2bf958afca49344 | Ruby | bogrobotten/fetch | /lib/fetch/callbacks.rb | UTF-8 | 2,068 | 3 | 3 | [
"MIT"
] | permissive | module Fetch
module Callbacks
def self.included(base)
base.extend ClassMethods
end
private
# Check if a callback has been used.
def callback?(name)
self.class.callbacks[name].any?
end
# Run specific callbacks.
#
# run_callbacks_for(:before_fetch)
# run_callba... | true |
b3d2b7a81cfb0e748cb34493c25e100799cd60a6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/src/502.rb | UTF-8 | 145 | 2.953125 | 3 | [] | no_license | def compute(a, b)
diffs = i = 0
while i < a.length and i < b.length
diffs += 1 if a[i] != b[i]
i += 1
end
diffs
end | true |
75dc5019616fe76bba6b8f66ec4825b32a87787d | Ruby | Nabox68/Mardi13-projet | /exo_14.rb | UTF-8 | 120 | 3.296875 | 3 | [] | no_license | puts " Donne moi un nombre "
nombre = gets.chomp
nombre = nombre.to_i
nombre.times do
nombre -= 1
puts nombre
end | true |
1b92747557f09cdd57bf7a26e34ce3385dcd1739 | Ruby | Kmullen444/RubyExercises | /adjacent_sum.rb | UTF-8 | 423 | 4.15625 | 4 | [] | no_license | # def adjacent_sum(arr)
# sum = []
# i = 0
# while i < arr.length-1
# sum << arr[i] + arr[i + 1]
# i += 1
# end
# return sum
# end
def adjacent_sum(arr)
sum = []
arr.each_with_index do |num, i|
if i != arr.length - 1
sum << num + arr[i + 1]
end
end
return sum
end
print ad... | true |
a7b996c98b231baa57834ed352b3b15cdbf9495b | Ruby | philipla1989/curve-yc | /app/controllers/home_controller.rb | UTF-8 | 14,416 | 2.8125 | 3 | [] | no_license | class HomeController < ApplicationController
def index
@stories = Story.all
@ids = @stories.pluck(:id)
@title = "Curve Your Career"
@description = "Find fulfillment and happiness in your job. Hear about how people just like you were able to change careers."
end
def browse
@title = "Curve You... | true |
59960fde41998d36baf96e2cf34cb687d475db52 | Ruby | questionmarkexclamationpoint/evilution | /samples/triple.rb | UTF-8 | 790 | 2.953125 | 3 | [
"MIT"
] | permissive | class Triple
extend Evilution::Organism
attr_accessor :one,
:two,
:three
def fitness
-((self.one + self.two + self.three) - 100).abs
end
def mutate!
self.one = mutated_value(self.one, 0, 100, 0.1, 1)
self.two = mutated_value(self.two, 0, 100, 0.1, 1)
self.thr... | true |
e32f8a800c77040aed7318c82c99523c22fc7abf | Ruby | nico-ortiz/testVocacional-app | /services/SurveyServices.rb | UTF-8 | 2,388 | 2.765625 | 3 | [
"MIT"
] | permissive | require "./models/init.rb"
class SurveyServices
def self.newSurvey(name)
@survey = Survey.new(username: name)
if @survey.save
[201, { 'Location' => "surveys/#{@survey.id}" }, 'User created sucesfully']
@questions = Question.all
return @survey, @questions
... | true |
21461ace4937c38702dbbee47e694578b6263300 | Ruby | xdougx/abstract_bundle | /lib/concerns/pagination_concern.rb | UTF-8 | 582 | 2.5625 | 3 | [
"MIT"
] | permissive | # Module to manage pagination
module PaginationConcern
extend ActiveSupport::Concern
PER_PAGE = 20
included do
attr_reader(:current_page, :current_per_page)
end
def setup_pagination
@current_page = params[:page]
@current_per_page = params[:per_page]
page
per_page
end
def page
c... | true |
dca569275e33f8441a3523dd1f59145e75c99f92 | Ruby | GaronHock/Homework | /anagrams/anagrams.rb | UTF-8 | 3,808 | 4.71875 | 5 | [] | no_license | # Anagrams
# Our goal today is to write a method that determines if two given words are anagrams.
# This means that the letters in one word can be rearranged to form the other word. For example:
# anagram?("gizmo", "sally") #=> false
# anagram?("elvis", "lives") #=> true
# Assume that there is no whitespace or pu... | true |
b3fbd5a106dda2c76cf5e379b6ed12243f726899 | Ruby | andyrow123/CodeWars | /katas/6kyu/duplicate_encoder.rb | UTF-8 | 1,390 | 4.0625 | 4 | [] | no_license | # The goal of this exercise is to convert a string to a new string where each character in the new string is '(' if that character appears only once in the original string, or ')' if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate.
#
# ... | true |
b30858b9e2dcf2d46a158d34725e82af1df76e1e | Ruby | austinnormancore/ruby_binary_search_tree | /binary_search_tree.rb | UTF-8 | 3,510 | 3.59375 | 4 | [] | no_license | class Node
attr_accessor :data, :left, :right
def initialize(data, left=nil, right=nil)
@data = data
@left = left
@right = right
end
end
class Tree
attr_accessor :root
def initialize(array)
@array = array.uniq.sort!
@root = build_tree(@array) unless array.nil?
end
def build_tree(array=@array)
re... | true |
8c6b22468a82c341eb1133142b46f890efd8050f | Ruby | DefactoSoftware/MedischRekenenArcade | /lib/answer_handler/challenge_answer_handler.rb | UTF-8 | 908 | 2.53125 | 3 | [] | no_license | class ChallengeAnswerHandler < AnswerHandler
attr_reader :challenge, :user_challenge
STANDARD_DEATH_CEILING = 3
def initialize(session, current_user, user_challenge, skill)
super(session, current_user, skill)
@challenge = user_challenge.challenge
@user_challenge = user_challenge
end
def handle!... | true |
f9e732601bda0030c8bf3a498eaba099a69f0c52 | Ruby | saifulAbu/leetcode | /771_jewel_and_stone.rb | UTF-8 | 352 | 3.640625 | 4 | [] | no_license | require 'set'
# @param {String} j
# @param {String} s
# @return {Integer}
def num_jewels_in_stones(j, s)
jewels = Set.new
j.each_char do
|jewel|
jewels.add jewel
end
jewel_count = 0
s.each_char do
|stone|
jewel_count += 1 if jewels.include? stone
end
jewel_count
end
J = "z"
S = "aAAbb... | true |
06e77144a2794832825ed26f8ceaab29dabcf27e | Ruby | wahl77/Automatic-Website | /spec/facebook_spec.rb | UTF-8 | 1,660 | 2.546875 | 3 | [] | no_license | require "spec_helper"
describe "Facebook" do
it "wish happy birthday", js: true do
visit "http://www.facebook.com/events/list"
user_info = get_user_info
fill_in "email", with: user_info[:email]
fill_in "pass", with: user_info[:password]
click_on "Log In"
#within "span.fbRemindersTitle" do fi... | true |
b316a51bbda1c31068d68c477b9968e7b4617988 | Ruby | DetectiveAzul/cc_hw_w2d1 | /Library/library.rb | UTF-8 | 759 | 3.671875 | 4 | [] | no_license | class Library
attr_reader :books
def initialize(books)
@books = books
end
def get_book_information_by_title(book_title)
for book in @books
return book if book[:title] == book_title
end
return nil
end
def get_book_rental_details_by_title(book_title)
book = get_book_information_by_... | true |
58d8e25f85d267a1b14c53cc3ae090e87541c0cb | Ruby | ChildeRowland/Above_Average | /Above_Average/app/models/travel.rb | UTF-8 | 3,952 | 2.828125 | 3 | [] | no_license | class Travel < ActiveRecord::Base
validates :walk,
:inclusion => { :in => 0..1000000, :message => "numbers only please, no decimals or symbols"},
:exclusion => { :in => -1000000..-1,
:message => "No negitive values please."}
validates :bicycle,
:inclusion => { :in => 0..1000000, :message => "numbers only... | true |
1e7120efe6df89a232034afff866301e2b0bbaba | Ruby | lodqa/uri-forwarding-db | /app/lib/exceptions.rb | UTF-8 | 501 | 2.65625 | 3 | [] | no_license | module Exceptions
class PostProcessError < StandardError; end
class GetCommandError < PostProcessError
def initialize e
super e
end
end
class InvalidURIError < PostProcessError; end
class GatewayError < PostProcessError
def initialize(response)
super "Gateway Error: the sever return... | true |
ee5289598948dc60d2ad7b4bcfe74145379b52a4 | Ruby | csoreff/ruby_linked_list | /lib/linked_list.rb | UTF-8 | 1,119 | 3.59375 | 4 | [] | no_license | require 'pry'
require_relative 'node'
class LinkedList
def initialize
@head = nil
end
def prepend(info)
@head = Node.new(info, @head)
end
def each
node = @head
while !node.nil?
yield node
node = node.next_node
end
end
def to_s
string = []
self.each { |node| str... | true |
eb503f2e2f440fb60979fb60d569fb1b1daf19e4 | Ruby | r-goodman/Hokuto-no-Kaimono | /app/models/basket.rb | UTF-8 | 611 | 2.640625 | 3 | [] | no_license | class Basket < ActiveRecord::Base
attr_accessible :purchased_at
has_many :line_items
has_one :transaction
def total_price
line_items.to_a.sum(&:unit_price)
end
# def initialize
# @items = []
# end
# def addToBasket(track_id)
# currentItem = @items.find { |item| item == track_id }
# unle... | true |
28ec69b3b185f2e78451926be5d0088e518d4a16 | Ruby | rhawkenson/hangman | /hangman.rb | UTF-8 | 5,848 | 4.15625 | 4 | [] | no_license | #-----Psuedocode-----
# 1. Load dictionary
# 2. Choose random word between 5 and 12 characters
# 3. Add hangman interface
# 4. Display letters chosen so far: correct and incorrect
# - Make chosen word an array and match the correct letter to #index_of
# - Do not allow the user to guess the same letter more t... | true |
ef7ba06e2a0d5f70b1fcf9b66095ed7a4ca46411 | Ruby | solnic/sql | /lib/sql/generator/emitter/conditional_parenthesis.rb | UTF-8 | 708 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: utf-8
module SQL
module Generator
class Emitter
# Add conditional parenthesization to an emitter
module ConditionalParenthesis
# Emit contents of the block within parenthesis when necessary
#
# @return [Boolean]
#
# @api private
def parent... | true |
442a7bd5844c2e7bffbf79b1046cb11e48e13daa | Ruby | jacksimmonds0/Music-Library | /app/models/album.rb | UTF-8 | 619 | 2.578125 | 3 | [] | no_license | class Album < ActiveRecord::Base
belongs_to :artist
belongs_to :genre
has_many :songs, dependent: :destroy
validates :name, presence: true
# same year validation as in the artist model
validates :year, presence: true, :inclusion => 1900..Time.now.year
# paperclip gem used to add album artwork to the appl... | true |
73b25bb0620830635360ba22a417fa8e012a80d1 | Ruby | abdellani/solved-challenges | /leetcode/15. 3Sum.rb | UTF-8 | 1,384 | 3.25 | 3 | [] | no_license | =begin
source: https://leetcode.com/problems/3sum/
=end
# @param {Integer[]} nums
# @return {Integer[][]}
def three_sum(nums)
p=Hash.new(0)
n=Hash.new(0)
z=0
nums.each do |num|
case true
when num==0
z+=1
when num>0
p[num]+=1
whe... | true |
3565bf084998bdf18eae09c4cda0aaa5b487d461 | Ruby | puppetlabs/puppet-resource_api | /lib/puppet/resource_api/simple_provider.rb | UTF-8 | 2,796 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module Puppet; end # rubocop:disable Style/Documentation
module Puppet::ResourceApi
# This class provides a default implementation for set(), when your resource does not benefit from batching.
# Instead of processing changes yourself, the `create`, `update`, and `delete` functions, a... | true |
f67249ccba056d6a4d9099d31041b3e0a55adcee | Ruby | sarah12345/pair-matcher | /app/services/pair_matcher_service.rb | UTF-8 | 630 | 2.921875 | 3 | [] | no_license | class PairMatcherService
class << self
def generate_pairs(team_id)
eligible_members = Member.where(team_id: team_id).to_a
pairs = []
while eligible_members.present? do
pairs << generate_pair(eligible_members)
end
pairs
end
private
def generate_pair(members)
... | true |
c3a95b44b30678e22f7b585139dc69af5228cfe3 | Ruby | mahalingaprabu/Myproject | /lib/role.rb | UTF-8 | 451 | 2.78125 | 3 | [] | no_license | class Role
attr_reader :key, :id
private
@@roles=Set.new
@@role_id_map={}
def initialize(key,id)
@key=key
@id=id
@@roles << self
@@role_id_map[id]=self
end
public
None=Role.new(:none,0)
Admin=Role.new(:admin,1)
LeaveApprover=Role.new(:leave_approver,2)
def self.roles
@@roles
end
def to_s
{@key => @id}
end
def... | true |
df394c1808824f28c2b53baf0810ecb78602496b | Ruby | warren34/morpionjeu | /morpiongames/lib/app/game.rb | UTF-8 | 3,798 | 3.625 | 4 | [] | no_license | class Game
attr_accessor :player1, :player2, :board_game
# method creating 2 players and the board
def initialize
@player1 = Player.new("X")
@player2 = Player.new("O")
@board_game = Board.new
end
# method puting the symbol of the players in the grid
def placement(player)
puts "Merci de r... | true |
d3bee783c72e4bb43ada2c7e1a7349552dd31438 | Ruby | C1C0/minesweeper_ruby | /v_palovic_291219/module-Random.rb | UTF-8 | 1,251 | 3.015625 | 3 | [
"MIT"
] | permissive | module RD
def generateBombs(fields, maxBombs, size, notX, notY)
planted = 0
x = 0
y = 0
# siblingsX = [-1,0,+1,+1,+1,0,-1,-1]
# siblingsY = [-1,-1,-1,0,+1,+1,+1,0]
while planted < maxBombs
for i in fields
bomb = rand(0..1)
... | true |
800157d596ea79b52fead5a4ceda31ef7846a6b4 | Ruby | thoumc/ar-exercises | /exercises/exercise_6.rb | UTF-8 | 892 | 2.65625 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
puts "Exercise 6"
puts "----------"
@store1.employees.create(
first_name: "Manager1",
last_name: "Virani",
hourly_rate: 60
)... | true |
ec57328425c833efed40612d0989bdf770a75a1d | Ruby | stephensxu/rpn-calculator | /lib/rpn_expression.rb | UTF-8 | 1,443 | 4.03125 | 4 | [
"MIT"
] | permissive | require "stack"
def factorial(n)
result = 1
n.downto(1) do |i|
result *= i
end
result
end
SYMBOL_TABLE = {
"+" => lambda { |stack, x, y| x + y },
"-" => lambda { |stack, x, y| x - y },
"*" => lambda { |stack, x, y| x * y },
"!" => lambda { |stack, n| factorial(n) },
"%" => lambda { |stack, n|... | true |
5473d3728a8eb442c3e92c1f56491f7f147dfe56 | Ruby | gd875/interpolation-super-power-bootcamp-prep-000 | /lib/display_rainbow.rb | UTF-8 | 356 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your #display_rainbow method here
def color_printer(color)
return "#{color[0].upcase}: #{color}"
end
def display_rainbow(colors)
puts "#{color_printer(colors[0])}, #{color_printer(colors[1])}, #{color_printer(colors[2])}, #{color_printer(colors[3])}, #{color_printer(colors[4])}, #{color_printer(colors[5])... | true |
8f8e6d5c56b46c5703f19328cdd2ea0b1bacf9e6 | Ruby | Krhorsch/oo-cash-register-v-000 | /lib/cash_register.rb | UTF-8 | 855 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :items, :discount, :total, :last_transaction
def initialize(discount = 0)
@total = 0
@discount = discount
@items = []
end
def add_item(item, price, quantity=1)
new_total = total + price * quantity
self.last_transaction = price * quantity
s... | true |
13d7e670200304eecbcf70acc73796354bb098c4 | Ruby | verynear/energia-calc | /vendor/gems/kilomeasure/spec/kilomeasure/formula_spec.rb | UTF-8 | 960 | 2.609375 | 3 | [] | no_license | require 'kilomeasure/formula'
describe Kilomeasure::Formula do
describe '#run' do
it 'calculates an expression' do
formula = described_class.new(name: :foo, expression: '1 + 1')
formula.run
expect(formula.value).to eq(2)
end
it 'substitutes provided inputs' do
formula = described... | true |
2f07f8dfd046aafe0c5f33dbb55b3452ee81ad8a | Ruby | wfslithtaivs/AA_Homeworks_and_Projects | /ClassesBorcsh/w1d3/recursion.rb | UTF-8 | 3,621 | 3.796875 | 4 | [] | no_license | # range
def range(first, last)
return [first] if first == last
range(first, last - 1) + [last]
end
# exponential
def exp(b, n)
n == 0 ? 1 : exp(b, n-1) * b
end
p exp(2, 2)
p exp(2, 8)
p exp(3, 3)
p exp(10, 3)
def exp2(b, n)
return 0 if n == 0
return b if n == 1
if n.even?
holder = exp2(b, n / 2)
... | true |
b1d330ebb0318c03982180a0f6227a3e3101dd3b | Ruby | klavinslab/ProtocolsForReview | /manager/protocol/make_media_for_comp_cell_batch/protocol.rb | UTF-8 | 1,604 | 3.03125 | 3 | [] | no_license | # This is a default, one-size-fits all protocol that shows how you can
# access the inputs and outputs of the operations associated with a job.
# Add specific instructions for this protocol!
class Protocol
def main
operations.make
show do
title "Gather the Following Items:"
check "#{ope... | true |
e9f74cd46b3558d0b643021fcd745faa4001a57a | Ruby | adar4reg/ci-scripts | /testlink/testlink_import_test_case_systemtest.rb | UTF-8 | 6,563 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'csv'
require 'xmlrpc/client'
require 'spreadsheet'
xlsfile = ARGV[0]
def get_test_project_id
args = {devKey: @key, testprojectname: 'DEMO'}
r = @server.call('tl.getTestProjectByName', args)
r['id']
end
def create_test_suite(suite, parentid)
if parentid == ''
args = {devKey: ... | true |
e28004e6515bf2005b90ce46919fad74d3b292df | Ruby | htachib/clerk | /lib/parsers/kehe_promotion.rb | UTF-8 | 1,497 | 2.546875 | 3 | [] | no_license | module Parsers
class KehePromotion < Base
class << self
def invoice_data(document)
parsed_meta_data_cover(document).deep_merge(
parsed_invoice_details(document)
).deep_merge(parsed_invoice_date(document))
end
def parsed_meta_data_cover(document)
parsed = {}
... | true |
1f32b31675f6b215f2d70648f26baf24ff56a20b | Ruby | davepodgorski/Monday-19th | /car.rb | UTF-8 | 612 | 3.53125 | 4 | [] | no_license | class Car
@@default_colour = 'blue'
@@cars_made = 0
def initialize(colour, owner)
@owner = owner
@mileage = 0
@colour = @@default_colour
@broken = false
@@cars_made += 1
end
def self.cars_made
return @@cars_made
end
def self-default_colour=(default_colour)
@@default_colour = de... | true |
5f9ad3e68c9441a088594968f6c791b6e608fd09 | Ruby | asseym/serp | /features/step_definitions/login_steps.rb | UTF-8 | 4,181 | 2.5625 | 3 | [] | no_license | ### UTILITY METHODS ###
def create_visitor (user_factory=false)
user_factory = :user if user_factory == false
@visitor ||= FactoryGirl.attributes_for(user_factory)
end
def find_user
@user ||= User.where(:email => @visitor[:email]).first
end
def create_unconfirmed_user
create_visitor :superadmin
sign_in
c... | true |
580ae228a9747d23c09d6faadefe947375a205fd | Ruby | hannahgreen1/Bounty_hunters_lab | /models/creature.rb | UTF-8 | 2,496 | 3.265625 | 3 | [] | no_license | require("pg")
class Creature
attr_accessor :name, :species, :location, :homeworld
def initialize(options)
@id = options["id"].to_i if options["id"]
@name = options["name"]
@species = options["species"]
@location = options["location"]
@homeworld = options["homeworld"]
end
def save()
d... | true |
9fe892ffd0fa6fd1b7ad47050252cf8f011280b4 | Ruby | ComPlat/sablon | /lib/sablon/processor/chem.rb | UTF-8 | 3,301 | 2.59375 | 3 | [
"MIT"
] | permissive | # The code of that class was inspired in "kubido Fork - https://github.com/kubido/"
module Sablon
module Processor
class Chem
# PICTURE_NS_URI = 'http://schemas.openxmlformats.org/drawingml/2006/picture'
# MAIN_NS_URI = 'http://schemas.openxmlformats.org/drawingml/2006/main'
RELATIONSHIPS_NS_UR... | true |
974efcdb0d97bbf8a48c3d70dd7ef285a86b7658 | Ruby | jtanadi/LS-Exercises | /0-Basics/2-UserInput/print_something.rb | UTF-8 | 115 | 3.59375 | 4 | [] | no_license | puts "Do you want me to print something? (y/n)"
answer = gets.chomp.downcase
puts answer == "y" ? "something" : ""
| true |
d647ab9723b6aa6910cf32050168345d40383475 | Ruby | Runli/thinknetica | /lesson08/train_cargo.rb | UTF-8 | 242 | 2.890625 | 3 | [] | no_license | require_relative 'train'
# methods for Train type :cargo
class TrainCargo < Train
def initialize(number)
super(number, :cargo)
end
def wagon_add(wagon)
return unless @type == wagon.type
super(wagon)
end
end
| true |
c1ec110d344d0f385d6b8b1611e439fafb6d4f79 | Ruby | Elizabeth555/learn_to_program | /ch11-reading-and-writing/build_a_better_playlist.rb | UTF-8 | 820 | 3.828125 | 4 | [] | no_license | def music_shuffle filenames
filenames - filenames.sort
len = filenames.length
#sorts array of songs and gets length
2.times do
l_idx =0
r_idx = len/2
shuf= []
#splits array into2.
while shuf.length < len
if shuf.length%2 ==0
shuf.push(filenames[r_idx])
... | true |
476af38216eaeddacdecde0b63d89746351bdccf | Ruby | stephanschubert/blog | /app/models/blog/tag.rb | UTF-8 | 676 | 2.53125 | 3 | [
"MIT"
] | permissive | module Blog
class Tag
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
field :name, type: String
validates_presence_of :name
slug :name
#has_and_belongs_to_many :posts
embedded_in :post
cattr_accessor :separator
self.separator = ','
# Returns ... | true |
148d96bd2bd0fde01c4156db98d889ecc44f941e | Ruby | mnoble/ChopperDropper | /lib/systems/wagon.rb | UTF-8 | 172 | 2.796875 | 3 | [] | no_license | module Systems
class Wagon
attr_reader :wagon
def initialize(wagon)
@wagon = wagon
end
def call(delta)
wagon.right(delta)
end
end
end
| true |
a44cad9a2ff93b1e9ca4c7b9da7081da4d952b3f | Ruby | rodrigodealer/pet_project | /app/helpers/plans_helper.rb | UTF-8 | 278 | 2.65625 | 3 | [] | no_license | module PlansHelper
def real_name(name)
case name
when 'W'
'Semanal'
when 'CW'
'Quinzenal'
when 'M'
'Mensal'
when 'FFD'
'45 dias'
when 'CM'
'Bimestral'
when 'TM'
'90 dias'
else
'Outro'
end
end
end
| true |
90bc22f94336444f4a89473bcb9ac10dfbd878a2 | Ruby | lezoudali/ruby-playground | /test_first_ruby/12_rpn_calculator/rpn_calculator.rb | UTF-8 | 988 | 4.1875 | 4 | [] | no_license | class RPNCalculator
def initialize
@nums = Array.new
end
def value
@nums.last
end
def push(num)
@nums << num
end
def plus
if @nums.length >=2
@nums << @nums.pop + @nums.pop
else
raise "calculator is empty"
end
end
def minus
if @nums.length >=2
@nums << 0 - @nums.pop + @nums.pop
el... | true |
caf42cb505e1354c7888663e51d2a86db2e9f454 | Ruby | nhatho89/my-inject | /spec/my_inject_spec.rb | UTF-8 | 2,862 | 3.640625 | 4 | [] | no_license | require 'my_inject'
describe Array do
context 'my_inject' do
it 'can sum a number without an initial value' do
expect([1,2,3].my_inject{ |memo, value| memo += value }).to eq 6
end
it 'can sum a number with an initial value' do
expect([1,2,3].my_inject(1){ |memo, value| memo += value }).to eq 7
end
i... | true |
220ea6299714172d0c7e0865cecd7ef7f9f0786b | Ruby | PacktPublishing/Practical-OneOps | /Chapter 09/circuit-oneops-1-master/components/cookbooks/panos/libraries/dataaccess/key_request.rb | UTF-8 | 1,127 | 2.78125 | 3 | [
"MIT"
] | permissive | require File.expand_path('../../models/key.rb', __FILE__)
class KeyRequest
def initialize(url, userid, password)
fail ArgumentError, 'url cannot be nil' if url.nil?
fail ArgumentError, 'userid cannot be nil' if userid.nil?
fail ArgumentError, 'password cannot be nil' if password.nil?
@url = url
... | true |
1ab7dbed5b469e15a103ea0ee2aae2c586c825d4 | Ruby | SteveSnow/scorecard | /app/models/hole.rb | UTF-8 | 228 | 2.765625 | 3 | [] | no_license | class Hole < ActiveRecord::Base
has_one :yardage
has_many :scores
def number
return self.name[1]
end
def course
case self.name[0].upcase
when 'W'
return 'White'
when 'R'
return 'Red'
when 'B'
return 'Blue'
end
end
end
| true |
e597277a9e929fc6433e9521f2831ab182e5052a | Ruby | aproperzi2/Math_Games_Ruby | /main.rb | UTF-8 | 548 | 3.640625 | 4 | [] | no_license | require './player'
require './question'
require './helpers'
puts "\n\n*************************"
puts "Welcome to the Math Game!"
puts "*************************\n\n"
puts "Player 1 & Player 2 both have 3 lives."
puts "Answer a question incorrectly, and lose a life."
puts "If you lose all your lives, the game ends!\n\... | true |
61b5216557effa4a6491a573001f2e01b6c2bb1b | Ruby | micahlee/treequel | /experiments/paged_results_example.rb | UTF-8 | 928 | 2.59375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby -w
#
# Program to demonstrate the use of the LDAPv3 PagedResults control. This
# control is interesting, because it requires the passing of controls in
# both directions between the client and the server.
require 'rubygems'
require 'treequel'
require 'treequel/controls/pagedresults'
unless ARGV[0]... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.