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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
75376967c855e4251ec4b9e7bd15c6aff1cbc92d | Ruby | sirinath/Terracotta | /dso/branches/aa-dgc2/code/base/buildscripts/maven_deploy.rb | UTF-8 | 1,968 | 2.5625 | 3 | [] | no_license | # Utility class for deploying JAR files to a Maven repository.
class MavenDeploy
include MavenConstants
def initialize(options = {})
@generate_pom = options.boolean(:generate_pom, true)
@group_id = options[:group_id] || DEFAULT_GROUP_ID
@repository_url = options[:repository_url] || MAVEN_REPO_LOCAL
... | true |
f6e64f529f21e025bd3dcb05b6080a802026ad02 | Ruby | SmrutiSuman/parking_lot | /parking/slot.rb | UTF-8 | 593 | 3.171875 | 3 | [] | no_license | require_relative './vehicle'
class Slot
attr_accessor :id, :vehicle
def initialize (id)
@id = id.to_i
end
def park(registration_number, color)
if self.vehicle
raise "Sorry, Car already parked"
else
puts "Allocated slot number: #{ self.id }"
self.vehicle = ::Vehicle.new(registra... | true |
f9a8d007904b26a5b37daf3752baa27a99816ef7 | Ruby | nathaliaifurita/docker_qasampa | /vendor/bundl/ruby/2.6.0/gems/cucumber-messages-15.0.0/lib/cucumber/messages/time_conversion.rb | UTF-8 | 802 | 2.890625 | 3 | [
"MIT"
] | permissive | module Cucumber
module Messages
module TimeConversion
NANOSECONDS_PER_SECOND = 1000000000
def time_to_timestamp(time)
Timestamp.new(
seconds: time.to_i,
nanos: time.nsec
)
end
def timestamp_to_time(timestamp)
Time.at(timestamp.seconds + timesta... | true |
89a9ee05401e9b0df70fdeab73d6d6c331119035 | Ruby | thprennes7/pet-RBnB_Flosamigui | /app/models/stroll.rb | UTF-8 | 172 | 2.515625 | 3 | [] | no_license | # Each stroll concerns one dogsitter, one dog and takes place in one city
class Stroll < ApplicationRecord
belongs_to :dogsitter
belongs_to :dog
belongs_to :city
end
| true |
88b0f4d65cc4a06d6bc1d52d453366aa23fe0494 | Ruby | jhawthorn/dkim | /test/test_helper.rb | UTF-8 | 1,125 | 2.65625 | 3 | [
"MIT"
] | permissive |
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
require 'minitest/autorun'
require 'dkim'
class String
# Parse the format used in RFC 6376
#
# In the following examples, actual whitespace is used only for
# clarity. The actual input and output text is designated using
# bracketed descriptors: "<SP>"... | true |
e62e27bb900004db2c8ab290b5e503dbd610642c | Ruby | strategist922/OpenTSDB-UDP-Proxy | /RedisFwd.rb | UTF-8 | 3,495 | 2.625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | #!/bin/env ruby
require 'rubygems'
require 'redis'
require 'eventmachine'
require 'socket'
# Address to listen on for the proxy. Listens on all addresses
# by default
PROXYLISTEN = '0.0.0.0'
# UDP port to listen on for proxy requests.
PROXYPORT = 11212
# Redis server to use
REDISSERVER = 'yourredisserverhere'
# Re... | true |
c81e4cf0b330e0f13e52010d4651b4f1b87a857b | Ruby | sneharpatel/ruby-leetcode-problem-solving | /delete_node_in_linked_list.rb | UTF-8 | 2,974 | 3.921875 | 4 | [] | no_license | class Node
attr_accessor :value, :next
def initialize(value, next_node = nil)
@value = value
@next = next_node
end
end
def print_ll(head)
current = head
while current
print " #{current.value} ->"
current = current.next
end
end
def insert(head, val, position)
if position == 0
new... | true |
db07df2d2262e33f13b514a188caaf2582c72d00 | Ruby | cleve703/chess | /spec/chess_spec.rb | UTF-8 | 1,960 | 3.375 | 3 | [] | no_license | require_relative '../lib/chess.rb'
require_relative '../lib/board.rb'
require_relative '../lib/pieces.rb'
require_relative '../lib/string.rb'
describe "Chess" do
describe "#analyze_board_check" do
it "Returns true if white rook is in attack position of black king" do
game = Game.new
game.board.update... | true |
557f21db1e3d4c9a4822b269b9c780bbaa2d117f | Ruby | Coding-Gymnasium/2020_turing_module_1 | /night_writer_NR/test/english_translator_test.rb | UTF-8 | 906 | 2.921875 | 3 | [] | no_license | require "./test/test_helper"
class EnglishTranslatorTest < Minitest::Test
def test_it_exists
translator = EnglishTranslator.new(ARGV[0], ARGV[1])
assert_instance_of EnglishTranslator, translator
end
def test_translates_letter_back_to_english
# skip
translator = EnglishTranslator.new("data/one_... | true |
d7c663f54aed12114391b717e19aa82296d260d4 | Ruby | think41c/exercism_ruby_anagram | /anagram.rb | UTF-8 | 717 | 3.84375 | 4 | [] | no_license | class Anagram
def initialize(anagram)
@anagram = anagram
@anagram_lets = anagram.downcase.split("").sort
end
def match(compared_word)
matches = []
counter = 0
until counter == compared_word.length
word_to_examine = compared_word[counter].downcase.split("").sort
matches <... | true |
35e4573125ae5157590f20c8a2c0eab804777894 | Ruby | ddmck/Bark | /app/models/todo_resetter.rb | UTF-8 | 283 | 2.625 | 3 | [] | no_license | class TodoResetter
include ::ScheduledJob
def perform
puts "#####"
puts "Refreshing Todos"
puts "#####"
Todo.where(completed: true).each {|todo| todo.completed = false; todo.save}
end
def self.time_to_recur(last_run_at)
last_run_at + 1.minutes
end
end | true |
99672419914b0ec9e9de62e5c42929a4b529a3cb | Ruby | mrrusof/gem_of_life | /lib/gem_of_life/square_board_presenter.rb | UTF-8 | 623 | 2.890625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'delegate'
module GemOfLife
class SquareBoardPresenter < SimpleDelegator
def initialize output_stream, rows, cols, board
super board
@output_stream = output_stream
@rows = rows
@cols = cols
@board = board
end
def draw
cells = @bo... | true |
a9ebf3e1d89594d6a5ff4efbdf598910fdf80623 | Ruby | milne1282/Armory | /lib/weaponizable.rb | UTF-8 | 1,316 | 2.609375 | 3 | [] | no_license | class ActiveRecord::Base
def self.acts_as_weapon
include Weaponizable
end
end
module Weaponizable
def self.included(base)
base.has_one :weapon, :as => :weaponizable, :autosave => true
base.validate :weapon_must_be_valid
base.alias_method_chain :weapon, :autobuild
base.extend ClassMethods
... | true |
fa8ebfc663aa696d5015f0bbbc4c4ab5bb55c299 | Ruby | guidomb/reviewer | /app/services/github.rb | UTF-8 | 1,922 | 2.828125 | 3 | [] | no_license | class Github
attr_reader :github_client, :webhook_secret, :webhook_url
WEBHOOK_NAME = 'web'
class MissingOptionError < ArgumentError
def initialize(option_key)
super("Option #{option_key} cannot be nil")
end
end
def initialize(github_client, options = {})
@github_client = validate_githu... | true |
fef12891232d8e4c93445f33c14a30435d7e66f3 | Ruby | ICanDoAllThingThroughChrist/roomscraper | /Rakefile | UTF-8 | 606 | 2.546875 | 3 | [] | no_license | require_relative './config/environment'
def reload!
load_all './lib'
end
task :console do
Pry.start
end
task :scrape_rooms do
#instantiate scraper, and find new rooms
nyc_scraper = RoomScraper.new('https://newyork.craigslist.org/search/mnh/roo')
nyc_scraper.call
chicago_scraper = RoomScraper.new('... | true |
5d745fec850daecc6ee68fba88b2a1ea6e5860f5 | Ruby | izumin5210-sandbox/coding-exercises | /abc041/d/main.rb | UTF-8 | 1,040 | 3.40625 | 3 | [
"MIT"
] | permissive | require 'set'
N, M = gets.split(' ').map(&:to_i)
=begin
LIST = []
N.times do |i|
LIST[i] = N.times.to_a
LIST[i].delete(i)
end
M.times do
pair = gets.split(' ').map(&:to_i)
LIST[pair[1] - 1].delete(pair[0] - 1)
end
def patterns(i, visited)
result = 0
if visited.size == N
result = 1
else
LIST[... | true |
2774f9a5bbcb40a8b049540827ff37d7d240668d | Ruby | Munded/rps-challenge | /spec/player_spec.rb | UTF-8 | 1,945 | 2.84375 | 3 | [] | no_license | require 'player'
describe Player do
let(:player) { Player.new 'Ed'}
context 'player starts with a' do
it 'win count' do
expect(player.win_count).to eq 0
end
it 'lose count' do
expect(player.lose_count).to eq 0
end
end
context 'choosing a move' do
it 'can fail if incorrect move c... | true |
de5b0e2129e26b145bbd018fc7a795f54fdf87c4 | Ruby | Umekawa/atcoder | /20200412/c.rb | UTF-8 | 256 | 3 | 3 | [] | no_license | require 'benchmark'
result = Benchmark.realtime do
num = gets.to_i
r = [*1..num]
sum_num=0
r.each do |num1|
r.each do |num2|
r.each do |num3|
sum_num+=num1.gcd(num2).gcd(num3)
end
end
end
puts sum_num
end
puts "処理概要 #{result}s"
| true |
1af1738cf95b25f03aa56227fb228b9c8606e24d | Ruby | alexander-mathieu/laugh_tracks | /spec/models/comedian_spec.rb | UTF-8 | 2,284 | 2.59375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Comedian, type: :model do
describe "relationships" do
it {should have_many(:specials)}
end
describe "validations" do
it {should validate_presence_of(:name)}
it {should validate_presence_of(:age)}
it {should validate_presence_of(:birthplace)}
end
describ... | true |
f3a79ac9f4764862fb3ac3385ea4a440d22fbef4 | Ruby | johnmmcg/baseball_team_directory | /models/player.rb | UTF-8 | 583 | 3.125 | 3 | [] | no_license | require_relative "./team_data"
require 'pry'
class Player
attr_reader :name, :position, :team
def initialize(name, position, team)
@name = name
@position = position
@team = team
end
def self.all
team_data = TeamData::ROLL_CALL
players_array = []
team_data.each do |team|
team[1]... | true |
2267deb31a0a69b964b0b9d615e5e1732bb2c389 | Ruby | mikutter/mikutter | /core/miku/nil.rb | UTF-8 | 611 | 2.59375 | 3 | [
"MIT",
"CC-BY-SA-3.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # -*- coding: utf-8 -*-
require_relative 'atom'
require_relative 'list'
class NilClass
include MIKU::Atom
# include MIKU::List
def car
self end
def cdr
self end
def setcar(val)
MIKU::Cons.new(val, nil) end
def setcdr(val)
MIKU::Cons.new(nil, val) end
# def each(&proc)
# nil end
... | true |
25244e7ce524adcc2d78c5ece1c67b4a284ebbdb | Ruby | bjjb/focloir | /app/models/word.rb | UTF-8 | 720 | 2.59375 | 3 | [] | no_license | class Word < ActiveRecord::Base
before_save :sanitize_word!
before_create :lookup_definition!
def to_param
word
end
@@default_source = "http://dictionary.reference.com/browse"
class << self
attr_writer :source
def source; @source ||= @@default_source; end
end
attr_writer :source
def sour... | true |
1ccf944ea41f87df8f1e13adefdb8a3f800eec5e | Ruby | snsavage/dynamic-orm-lab-v-000 | /lib/interactive_record.rb | UTF-8 | 1,528 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative "../config/environment.rb"
require 'active_support/inflector'
require 'pry'
class InteractiveRecord
def self.table_name
self.to_s.downcase.pluralize
end
def self.column_names
DB[:conn].results_as_hash = true
sql = "PRAGMA table_info('#{table_name}');"
DB[:conn].execute(sql).ea... | true |
48f4c949d90f39d018f4bdc6210d86101bfba0ab | Ruby | Cfmcewan/homework_weekend_week_2 | /song.rb | UTF-8 | 136 | 2.734375 | 3 | [] | no_license | class Song
attr_reader :title
def initialize(title)
@title = title
end
def get_song_title(title)
return @song1.title
end
end
| true |
4726ccd71ebfb6dbc2809dbb67c79d4db454ab30 | Ruby | esambo/tic_tac_toe | /spec/tic_tac_toe/roles/mark_placer_spec.rb | UTF-8 | 2,655 | 2.921875 | 3 | [] | no_license | require 'spec_helper'
require 'tic_tac_toe/data/player'
require 'tic_tac_toe/data/board_state'
require 'tic_tac_toe/roles/mark_placer'
module TicTacToe
describe MarkPlacer do
let(:board_state) { BoardState.new 3, Player.none, Player.X }
before :each do
board_state.extend MarkPlacer
board_state.s... | true |
4ea4334987d4370429bf0eb56bae7a80e1ef9634 | Ruby | Shelby219/RPSLS_Terminal_App | /src/computer_player.rb | UTF-8 | 359 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'weapons.rb'
require_relative 'rules_engine.rb'
class ComputerPlayer
include Weapons
include RulesEngine
#NICE TO HAVE FEATURE
# def initialize
# @computer_name
# end
def move_shuffle
computer = Weapons::COMPUTER_CHOICES.sample # .to_s.downcase
en... | true |
dedacb860f391ca73d2cee75d4f77a59af814d6d | Ruby | lmarburger/zookeeper-talk | /examples/verified_locking.rb | UTF-8 | 836 | 2.875 | 3 | [] | no_license | # Acquire a lock and verify it before performing some work.
#
# $ bundle exec ruby -I. examples/verified_locking.rb
#
# If explicit cleanup is needed, run the folling in IRB:
#
# $ bundle exec irb -I. -rexamples/requires.rb
# > $zk = ZK.new('127.0.0.1:2181')
# > locker = $zk.exclusive_locker('work')
# > $z... | true |
86cf625c2ac44f9703d5f35f41af85410c425b78 | Ruby | gabeolivares/BankSearch | /custom_validator.rb | UTF-8 | 680 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
def validateParams(lat, long, type)
validation = Hash.new
lat_validation = /^-?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)$/
long_validation = /^-?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)$/
unless lat_validation === lat
validation = { :code => 301, :message => "Latitu... | true |
ac281aa231033275533da50fc4be258072c70f05 | Ruby | newhavenrb/padrino-framework | /padrino-mailer/lib/padrino-mailer/mime.rb | UTF-8 | 1,161 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Padrino
module Mailer
module Mime
##
# Returns Symbol with mime type if found, otherwise use +fallback+.
# +mime+ should be the content type like "text/plain"
# +fallback+ may be any symbol
#
# Also see the documentation for MIME_TYPES
#
# ==== Examples
... | true |
6878fc249508910fe863fe729574ebe87cd4b2ce | Ruby | karunk/Parking-Lot | /lib/models/ticket.rb | UTF-8 | 1,972 | 2.859375 | 3 | [] | no_license | class Ticket
attr_accessor :parked_slot
@@active_ticket_pool = {}
@@tickets_car_colour_map = {}
@@ticket_car_map = {}
def self.issue_ticket!(car)
slot = Slot.new
slot.park!(car)
ticket = Ticket.new(slot)
return ticket
end
def self.active_tickets_for_car_colour(colour)
return @@tick... | true |
701cd7bb410474399803f50f356f519677e24d07 | Ruby | justin-tse/app-academy | /01-intro-to-programming/advanced-problems/all_else_equal.rb | UTF-8 | 636 | 4.53125 | 5 | [] | no_license | # Write a method all_else_equal that takes in an array of numbers. The method
# should return the element of the array that is equal to half of the sum of
# all elements of the array. If there is no such element, the method should return nil.
def all_else_equal(arr)
sum = 0
arr.each { |i| sum += i}
if arr.index(... | true |
d09f321472077579ddb588b7bb5954b723056ae2 | Ruby | johnjvaughn/ls_course101 | /SmallProblems/Easy9/grade_book.rb | UTF-8 | 310 | 3.875 | 4 | [] | no_license | SCORE_TO_GRADE = { 90 => 'A', 80 => 'B', 70 => 'C', 60 => 'D', 0 => 'F' }
def get_grade(score1, score2, score3)
mean = (score1 + score2 + score3) / 3
SCORE_TO_GRADE.each do |level, grade|
return grade if mean > level
end
nil
end
puts get_grade(95, 90, 93) == "A"
puts get_grade(50, 50, 95) == "D" | true |
2fb12efc31639296c35629e8bcf74cd346793f8e | Ruby | rgc3/simple_ruby_programs_tts | /atm.rb | UTF-8 | 2,167 | 4.3125 | 4 | [] | no_license | # Create an ATM Application
# Create a class called Account
# Initialize should take on 3 attributes: name, balance, pin
# Create 4 additional methods: display_balance, withdraw, deposit, and pin_error.
# The user should be prompted to enter their pin anytime they call display_balance, withdraw, or deposit.
# pin_err... | true |
b2d8012e3160b5c8dcdd30c9fe8ed05402e712c5 | Ruby | zzuu666/leetcode-ruby | /cn/234.回文链表.rb | UTF-8 | 1,462 | 3.609375 | 4 | [] | no_license | #
# @lc app=leetcode.cn id=234 lang=ruby
#
# [234] 回文链表
#
# https://leetcode-cn.com/problems/palindrome-linked-list/description/
#
# algorithms
# Easy (39.58%)
# Likes: 371
# Dislikes: 0
# Total Accepted: 56.1K
# Total Submissions: 141.3K
# Testcase Example: '[1,2]'
#
# 请判断一个链表是否为回文链表。
#
# 示例 1:... | true |
11aa0348e884c88247f9d1154f1334d09928d089 | Ruby | orbitalimpact/crystal-meth | /lib/volt/models/array_model.rb | UTF-8 | 9,993 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'volt/reactive/reactive_array'
require 'volt/models/model_wrapper'
require 'volt/models/helpers/base'
require 'volt/models/state_manager'
require 'volt/models/helpers/array_model'
require 'volt/data_stores/data_store'
module Volt
class RecordNotFoundException < Exception ; end
class ArrayModel < ReactiveA... | true |
95725622842b1bbef8d1ce2feee41115751f2633 | Ruby | Nickolai8/rb101 | /ruby_collections/additional_practice/problem7.rb | UTF-8 | 368 | 3.1875 | 3 | [] | no_license | statement = "The Flintstones Rock"
# method 1
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
letter_occurence = {}
alphabet.chars.each do |x|
letter_occurence[x] = statement.count(x) unless statement.count(x) == 0
end
# method 2
letter_occurence = {}
statement.chars.each do |x|
letter_occur... | true |
a4289bb2bfd3bea1bc65fc2b2001cb04e9fe8e66 | Ruby | shawn42/chessbox | /src/ai/glance_ahead_ai.rb | UTF-8 | 1,487 | 3.234375 | 3 | [] | no_license | # Look ahead one move (if I move this piece the new score will be)
require 'evaluator'
class GlanceAheadAI
attr_accessor :board
def do_move!(color = nil)
color = board.turn if color.nil?
board.move! find_move(color)
STDOUT.puts Time.now
STDOUT.flush
end
def find_move(color)
unless board.nil?
# TOD... | true |
b859c9b1e1cebf0b3832814efca86dde99d71bea | Ruby | edwardzhou/lottery | /app/models/ball.rb | UTF-8 | 1,588 | 2.65625 | 3 | [] | no_license | class Ball
include Mongoid::Document
field :ball_name, type: String
field :ball_no, type: Integer
field :odds, type: BigDecimal
field :ball_value, type: Integer
field :big, type: Boolean
field :small, type: Boolean
field :even, type: Boolean
field :odd, type: Boolean
field :add_even, type: Boolean
... | true |
27859e7607344d0476ea8046e9838b9b899a46af | Ruby | vaginessa/inspec | /test/unit/objects/attribute_test.rb | UTF-8 | 1,541 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | # encoding: utf-8
require 'helper'
require 'inspec/objects/attribute'
describe Inspec::Attribute do
let(:attribute) { Inspec::Attribute.new('test_attribute') }
it 'returns the actual value, not the default, if one is assigned' do
attribute.value = 'new_value'
attribute.value.must_equal 'new_value'
end
... | true |
7459ef33bcc2b321d03ca7d9b1597139121a354b | Ruby | funatsufumiya/git-push.sh | /git-push.rb | UTF-8 | 1,904 | 2.59375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'open3'
require 'optparse'
BOLD = "\e[1m"
RED = "\e[31m"
GREEN = "\e[32m"
YELLOW = "\e[33m"
CLEAR = "\e[0m"
CL = CLEAR
OK = "[ OK ]"
WARN = "[ WARN ]"
FATAL = "[ FATAL ]"
# ==============================
def sh(command)
stdout, stderr, process = Open3.capture3(command)
if @quiet == t... | true |
f4665e632b78009e0cbf8252400884576acee942 | Ruby | josephcake/cartoon-collections-dumbo-web-career-010719 | /cartoon_collections.rb | UTF-8 | 550 | 3.4375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(arr)
count = 0
while count < arr.length
puts "#{count+1}. #{arr[count]}"
count += 1
end
end
def summon_captain_planet(arr)
arr.map {|n| n.capitalize + "!"}
end
def long_planeteer_calls(arr)
arr.each do |n|
if n.length > 4
return true
end
end
return false
end
def find_the_chees... | true |
2495e23dcab87d84dc5c9a794a77adee1cadc35d | Ruby | L-Ghost/dailyprogrammer | /EASY/app/255 - Light Switches/n_light_switches.rb | UTF-8 | 1,620 | 3.78125 | 4 | [] | no_license | class LightSwitches
def initialize
puts "Input the number of light bulbs you want to play with:"
@nlights = gets.chomp.to_i
constructArray
end
def constructArray
@switches = Array.new(@nlights) {"."}
#printSwitches
puts "All the lights are turned off.\n\n"
end
de... | true |
8433e97ef55f57a6f0aba9c33e8b57e024b18678 | Ruby | kc7rwx/Cicada | /tile.rb | UTF-8 | 1,668 | 3 | 3 | [] | no_license | class Tile < Image
def initialize(x,y)
super
@draw = Magick::Draw.new
end
def rand_color
color_string = "rgb("+rand(255).to_s+","+rand(255).to_s+","+rand(255).to_s+")"
color_string
end
def random_stuff
@draw.stroke_width(2)
@draw.stroke(rand_color)
@draw.fill(rand_color)
@d... | true |
cf48b4a7410b7c51f2518b4571cc023641c0c9a1 | Ruby | pharhadnadi/kyubits | /leetcode/learns/explore/hash/4_hash_key_design/dup_trees.rb | UTF-8 | 2,275 | 3.859375 | 4 | [] | no_license | # Find Duplicate Subtrees
# Go to Discuss
# Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.
#
# Two trees are duplicate if they have the same structure with same node values.
#
# Example 1:
#
# 1
# / \
# ... | true |
fd9e8016aeb080ac4fcb0e535d4a9a83963e6e2e | Ruby | amer519/ruby-project-alt-guidelines-nyc04-seng-ft-041920 | /lib/child.rb | UTF-8 | 4,062 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Child < ActiveRecord::Base
has_many :enrollments
has_many :daycares, through: :enrollments
def self.create_new_child
system("clear")
prompt = TTY::Prompt.new
child_name = prompt.ask("Great! Whats your child's name?".colorize(:color => :white, :background => :cyan))
s... | true |
965766b9a930fa20702df5b516e819ab4cdb605e | Ruby | tanaken0515/ruby-examination | /gold/challenge01/ex39/sample02.rb | UTF-8 | 71 | 3.140625 | 3 | [] | no_license | def method(val)
yield(15 + val)
end
p method(100){|arg| 100 + arg }
| true |
54962bd4fcd120deb51d929ce9babac84262636e | Ruby | naota/gentwoo | /server/app/helpers/emerges_helper.rb | UTF-8 | 738 | 2.65625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
module EmergesHelper
def viewDuration(dur)
days = dur.divmod(24*60*60)
hours = days[1].divmod(60*60)
mins = hours[1].divmod(60)
if days[0] > 0
days[0].to_s + t(:day) + hours[0].to_s + t(:hour) + mins[0].to_s + t(:minute)
elsif hours[0] > 0
hours[0].to_s + t... | true |
0ab23df78df4141aa747f54a3f9b306cce95ab14 | Ruby | natalia-ku/Algorithms-and-Data-Structures-Exercises | /general, numbers, arrays/find_next_greater_element.rb | UTF-8 | 650 | 4.15625 | 4 | [] | no_license | # Next Greater Element
# Given an array, print the Next Greater
# Element (NGE) for every element. The Next
#greater Element for an element x is the
#first greater element on the right side
#of x in array. Elements for which no greater
#element exist, consider next greater element
#as -1.
def find_next_greater_elemen... | true |
0f17ee5647b9d5e091fbae48f803ddcec86c3ac6 | Ruby | Kreitech/active_service | /spec/support/hook_builder.rb | UTF-8 | 702 | 2.578125 | 3 | [
"MIT"
] | permissive | module HookBuilder
def build_hooked(&block)
hooked = Class.new
hooked.class_eval do
include ActiveService::Hooks
attr_reader :steps
def initialize
@steps = []
end
def execute(*_args)
self.class.run_before_hooks(self)
self.class.run_around_hooks(self) ... | true |
fb9d35f28787e305dc1ad84ea27f0e6347315c2a | Ruby | michaeljohnsargent/complete_ror_developer | /S2/section2_analyzer3.rb | UTF-8 | 1,184 | 4.75 | 5 | [] | no_license | def multiply(number_1, number_2)
number_1.to_f * number_2.to_f
end
def divide(number_1,number_2)
number_1.to_f / number_2.to_f
end
def subtract(number_1,number_2)
number_1.to_f - number_2.to_f
end
def add(number_1,number_2)
number_1.to_f + number_2.to_f
end
def mod(number_1,number_2)
number_1.to... | true |
997a2e6ada84344ca9c1637d1a5f21c9b9e0f061 | Ruby | rfrm/uninortehorarios | /lib/tasks/uninorte.rake | UTF-8 | 1,846 | 2.5625 | 3 | [] | no_license | # Encoding: utf-8
require 'erb'
require 'set'
require 'yaml'
namespace :uninorte do
desc 'creates the codes.yml file'
task create_codes: :environment do
pool = CodeGetter.pool size: 16
codes =
Set.new((1000..9999).to_a.map { |nrc| pool.future.get_code(nrc) }.map(&:value).reject(&:nil?))
file_con... | true |
182337f7dd9fd3697314b4634c9d58ae504b0628 | Ruby | tvojnar/capstone_backend | /test/models/waypoint_test.rb | UTF-8 | 871 | 2.53125 | 3 | [] | no_license | require "test_helper"
describe Waypoint do
let :hike {Hike.create(name: 'test hike', start_lat: 47.6062, start_lng: 122.3321)}
describe 'relationships' do
it 'belongs to a hike' do
w = Waypoint.new(hike_id: hike.id, lat: 47.6062, lng: 122.3321)
w.must_respond_to :hike
w.hike.must_equal hike
... | true |
cafef9540259d124e79694befa7935f6ea124160 | Ruby | bogardpd/flight_log | /test/classes/aero_api4_test.rb | UTF-8 | 4,241 | 2.515625 | 3 | [
"MIT"
] | permissive | require "test_helper"
class AeroAPI4Test < ActiveSupport::TestCase
def setup
flight = flights(:flight_ord_dfw)
ident = "#{flight.airline.icao_code}#{flight.flight_number}"
@samples = {
ident: ident,
fa_flight_id: "#{ident}-#{flight.departure_utc.to_i}-airline-0001",
origin_airport_ic... | true |
b7a62838e136b9a55297986a44d2f71deab51a90 | Ruby | jph98/ant-colony-optimisation | /world.rb | UTF-8 | 2,585 | 3.828125 | 4 | [] | no_license | #!/usr/bin/env ruby
require_relative "cell"
require_relative "food"
class World
attr_accessor :interval
DEBUG = false
# user_width - width of the board
# user_height - height of the board
# interval - interval to wait inbetween making moves
# ants_random_direction_change - whether Ants should randomly change... | true |
6e1223753eb3327907f9412945fa7885dca72358 | Ruby | orenmazor/capacity-monitor | /lib/tasks/list.rake | UTF-8 | 1,491 | 2.53125 | 3 | [] | no_license |
namespace :newrelic do
desc "list hosts from newrelic"
task :list_hosts => [:environment] do
servers = Newrelic.get_servers
puts "agent id\t\thostname"
servers.each do |s|
puts "#{s["id"]}\t\t#{s["hostname"]}"
end
end
def print_metrics(agent_id)
metrics = Newrelic.get_metrics(agent_i... | true |
c48141995993ce3dc12c0b3b8d14516e5cd3ea8e | Ruby | sanbefo/Nested_Arrays2 | /Nested_Arrays2.rb | UTF-8 | 850 | 3.375 | 3 | [] | no_license | #METODO QUE CREA UN TABLERO DE GATO Y LO LLENA DE FORMA
#AE
def gato(x, o)
tablero = []
i = 0
if x > o
until i == 9
n = Random.rand(9)
if tablero[n] == nil
m = i % 2
if i % 2 == 0
tablero[n] = "X"
i += 1
else
tablero[n] = "O"
i += 1
end
else
n = Random.rand(9)
en... | true |
1827f762379e65e58338be4a96ea649c90514796 | Ruby | alexandersdickinson/restaurants | /lib/food.rb | UTF-8 | 716 | 3.3125 | 3 | [] | no_license | class Food
attr_reader(:name, :price)
def initialize(attributes)
@name = attributes.fetch(:name)
@price = attributes.fetch(:price)
@id = nil
end
def ==(comparison)
self.name() == comparison.name()
end
def self.all()
returned_food = DB.exec("SELECT * FROM food;")
foods = []
... | true |
f88eda3c7db5daf938fb751a713354d2f93936bd | Ruby | bitcoupon/bitcoupon-on-rails | /ruby-java-integration/socket_example/socket.rb | UTF-8 | 295 | 2.625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'rubygems'
require 'socket'
i = 0
server = TCPServer.new 2000
def json(id)
'{"id":' + id.to_s + ', "name":"coupon"}'
end
loop do
Thread.start(server.accept) do |client|
client.puts json(i += 1)
puts "Server: #{client.gets}"
client.close
end
end
| true |
6a3094c00867311bb2a549b8ee9ed2a7081f7433 | Ruby | tribesports/rollup | /lib/rollup/sentence_vector_maker.rb | UTF-8 | 944 | 3.046875 | 3 | [] | no_license | require 'java'
import org.apache.mahout.math.RandomAccessSparseVector
module Rollup
class SentenceVectorMaker
def initialize(analyzer, dictionary, text_encoder)
@analyzer = analyzer
@dictionary = dictionary
@text_encoder = text_encoder
@examples = []
end
def add_example(example)
... | true |
3ee4dedc0e7da10c974e9e52c33003c36ea5a090 | Ruby | ErickG123/miniProjetosRubyOBC | /aula2/hello.rb | UTF-8 | 177 | 3.765625 | 4 | [] | no_license | # Sáida de dado
# Print não pula linha
print 'Digite seu nome: '
# Recebendo o valor digitado
name = gets.chomp
# Imprimindo a saída concatenada
puts "Seu nome é: #{name}" | true |
6c223cc0bb3a93b0c0e739a97cb1bca8cfff766f | Ruby | parrot/parrot | /examples/benchmarks/oofib.rb | UTF-8 | 380 | 3.71875 | 4 | [
"Artistic-2.0"
] | permissive | #! ruby
class A
def fib(n)
return n if (n < 2)
return fibA(n - 1) + fibB(n - 2)
end
def fibA(n)
return n if (n < 2)
return fib(n - 1) + fibB(n - 2)
end
end
class B < A
def fibB(n)
return n if (n < 2)
return fib(n - 1) + fibA(n - 2)
end
end
b = B.new
N = In... | true |
a4f3c59598d1b5effd7bb47bcdef7a15b965370d | Ruby | tackyunicorn/hello-ruby | /calculator.rb | UTF-8 | 236 | 4.4375 | 4 | [] | no_license | # Ruby converts whatever you enter into a string, so convert it
# to float with to_f() or to integer with to_i()
puts "Enter a number: "
num1 = gets.chomp().to_f()
puts "Enter a number: "
num2 = gets.chomp().to_f()
puts (num1 + num2) | true |
a2a4644c5698e69ae2358f91f1df2d82985e9777 | Ruby | RootSeven/Sheet_Music_Catalogue | /models/piece.rb | UTF-8 | 2,915 | 3.125 | 3 | [] | no_license | require('pg')
require_relative('../db/sql_runner.rb')
require_relative('piece.rb')
require_relative('piece_location.rb')
class Piece
attr_reader :id
attr_accessor :name, :suite, :movement, :catalogue_name, :opus, :work_number, :composer
def initialize(options)
@id = options['id'].to_i if options['id']
... | true |
591fc47a764dda0c40da4204e5ddf3aa841cc870 | Ruby | japmelian/ruby_tutorial | /ruby_primer/problem02/length_string.rb | UTF-8 | 356 | 3.9375 | 4 | [] | no_license | # PROBLEM 02
# Given an array containing some strings, return an array
# containing the hength of those strings
# You are supposed to write a method named 'length_finder'
# to accomplish this task
def length_finder(input_array)
output_array = input_array.map{ |string| string.length}
end
A = ['My', 'nickname', 'is', ... | true |
2f7499804ed46a7d2d61cb42d3f17197ca64b0a4 | Ruby | flavray/url-shortener | /http/request.rb | UTF-8 | 521 | 3.1875 | 3 | [] | no_license | class Request
attr_reader :method, :uri, :headers, :body
# request from a TCP socket, HTTP request-line, headers and body
def initialize(socket)
# read request-line
@method, @uri = socket.gets.split
@headers = {}
# read headers
loop do
name, value = socket.gets.split(" ", 2)
brea... | true |
c0b552748989e496d27295a66524887da7c4f2df | Ruby | Freaky/tarssh | /extra/tarssh_log_stats.rb | UTF-8 | 1,863 | 2.9375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'time'
def ft(t)
if t >= 86400
"%.1fd" % (t / 86400.0)
elsif t >= 3600
"%.1fh" % (t / 3600.0)
elsif t >= 60
"%.1fm" % (t / 60.0)
else
"%.0fs" % t
end
end
history = []
clients = {}
startup = nil
ARGF.each_line do |line|
prefix, data = line.split('] ', 2)
ts =... | true |
6d73c70d412e0f5d2e4a5bcaf59e2640234660a5 | Ruby | github/puppetlabs-puppet | /test/util/utiltest.rb | UTF-8 | 5,766 | 2.6875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
require 'puppettest'
require 'mocha'
class TestPuppetUtil < Test::Unit::TestCase
include PuppetTest
def test_withumask
oldmask = File.umask
path = tempfile
# FIXME this fails on FreeBSD with a mode of 01777... | true |
586e3bbd8bf73fa06fe782de3651c0a6c2230ad2 | Ruby | kirirotha/programming-univbasics-nds-green-grocer-part-2-hou01-seng-ft-071320 | /lib/grocer_part_2.rb | UTF-8 | 2,454 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative './part_1_solution.rb'
def apply_coupons(cart, coupons)
# Consult README for inputs and outputs
#
# REMEMBER: This method **should** update cart
new_cart=cart
coupons.each do |coupon_item|
cart.each do |cart_item|
if cart_item[:item] == coupon_item[:item]
if cart_item[:coun... | true |
d248a4d5cd1ad3d5211ee528051942e0a60e16cd | Ruby | zzeni/evans | /features/step_definitions/solutions_steps.rb | UTF-8 | 2,728 | 2.78125 | 3 | [] | no_license | # encoding: utf-8
Дадено 'че "$name" има следните решения:' do |name, table|
task = Factory(:closed_task, :name => name)
table.hashes.each do |row|
attributes = {
:user => Factory(:user, :full_name => row['Студент']),
:task => task,
:passed_tests => row['Успешни'],
:failed_tests => row[... | true |
5a72451f30aec32554f5f545cdf37df7bd2ff8b1 | Ruby | MickeyOoh/AlgorithmPuzzle | /Ruby/q11_2.rb | UTF-8 | 152 | 3.203125 | 3 | [] | no_license | N = 7
def vote(n)
return 1 if n <= 2
v1 = vote(n - 1)
v2 = 0
2.upto(n - 1) do |i|
v2 += vote(i)
end
1 + v1 + v2 * v1
end
puts vote(N)
| true |
d59db15f9e055ebea36d305f0a94ce39100ecab2 | Ruby | Alprather/TicTacToe | /spec/board_spec.rb | UTF-8 | 377 | 2.59375 | 3 | [] | no_license | require "spec_helper"
module TicTacToe
describe Board do
context "#initialize" do
it "initializes the board" do
expect { Board.new }.to_not raise_error
end
end
context "#grid" do
it "returns the grid" do
board = Board.new
expect(board.grid).to eq [1, ... | true |
d3381e7c26cf28d40c56655d889b624a02ac619f | Ruby | bizdev324/Ruby-on-Rails-Music-Product | /db/seeds.rb | UTF-8 | 4,178 | 2.65625 | 3 | [] | no_license | require 'faker'
# Remember to install ImageMagick + ffmpeg
def image_path( image )
Rails.root.join( 'app', 'assets', 'images', 'seeds', image )
end
def audio_path( audio )
Rails.root.join( 'app', 'assets', 'audios', audio )
end
def cover_file( name )
File.open( image_path( name ) )
end
def audio_file(name)
... | true |
c41d25aa9f67e75aff6a8da518098f51d3cfa879 | Ruby | JaesonWatts/theAmazingSystemFinder | /lib/animation.rb | UTF-8 | 1,044 | 2.875 | 3 | [
"MIT"
] | permissive |
class Animation
@anim_text_ing = ["scraping","loading","fetching", "pinging"]
@anim_text_er = ["scraper","loader", "fetcher",]
@anim_char_array = ["-","\\","|","/","-"]
def self.scraperforchris
system "clear"
ing_sample = @anim_text_ing.sample
er_sample = @anim_text_er.sample
7.times do
... | true |
3f8a0689b948963bdfa2d54f46382b47c2e41c30 | Ruby | damenturnbull/poignant | /ch_4/gets.rb | UTF-8 | 111 | 3.5 | 4 | [] | no_license | # 'puts' is a kernel method
print "Enter your favourite beer: "
backwards = gets.upcase.reverse
puts backwards | true |
784fe6a22017eca7d1f802cbe027b06942a690f2 | Ruby | ed-creator/oystercard | /lib/oystercard.rb | UTF-8 | 974 | 3.515625 | 4 | [] | no_license | require_relative 'station'
class Oystercard
attr_reader :balance, :entry_station, :journey_history
MAX_LIMIT = 90
MIN_CHARGE = 1
def initialize()
@balance = 0
@journey_history = []
end
def touch_in(station)
fail "Insufficient Balance" unless min_balance?
self.entry_station = station
... | true |
4ac0114d5a1f0e4b87c1bae4310a9c4924607a46 | Ruby | marclevetin/learning-recursion | /cut-pizza-extra-credit.rb | UTF-8 | 744 | 4.375 | 4 | [] | no_license | # From https://softwareengineering.stackexchange.com/questions/25052/in-plain-english-what-is-recursion
# Extra Credit The cut_pizza example above will give you a stack level too deep
# error if you ask it for a number of slices that isn't a power of 2 (i.e 2 or
# 4 or 8 or 16). Can you modify it so that if someone as... | true |
7f353ab3c1e0b34231c6fc320a286609bc87549e | Ruby | Tim-B/ef2 | /lib/ef2/domain/collection_entry.rb | UTF-8 | 395 | 3.03125 | 3 | [
"MIT"
] | permissive | class CollectionEntry
attr_reader :entry
def initialize(entry, &block)
@entry = entry
@quantity = 1
(block.arity < 1 ? (instance_eval &block) : block.call(self)) if block_given?
end
def quantity(quantity=nil)
quantity.nil? ? @quantity : @quantity = quantity
end
def pick(strategy)
@pi... | true |
00cb71bc144af903b704828868d9dbc983dd9450 | Ruby | wemrysi/jruby-scala | /lib/jruby_scala/core_ext/operator_translations.rb | UTF-8 | 3,904 | 2.953125 | 3 | [
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module JrubyScala
module CoreExt
# Provides translations between the standard set of Ruby operators and their
# Scala counterparts allowing the natural use of Ruby operators on Scala
# objects.
#
# Currently, translates the ruby-style array/hash access operator #[] and
# handles Proc methods o... | true |
26a864ced86d9ffae73b3133187240876c5fd39b | Ruby | takupaca/run_vco_workflow | /kick_vco_workflow.rb | UTF-8 | 2,246 | 2.765625 | 3 | [] | no_license | #!/usr/local/bin/ruby
#
# Usage: ruby kick_vco_workflow.rb {options}
# -w, --workflow VALUE Workflow Name
# -u, --username VALUE vCO User Name
# -p, --password VALUE Password
# -h, --host VALUE vCO Host
#
require 'optparse'
username = "vcoadmin"
passwo... | true |
e7499d3b3e8fe84eb5af224c13133373d4f2d88f | Ruby | Commit451/android-sdk-installer | /lib/android-sdk-installer.rb | UTF-8 | 4,388 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'psych'
require 'logger'
require 'optparse'
module AndroidInstaller
# Installs components for building Android projects
# noinspection RubyClassVariableUsageInspection
class Installer
KEY_SDK_TOOLS = '{ANDROID_SDK_TOOLS}'
KEY_PLATFORM = '{PLATFORM}'
SDK_URL = 'https://dl.google.com'
SDK_... | true |
e5651665a6ef3b2988f0122c6930ab277487449f | Ruby | smcunning/backend_mod_1_prework | /day_4/exercises/ex19.rb | UTF-8 | 2,876 | 4.3125 | 4 | [] | no_license | # Defines the method as cheese_and_crackers and sets the argument to include
# cheese_count and boxes_of_crackers
def cheese_and_crackers(cheese_count, boxes_of_crackers)
# Prints line below and includes the cheese_count variable.
puts "You have #{cheese_count} cheeses!"
# Prints the line below and includes the boxes... | true |
754de56d28fb2b2f0a57da8a733d42c8514cedf7 | Ruby | kassi/geocaching | /lib/core_ext/float.rb | UTF-8 | 258 | 3.125 | 3 | [
"MIT"
] | permissive | class Float
def crossfoot
result = 0
self.to_s.chars.each do |char|
result += char.to_i
end
result
end
def iterated_crossfoot
result = self.crossfoot
result = result.crossfoot while result.digits > 1
result
end
end
| true |
a981cdebbe370b8e3a836ad7a68c70ad001227cd | Ruby | dnesteryuk/site_prism.vcr | /spec/unit/fixture_spec.rb | UTF-8 | 3,302 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe SPV::Fixture do
describe '#name' do
subject { described_class.new(name) }
context 'when there is only a name' do
let(:name) { 'test' }
it 'has correct name' do
expect(subject.name).to eq('test')
end
end
context 'when there is a name with pat... | true |
52eb329571ae240e76a9197128a256bbc2ad2054 | Ruby | jacobabarbary/Dekki | /yaml2text.rb | UTF-8 | 429 | 2.796875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'yaml'
data = YAML.load_file(ARGV[0])
puts data.inspect
new_data = File.open("data/animeCommonCardsAnki", "w")
data.each_pair do |k, v|
writing = v[:writing]
reading = v[:reading]
desc = v[:desc]
frequency = v[:frequency]
puts "row #{k} => #{reading}"
new_data.puts "wri... | true |
78034347a18a3bf3769d0cc9a0984e1d424c68d9 | Ruby | joshbuddy/rack-console | /lib/rack_console.rb | UTF-8 | 2,312 | 2.71875 | 3 | [] | no_license | require 'gserver'
require 'thread'
require 'json'
module Rack
class Console
@@stats = Hash.new{|h,k| h[k] = []}
@@gather_stats = false
@@watch = false
@@watch_queue = []
Watch = Struct.new(:time, :env, :response)
def self.watch_queue
@@watch_queue
end
def se... | true |
8f89728bc33371ae876f877f39966f319dfd69b9 | Ruby | arthurfincham/premierleagueproject | /scraper.rb | UTF-8 | 1,090 | 2.90625 | 3 | [] | no_license | require 'httparty'
require 'nokogiri'
require 'byebug'
def scraper
url = "https://www.soccerstats.com/latest.asp?league=england"
unparsed_page = HTTParty.get(url)
parsed_page = Nokogiri::HTML(unparsed_page)
# Club name.
club_total = parsed_page.css('table#btable').css('tr.odd').css("[align='left']"... | true |
de7ad2cf07e7d22cbe40abf5545b882391673aa7 | Ruby | 7ruth/landlord | /db/seeds.rb | UTF-8 | 1,363 | 2.65625 | 3 | [] | no_license | require_relative "connection"
require_relative "../models/apartment"
require_relative "../models/tenant"
Apartment.destroy_all
Tenant.destroy_all
apartment1= Apartment.create(address:"International Space Station #1", monthly_rent: 999999, sqft: 400, num_beds: 0, num_baths: 0)
apartment2= Apartment.create(address:"Giz... | true |
68595181bb1a235debd8b3a1a58137e534104b9b | Ruby | akanshmurthy/codelearnings | /appacademy/w1d1/ghost.rb (do phase 3).rb | UTF-8 | 1,986 | 3.78125 | 4 | [] | no_license | class Game
attr_accessor :fragment
LOSSES = {1 => "G", 2 => "H", 3 => "O", 4 => "S", 5 => "T"}
def initialize
@fragment = ""
@dictionary = File.readlines("ghost-dictionary.txt")
end
def change(val)
@fragment << val
end
def valid_play?(string)
if ("a".."z").to_a.include?(string)
r... | true |
be0e39560db8c2e36d2caa12305cbbb9f37520ab | Ruby | kmdtmyk/rsql | /lib/rsql/sql_text.rb | UTF-8 | 1,614 | 3.0625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Rsql
class SQLText
def self.split(text)
new(text).split
end
def initialize(text)
@text = text
end
def split
[0, *split_positions, @text.length]
.each_cons(2)
.map{ |first, last| @text[first...last]}
.filter{ |text| ... | true |
6dc6eb260280bad33d14f65cb7209a380dcda6ab | Ruby | sridharbs/sridds | /ticketing_app/app/models/user.rb | UTF-8 | 651 | 2.640625 | 3 | [] | no_license | class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :gender
has_and_belongs_to_many :events
validates_presence_of :name, :gender
... | true |
b14375eb7ef614ee8745c2dd8da608f20090cf01 | Ruby | ashleymichal/the_odin_project | /ruby/oop/tictactoe/lib/tic_tac_toe.rb | UTF-8 | 2,294 | 3.6875 | 4 | [] | no_license | class TicTacToe
SPACES = [ :A1, :A2, :A3, :B1, :B2, :B3, :C1, :C2, :C3 ]
WINNING_COMBINATIONS = [
[:A1, :A2, :A3], [:B1, :B2, :B3], [:C1, :C2, :C3],
[:A1, :B1, :C1], [:A2, :B2, :C2], [:A3, :B3, :C3],
[:A1, :B2, :C3], [:A3, :B2, :C1]
]
attr_reader :players, :active_player, :board
def initialize
... | true |
f9c64c5601fe680dd22a681b36e502488dc01198 | Ruby | takanemirai/potatoes-to-potatoes | /models/purplepotato.rb | UTF-8 | 783 | 2.71875 | 3 | [] | no_license | class PurplePotato
def initialize
@nouns =
"Dragon: The mythical creature that pwns all others. Enough said.",
"Fencing: Sport that involves stabbing people with cool sticks",
"Myspace: ...",
"Nicolas Cage: 'Bangers and mash! Bubbles and squeak! Smoked eel pie! Haggis!'",
"N00b: An ine... | true |
f5dd0df2c3432e44630bffe2e148a0572688c099 | Ruby | vladveterok/ruby | /learning/profiler.rb | UTF-8 | 468 | 3.53125 | 4 | [] | no_license | def profile block_description, &block
prof_on = true #thumbler turns profile method on/off
if prof_on
start_time = Time.new
block.call
duration = Time.new - start_time
puts "#{block_description}: #{duration} seconds"
else
block.call
end
end
profile '25000 doublings' do
number = 1
25000.times do
n... | true |
041311506d276840bbdb155ec3a1823ea40b3435 | Ruby | dvopalecky/launchschool | /introduction_to_programming/files/files.rb | UTF-8 | 989 | 2.765625 | 3 | [
"MIT"
] | permissive | require "json"
require "nokogiri"
require "axlsx"
require "csv"
slashdot_articles = []
File.open("slashdot.xml", "r") do |f|
doc = Nokogiri::XML(f)
slashdot_articles = doc.css('item').map do |i|
{
title: i.at_css('title').content,
link: i.at_css('link').content,
summary: i.at_css('description... | true |
3ddaac06959eda3e7defde1514c1c31bc116dba5 | Ruby | agallant121/pet_shop_paired | /app/models/favorite.rb | UTF-8 | 428 | 2.90625 | 3 | [] | no_license | class Favorite
attr_reader :pets
def initialize(pets)
@pets = pets || Hash.new(0)
end
def add_pet(id)
@pets[id] = 0
end
def favorite_count
@pets.count
end
def selected_pets
Pet.find(@pets.keys)
end
def remove_pet_id(pet_id)
@pets.delete(pet_id)
end
def remove_all
@p... | true |
bf331a7721a4f1903bc7d1b21c0b192a7e35657d | Ruby | jatin837/theodinproject | /app/services/next_lesson.rb | UTF-8 | 781 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-unknown",
"MIT"
] | permissive | class NextLesson
def initialize(course, lesson_completions)
@course = course
@lesson_completions = lesson_completions
end
def to_complete
next_lesson_to_complete || remaining_lesson_to_complete
end
private
attr_reader :course, :lesson_completions
def lessons_left_to_complete
course.les... | true |
053df12a32aa771c473b37d597b0ea339a0483d5 | Ruby | JYCSEC/W4P_MassAssignment2 | /howdoIruby2.rb | UTF-8 | 504 | 2.515625 | 3 | [] | no_license | s = Random.new(0)
rand(1000).times {s.rand(5)}
passadmin = 6.times.map { ('a'..'z').to_a[s.rand(('a'..'z').to_a.size)]}.join
passhacker = 6.times.map { ('a'..'z').to_a[s.rand(('a'..'z').to_a.size)]}.join
n = 0
puts passhacker
while passhacker != 'uvddhj' do
s = Random.new(0)
n.times {s.rand(5)}
passadmin = 6.times.m... | true |
be9b0ef63e15ab20a56abf1e221e8b2be097634e | Ruby | alectower/time_tracker | /lib/time_tracker/tracker.rb | UTF-8 | 1,018 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require_relative 'entry_log'
module TimeTracker
class Tracker
attr_reader :project, :task, :description
private :project, :task, :description
def initialize(args)
fail 'Project name required' unless !args[:project].nil?
fail 'Task name required' unless !args[:task].nil?
@project = arg... | true |
af7a33e3494fbd5068c4950f08a26f9f5e007446 | Ruby | mashedkeyboard/zxcvbn-ruby | /lib/zxcvbn/matchers/new_l33t.rb | UTF-8 | 4,085 | 3.125 | 3 | [
"MIT"
] | permissive | module Zxcvbn
module Matchers
class L33t
L33T_TABLE = {
'a' => ['4', '@'],
'b' => ['8'],
'c' => ['(', '{', '[', '<'],
'e' => ['3'],
'g' => ['6', '9'],
'i' => ['1', '!', '|'],
'l' => ['1', '|', '7'],
'o' => ['0'],
's' => ['$', '5'],
... | true |
c635e0a0596e8d9cd9f6b49be2a3ec71727752fc | Ruby | polishgeeks/polishgeeks-dev-tools | /lib/polish_geeks/dev_tools/hash.rb | UTF-8 | 847 | 2.875 | 3 | [] | no_license | module PolishGeeks
module DevTools
# Hash extensions required only by rake tasks in this rake file
# No need to add them to app itself
# We don't put it directly into hash, since it won't be used outside of
# this gem
class Hash < ::Hash
# @param other [Hash] different hash that we want to c... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.