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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
0089f38d59d01eb6464fc9e6df6ec4fc886abb99 | Ruby | joshwalsh/Toroid | /app/services/persist_state.rb | UTF-8 | 762 | 2.703125 | 3 | [] | no_license | class PersistState
def initialize(current_state)
@current_state = current_state
end
def save(new_content)
@current_state.write new_content
@current_state.rewind
end
def load
@current_state.read.tap { @current_state.rewind }
end
def self.save(game)
File.open(self.file_path, "w+") do... | true |
42614861d42154073cbceb35b987465a9751cce8 | Ruby | wellavelino/image-comparable | /lib/image_comparable/image_diff.rb | UTF-8 | 1,316 | 2.765625 | 3 | [
"MIT"
] | permissive | class ImageDiff
def initialize(baseline, screenshot, acceptant_criteria)
@baseline = baseline.image
@screenshot = screenshot.image
@diff = []
@baseline.height.times do |y|
@baseline.row(y).each_with_index do |pixel, x|
@diff << [x, y] unless pixel == @screenshot[x, y]
end
e... | true |
69e4312f8046beb7e70781b7e564f52aa39442ba | Ruby | MustafaTaha15/ttt-10-current-player-re-coded-000 | /lib/current_player.rb | UTF-8 | 200 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def turn_count(board)
count=0
board.each do |mt|
if mt=="X" || mt=="O"
count+=1
end
end
count
end
def current_player(board)
if turn_count(board) % 2 == 0
return "X"
else
return "O"
end
end
| true |
7a41b1ebb1dd1bae6a49249a62b0d2de3fc2a665 | Ruby | Svischev/my_blog | /app/helpers/blogs_helper.rb | UTF-8 | 1,248 | 2.6875 | 3 | [] | no_license | module BlogsHelper
# Вывести все посты блога пользователя, который смотрим
def get_blogs()
user_id_which_created_blog = get_user_id_which_created_blog()
if !user_id_which_created_blog.blank?
user = User.find(get_user_id_which_created_blog())
blogs = user.blogs #Blog.where(user_id: user.id)
end
return bl... | true |
57f7f18da27af24764c5b8a958d0b9fb4af8e0c4 | Ruby | JuanitoFatas/OJAD | /lib/ojad/result.rb | UTF-8 | 644 | 2.890625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative "verbs"
module OJAD
class Result
def initialize(response)
@response = response
end
def to_human
if response.success?
verbs_for_human
else
error_message
end
end
private
attr_reader :response
LINE = ... | true |
1ea5d8474f1b976a952532918b2688302a6ea410 | Ruby | mgriffin/mikegriffin | /script/bookmark | UTF-8 | 846 | 2.90625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'date'
require 'mechanize'
date = DateTime.now.strftime("%Y-%m-%dT%H:%MZ")
link = ARGV[0]
title = Mechanize.new.get(link).title
tags = ARGV[1..-1]
slug = DateTime.now.strftime("%Y-%m-%d-") + title .gsub(/\s+/, "-") # replace spaces with -
.gsub(/&/, "-and-") # replac... | true |
2c3d9c63c2cd8ab1581782d84f17747d9bda442f | Ruby | rec0de/obdd-gen | /benchmark/bdd-gen/formula-gen.rb | UTF-8 | 1,263 | 3.296875 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | class MockFormula
@@varCount = 4
@@vars = "abcdefghijklmnop"
def genFormula()
generatePureExpr()
end
def generatePureExpr()
generateImpl()
end
def generateImpl()
if chance(0.3)
op = ["->", "<=>", "=>", "<->"].sample
return "#{generateOr()} #{op} #{generateOr()}"
else
return generateOr()
en... | true |
c9edb3078bddee53f7432c294844b79b0589d670 | Ruby | need47/fselector | /lib/fselector/algo_discrete/Specificity.rb | UTF-8 | 888 | 2.84375 | 3 | [
"MIT"
] | permissive | #
# FSelector: a Ruby gem for feature selection and ranking
#
module FSelector
#
# Specificity (SP)
#
# TN D
# SP = ------- = -----
# TN+FP B+D
#
# ref: [Wikipedia](http://en.wikipedia.org/wiki/Sensitivity_and_specificity)
#
class Specificity < BaseDiscrete
# this algo outpu... | true |
049497ca781841a6140300128b9201c07df59051 | Ruby | Terry814/Ruby-project3 | /lib/rubyrems/emailmatcher.rb | UTF-8 | 5,961 | 2.6875 | 3 | [] | no_license | # process the emails to customers, enquiries etc
# Finds all email where source is not 'python', parsed is true, matched is false and ignore_match is false
# Calls the email.parse_cust_name function for all, sets ignore_match if no customer email
# handle 'in' and 'out' differently
# 'in' - find or create customer, fi... | true |
bfcc3830c51465acb1c421e85215b9c389ff9dfc | Ruby | arturcp/arenah-rails | /lib/legacy/importers/characters_importer.rb | UTF-8 | 913 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
require 'legacy/legacy_character'
require 'legacy/legacy_user'
module Legacy
module Importers
class CharactersImporter
INACTIVE_NAMES_LIST = [
'Guest',
'??'
].freeze
def self.import(characters, users)
puts '3. Creating characters...'
... | true |
77a6ade72c6a4d64b98ba78cc43bedc71bce637d | Ruby | Xabier-Casan-Abia/oo-relationships-practice-london-web-career-040119 | /app/models/airbnb/listing.rb | UTF-8 | 854 | 3.328125 | 3 | [] | no_license | class Listing
attr_reader :city
@@all = []
def initialize(city)
@city = city
@@all << self
end
def self.all
@@all
end
def trips
Trip.all.select { |trip| trip.listing == self }
# - returns an array of all trips at a listing
end
def guests
trips.collect { |trip| trip.guest }.uniq
# -... | true |
2125143f034ebedd4b540cb33db3747c24334675 | Ruby | schmee3spades/Ruby-Quizes-New | /quiz10/Crosswords.rb | UTF-8 | 6,981 | 3.015625 | 3 | [] | no_license | module RubyQuiz
class Crosswords
attr_reader :crossword, :cell_height, :cell_width, :clue_number, :row_separators, :column_separators, :output_string;
def initialize( filename )
@crossword = Array.new()
@row_separators = Array.new()
@column_separators = Array.new()
load_file( ... | true |
3313c07f5c9942f35d1d3a815fd02207adeda02d | Ruby | FreddieR96/negotiator-timetable | /app/helpers/main_helper.rb | UTF-8 | 212 | 2.65625 | 3 | [] | no_license | module MainHelper
class Result
attr_reader :arrive_at, :label, :leave_at
def initialize(arrival, label, leave = 30)
@arrive_at = arrival
@label = label
@leave_at = @arrive_at + leave.minutes
end
end
end
| true |
915e671507f7e341eb4b07a1b97f77ce743e5636 | Ruby | tkbeili/august_2016_fundamentals | /ruby_3/cat.rb | UTF-8 | 293 | 4.03125 | 4 | [] | no_license | require "./animal.rb"
class Cat < Animal
def catch(bird)
@bird = bird
puts "The cat #{@name} caught bird #{bird.name}"
end
def eat
if @bird
puts "The car #{@name} ate the bird #{@bird.name}"
@bird = nil
else
puts "No bird to eat!"
end
end
end
| true |
4658d75d6b7a8b286d39bc3b6aa7b8ae6f500ef5 | Ruby | dbrewster42/Ruby | /Project TDD/project_spec.rb | UTF-8 | 1,374 | 3.390625 | 3 | [] | no_license | require_relative 'project'
# include our Project class in our spec file
RSpec.describe Student do
before(:each) do
@project1 = Student.new('Project 1', 'description 1')
@project2 = Student.new('Project 2', 'description 2')
# create a new project and make sure we can set the name attribute
en... | true |
15b0d398a52318cd07724a60d10b4a12396d977f | Ruby | NguyenTuanLong/Rails | /app/models/post.rb | UTF-8 | 1,030 | 2.71875 | 3 | [] | no_license | class Post < ApplicationRecord
belongs_to :user
before_destroy :check_if_has_line_item
validate :check_if_price_and_cost
validates :title, :body, :price, :cost, :quantity, presence: true
validates :price, numericality: {greater_than_or_equal_to: 1000}
validates :cost, numericality: {greater_than... | true |
f6a989b2cd1ee6dbcbccd0a0a7aa184be867080c | Ruby | juanmaberrocal/game-scoreboard | /app/helpers/slash_command_action_service_picker.rb | UTF-8 | 637 | 2.671875 | 3 | [] | no_license | class SlashCommandActionServicePicker
attr_reader :action, :model
def initialize(action, model)
@action = action
@model = model
end
def select(params)
service_string = "#{SLASH_COMMAND_ACTIONS_PREFIX}"\
"#{model}_#{action}"\
"#{SLASH_COMMAND_ACTIONS_SUFIX}... | true |
c5b84ae05921c8346a17ad1d02b1dabe2dd1fd58 | Ruby | fytzzz/easy-blog | /app/models/setting.rb | UTF-8 | 3,178 | 2.59375 | 3 | [] | no_license | # encoding: utf-8
# renfences Redmine - project management software
class Setting < ActiveRecord::Base
DATE_FORMATS = [
'%Y-%m-%d',
'%d/%m/%Y',
'%d.%m.%Y',
'%d-%m-%Y',
'%m/%d/%Y',
'%d %b %Y',
'%d %B %Y',
'%b %d, %Y',
'%B %d, %Y'
]
TIME_FORMATS = [
'%H:... | true |
d2864ebb8c5ea1f512986ace04248d116269fcb4 | Ruby | vdpham326/Ruby_Intro | /conditionals_arrays/doubler.rb | UTF-8 | 215 | 3.765625 | 4 | [] | no_license | def doubler(number)
new_arr = []
i = 0
while i < number.length
new_arr << number[i] * 2
i += 1
end
return new_arr
end
print doubler([1, 2, 3, 4])
puts
print doubler([7, 1, 8]) | true |
b53bb6ede065cf1fc41433ea850131bec86e37f2 | Ruby | sjbach/lusty | /src/lusty/buffer-grep.rb | UTF-8 | 5,981 | 2.65625 | 3 | [] | no_license | # Copyright (C) 2007 Stephen Bach
#
# Permission is hereby granted to use and distribute this code, with or without
# modifications, provided that this copyright notice is copied with it. Like
# anything else that's free, this file is provided *as is* and comes with no
# warranty of any kind, either expressed or implie... | true |
302869c36753941618aa9fe33ef8c6435f4d7cef | Ruby | PhilippaElliott/intro_to_ruby | /chapter_4/all_caps.rb | UTF-8 | 171 | 3.53125 | 4 | [] | no_license | def all_caps(string)
if string.length > 10
string.upcase!
else
string
end
end
puts all_caps("I think this is wrong")
puts all_caps("maybe not")
| true |
c8531166f7ac185c983879b4c4b54f0843e7ddf9 | Ruby | Atar97/W2D1-projects | /chess/display.rb | UTF-8 | 506 | 3.109375 | 3 | [] | no_license | require 'colorize'
require_relative 'board'
require_relative 'cursor'
class Display
attr_reader :cursor
def initialize(board=Board.new)
@board = board
@cursor = Cursor.new([0,0],@board)
end
def render
system('clear to start')
puts @board.render(@cursor.cursor_pos)
end
def move_c... | true |
f1fbf6cdfd8a063519a04e2a4a6ca988a76d7f3c | Ruby | tannerwelsh/code-training | /ruby/Learn to Program/ages.rb | UTF-8 | 447 | 3.734375 | 4 | [
"MIT"
] | permissive | hours = 24 * 365
puts 'There are ' + hours.to_s + ' hours in a year'
minutes = 60 * 24 * ((365 * 8) + (366 * 2))
alt_minutes = 60 * 24 * 365 * 10
puts "There are #{minutes} minutes in a decade. Or is it #{alt_minutes}? I'm not sure."
my_age_in_seconds = 24 * 365 * 24 * 60 * 60
puts "I am #{my_age_in_seconds} secon... | true |
e99d050c1cc3fafcca19ba341e2d682f91156eb5 | Ruby | ygorxds/RUBY-BASIC-COMMANDS | /case.rb | UTF-8 | 196 | 3.578125 | 4 | [] | no_license | puts ("Insira a idade:")
idade = gets.chomp.to_i
case idade
when 0..2
puts("bebe")
when 3..12
puts ("Criança")
when 13..18
puts "adolescente"
else
puts "adulto"
end
| true |
4492fe19a766e6beb76512f17fc96505714c2c43 | Ruby | felipernb/project-euler | /euler_45.rb | UTF-8 | 354 | 3.546875 | 4 | [] | no_license | def is_triangle?(tn)
n = (-1 + Math.sqrt(1+8*tn))/2
n == n.to_i
end
def triangle(n)
n*(n+1)/2
end
def is_pentagonal?(n)
p = (Math.sqrt(1+24*n)+1)/6
p == p.to_i
end
def is_hexagonal?(hn)
n = (1+Math.sqrt(1+8*hn))/4
n == n.to_i
end
n = 286
i = triangle(n)
while not (is_pentagonal?(i) and is_hexagonal?(i)) do
... | true |
203f321101d92a03390b991376098ccecba029e8 | Ruby | kuroneko995/cosc480-hw2 | /part2.rb | UTF-8 | 1,393 | 3.71875 | 4 | [] | no_license | require 'date'
class Numeric
@@currencies = {'yen' => 0.0065, 'euro' => 1.15, 'rupee' => 0.016}
def method_missing(method_id, *args)
singular_currency = method_id.to_s.gsub( /s$/, '')
if @@currencies.has_key?(singular_currency)
self * @@currencies[singular_currency]
else
... | true |
5dc5f43d62843bd4f3293687640850fe307e358f | Ruby | fragkakis/advent_of_code | /2021/day8/part1.rb | UTF-8 | 315 | 3.5 | 4 | [
"MIT"
] | permissive | module Day8
class Part1
def solve(input)
output_signals = input.split("\n").map{|line| line.split(" | ")[1].split(" ")}.flatten
output_signals.select{|signal| digit_of_interest?(signal)}.size
end
def digit_of_interest?(signal)
[2, 3, 4, 7].include?(signal.length)
end
end
end
| true |
2f1184714d93bd3ae8ef6cb61218156452b6fb57 | Ruby | progpyftk/learn_to_code_with_ruby_udemy | /Section 9/challenge_2_each_index.rb | UTF-8 | 303 | 3.671875 | 4 | [] | no_license | # print the product of element x its index, only if index pos is greater than the element
fives = [-1, 1, 2, 3, 5, 7, 3, 4, 8, 9]
fives.each_with_index do |each, index|
if index > each
puts "Element: #{each} Index: #{index}"
puts "Element x Index = #{each * index}"
end
end
| true |
522a6e0f2ac6b9f49808ae00dec07c9f69745f61 | Ruby | peterckim/basketball-statistics-app | /lib/tasks/get_game_data.rake | UTF-8 | 2,496 | 2.578125 | 3 | [
"MIT"
] | permissive | task :get_game_data do
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open(url))
gameDate = page.css('.scorebox').css('.scorebox_meta > div')[0].text
parseGameDate = gameDate.split(", ")
actualGameDate = "#{parseGameDate[1]}, #{parseGameDate[2]}"
player_game_hash = {
... | true |
8b3c788c4665d6d677b92d226b8d8695397ab00f | Ruby | customink/ft2-ruby | /examples/test_ft2.rb | UTF-8 | 655 | 2.796875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'ft2'
puts FT2::version
puts FT2::VERSION
face = FT2::Face.new 'fonts/yudit.ttf'
puts "glyphs: #{face.glyphs}",
"charmaps: #{face.num_charmaps}",
"horiz: #{face.horizontal?}",
"vert: #{face.vertical?}"
# cycle through default charmap
puts 'listing character codes ... | true |
8618b8c71071bad0e7e1dad10a16bf878e633e65 | Ruby | siphomsiza/platform45-mars-rover-assessment | /app/helpers/rover_platos_helper.rb | UTF-8 | 431 | 2.578125 | 3 | [] | no_license | module RoverPlatosHelper
def rover_plato_position(x, y)
if @rover_plato.position[[x, y]]
rover_image
else
"fa fa-times fa-3x"
end
end
def rover_image
image_rules = {'E' => "fa fa-arrow-right fa-3x",
'N' => "fa fa-arrow-up fa-3x",
'W' => "fa fa-arr... | true |
64feb79fdb47b5470570f8884ac0fed48ddca65b | Ruby | rudyoyen/cStore | /spec/scenario_spec.rb | UTF-8 | 667 | 2.671875 | 3 | [] | no_license | require 'spec_helper'
require 'config'
describe 'Scenario' do
before {
@scenario = Scenario.new
@count_symbol = Config::ITEM_COUNT_SYMBOL
}
# additional tests related to the scenario run inside store, orders, and promo classes
describe '#run' do
it 'returns an output as a Hash' do
order = @scenario... | true |
e6b51b6d5ae4d0c64e121237853afb31cbae3440 | Ruby | MarcinCebula/github-services | /services/crisply_api.rb | UTF-8 | 4,796 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'rest_client'
require 'nokogiri'
class CrisplyApi
def self.post_activity options
##Don't like something about this. Think about it later
resource = CrisplyApi.new(options)
resource.override_defaults_with options
project_id = resource.get_project_id_by_name options[:p... | true |
2ec0975e1d6ee0751fea2217c7c71a3899e83ee4 | Ruby | LinglingChen/aa_projects | /chess_project/game.rb | UTF-8 | 1,244 | 3.46875 | 3 | [] | no_license | require_relative 'board'
require_relative 'human_player'
require_relative 'computer_player'
class Game
attr_reader :board,:players,:display,:current_player
def initialize
@board=Board.new
@display=Display.new(@board)
@players={
:white => HumanPlayer.new(:white,@display),
... | true |
53bc8ee18d8ba058d09bb667df20a939d4837f2f | Ruby | Su0414/sinatra-nested-forms-v-000 | /app/models/pirate.rb | UTF-8 | 353 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pirate
attr_accessor :name, :weight, :height
@@pirate = []
def initialize(name, weight, height)
@name = name
@weight = weight
@height = height
save
end
def self.ships
@ships
end
def save
@@pirate << self
@@pirate
end
def self.all
@@pirate
end
def self.cle... | true |
4fe698999d42bd4f69f7021add15400b31df06ca | Ruby | danbriechle/calculator | /app/models/calc.rb | UTF-8 | 735 | 3.328125 | 3 | [] | no_license | class Calc
def self.calculate(math_string)
result = 0
# multiply
math_string.scan(/(\d*)([*])(\d*)/).each do |array|
result += array[0].to_f * array[2].to_f
math_string.sub!(array.join,"")
end
#divide
math_string.scan(/(\d*)([\/])(\d*)/).each do |array|
result += array[0].to_... | true |
3312e6c924513c145a929f5424f41b8371eaafd4 | Ruby | EthWorks/ethereum.rb | /lib/ethereum/transaction.rb | UTF-8 | 994 | 2.84375 | 3 | [
"MIT",
"LicenseRef-scancode-free-unknown"
] | permissive | module Ethereum
class Transaction
DEFAULT_TIMEOUT = 300.seconds
DEFAULT_STEP = 5.seconds
attr_accessor :id, :mined, :connection, :input, :input_parameters
def initialize(id, connection, data, input_parameters = [])
@mined = false
@connection = connection
@id = id
@input = d... | true |
acdffa4b3dc5108930586646cf2faca2986be633 | Ruby | zhangsu/seal | /demo/reverb.rb | UTF-8 | 1,052 | 2.828125 | 3 | [
"WTFPL"
] | permissive | require 'seal'
include Seal
Seal.startup
EFFECT = ARGV[0] || 'FOREST'
def print_constants(mod, level = 0)
mod.constants.each do |const_key|
const_val = mod.const_get(const_key)
puts ' ' * level + const_key.to_s
print_constants(const_val, level + 4) if const_val.is_a? Module
end
end
puts 'Available ... | true |
fce0e319406ffda01c49a508ab96e89e6235034b | Ruby | henry-doan/sti-scaffolding-intro | /app/models/animal.rb | UTF-8 | 544 | 2.71875 | 3 | [] | no_license | class Animal < ActiveRecord::Base
# BASE CLASS
belongs_to :zoo
# Tell rails about STI column since we didn't use type
self.inheritance_column = :race
validates_presence_of :name
def self.races
%w(Lion Bear Elephant Ape Cat)
end
# Scopes
def self.lions
where(race: 'Lion')
end
def self.bears
where(rac... | true |
2e34691695e3d110772855b9f5a18472aa476fc6 | Ruby | kieran-lockyer/challenges | /ruby/banking_app.rb | UTF-8 | 3,930 | 3.5625 | 4 | [] | no_license | begin
users = eval(File.open("balance.txt", 'a+') { |file| file.readline})
rescue EOFError => e
users = Hash.new
end
def authenticate(users)
attempts = 3
while attempts > 0
puts "#{attempts} attempts remaining"
print "Please enter your username: "
username = gets.chomp
p... | true |
0ace4fdae304eb8f968cfe19e3d0d07e52fa2cec | Ruby | hfitton/rubyexamples | /calc.rb | UTF-8 | 579 | 3.984375 | 4 | [] | no_license |
puts 'Hi, what\'s your name?'
name = gets.chomp
puts 'Your first name is '+ name + '? What\'s your surname?'
surname = gets.chomp
puts 'So your name is ' + name + ' '+ surname + '. Got any middle names?'
middle = gets.chomp
puts 'Wow! ' + middle + ' ' +'is fabulous! Hello there, ' + name + ' ' + middle + ' ' + sur... | true |
2511323db66a61d5b4348ca5ea807a27d25516bc | Ruby | mocklerlab/genomics | /lib/genomics/io/blast/e_value.rb | UTF-8 | 1,253 | 3.171875 | 3 | [] | no_license | module Genomics
module IO
module BLAST
# This class represets an E-value, which formats itself properly for printing and limits the floating point effects of extremely
# small values. It effectively sub classes a Numeric by defering all numerical computation to the float class.
class EValue
... | true |
dcf4173bf4dca8ff4b19235a7ff8766632a0be4f | Ruby | scootcho/ctci_exercises | /3.4_tower_of_hanoi.rb | UTF-8 | 4,726 | 3.921875 | 4 | [] | no_license | # ### Problem:
# In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:
# (1... | true |
4fdc012a070571c09b55c52fdfad6367f8f98fd4 | Ruby | urbanquakers/pantograph | /Dangerfile | UTF-8 | 1,092 | 2.625 | 3 | [
"MIT"
] | permissive | # We generally try to avoid big PRs
warn("Big PR") if git.lines_of_code > 500
# Show a warning for PRs that are Work In Progress
if (github.pr_body + github.pr_title).include?("WIP")
warn("Pull Request is Work in Progress")
end
# Contributors should always provide a changelog when submitting a PR
if github.pr_body.... | true |
1967ba2d446705e775d9db3b695c6c80312dd5f3 | Ruby | juliocesar/shining | /bin/shine | UTF-8 | 2,310 | 2.859375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'shining'
require 'stringex'
include Shining::FileMethods
ACTIONS = {
:new_on! => ['build'],
:new_slide! => ['slide'],
:help_and_exit! => ['help', '-h', '--help'],
:deploy => ['deploy'],
:remove ... | true |
563d241b3b05bff55f486bf8f483f66019158fae | Ruby | wInevitable/Chess | /chess.rb | UTF-8 | 2,592 | 3.515625 | 4 | [] | no_license | #encoding: utf-8
require 'pry'
require 'yaml'
require_relative 'pieces/piece'
require_relative 'pieces/stepping_piece'
require_relative 'pieces/sliding_piece'
require_relative 'pieces/pawn'
require_relative 'pieces/bishop'
require_relative 'pieces/king'
require_relative 'pieces/queen'
require_relative 'pieces/rook'
r... | true |
c73fef57f239a408be04df491090da5b06088c8c | Ruby | quotha/Huffwork | /lib/auction.rb | UTF-8 | 803 | 3.171875 | 3 | [] | no_license | require 'json'
class Auction
attr_accessor :item
attr_accessor :reserve
attr_accessor :started
attr_accessor :called
attr_accessor :bid
def initialize(args)
@item = args[:item]
@reserve = args[:reserve]
@started = args[:started] || false
@called = args[:called] || false
... | true |
832b62366e4d6a879a04cd80b0f0de719df96c1a | Ruby | synergychen/leetcode-ruby | /closest_binary_search_tree_value.rb | UTF-8 | 460 | 3.5625 | 4 | [] | no_license | # BST: left_value < root_value < right_value
class TreeNode
attr_accessor :val, :left, :right
def initialize(val)
@val = val
@left, @right = nil, nil
end
end
def closest_value(root, target)
return nil unless root
root_val = root.val
sub_root = root_val < target ? root.left : root.right
return... | true |
07369ec3cc0cb6af1de4dbf290329154e4d856b0 | Ruby | squiggle-lang/squiggle-lang.org | /_plugins/table_of_contents.rb | UTF-8 | 2,244 | 3.015625 | 3 | [
"MIT"
] | permissive | module TableOfContents
class Generator < Jekyll::Generator
# Chapter files are stored in /tutorial/chapter/NUM/index.md
SEC_REGEXP = %r{/tutorial/chapter/(\d+)}
def generate(site)
pairs = site
.pages
.select {|page| page.basename == "index" }
... | true |
c448ad77b77185d9f44dcf39d3965e0d24652e9a | Ruby | pahihu/syx | /plugins/x11/x11.rb | UTF-8 | 1,373 | 2.71875 | 3 | [
"MIT",
"FSFUL"
] | permissive |
class X11Extract
def X11Extract.parse(file)
lines = File.readlines(file)
funcs = {}
func = []
lines.each do |line|
line.strip!
case line
when /^extern[ \t]+.*[ \t]+([^ \t]+)[ \t]*\($/
fn = $1
fname = fn.gsub(/[*]+/,... | true |
098cfc3a77edbe3c4fa2a0e4bd73d185ec34c3c4 | Ruby | TAdP-Grupo3/Tp1-Metaprogramacion | /src/filters/negation_filter.rb | UTF-8 | 544 | 2.8125 | 3 | [] | no_license | require_relative '../../src/filters/abstract_filter'
require_relative '../../src/exceptions/no_arguments_given'
class NegationFilter<AbstractFilter
def initialize(filters)
raise NoArgumentsGivenError if filters.empty?
@filters = filters
end
private
def matching_methods(selectors)
matchs = @filter... | true |
08cd82bfe2f11b87957f2771b6e6cbee3f312c1f | Ruby | jrom/resque-insist | /spec/resque_insist_spec.rb | UTF-8 | 2,278 | 2.5625 | 3 | [] | no_license | require File.dirname(__FILE__) + '/spec_helper'
class Job
extend Resque::Plugins::Insist
@queue = :job
@insist = 2
def self.perform(success)
raise 'Not gonna work' unless success
end
end
describe Resque::Plugins::Insist do
describe "compliance of Resque Plugins guidelines" do
it "should be valid" ... | true |
89d3a21de7739899c0892939ad7eefad471cecc7 | Ruby | IngramCapa/makersbnb | /lib/requests.rb | UTF-8 | 3,654 | 3.25 | 3 | [] | no_license | require 'pg'
require 'date'
class Requests
CONNECTION = PG.connect(dbname: 'makersbnb')
def initialize(user_id)
@user_id = user_id
end
def user
@user_id
end
def display_requests
all_bookings = CONNECTION.exec("SELECT * FROM bookings")
all_bookings.map { |booking|
"#{return_property... | true |
751cd8fcfe8e5a6f7a472a6f48d6b064a64b9462 | Ruby | HirokiTachiyama/armyknife_old | /src/pomodoro/pomodoro.rb | UTF-8 | 3,944 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | # coding: utf-8
require 'tk'
#require 'C:\Ruby26-x64\lib\ruby\gems\2.6.0\gems\tk-0.2.0\lib\tk'
# https://illyasviel.wiki.fc2.com/wiki/Ruby%E3%81%A7%E3%83%A9%E3%83%BC%E3%83%A1%E3%83%B3%E3%82%BF%E3%82%A4%E3%83%9E%E3%83%BC
Tk.root.title("POMODORO Timer")
Tk.root.width(800) # window幅、効いてない
Tk.root.height(1000) # windows高さ... | true |
4b9e81ddf689e195a2274919d56b1fa33060a354 | Ruby | Edderic/pgit | /lib/pgit/helpers/query_methods.rb | UTF-8 | 1,647 | 2.5625 | 3 | [
"MIT"
] | permissive | module PGit
module Helpers
module QueryMethods
def set_attr(attribute)
unless instance_variable_get("@#{attribute}")
instance_variable_set("@#{attribute}", @query_hash[attribute.to_s] || yield)
end
end
def not_given(attribute)
"no_#{attribute}_given".to_sym
... | true |
b0f8c64a33196e90c0b8cc02922cd98e3272df6b | Ruby | Somniloquist/building_blocks | /spec/caesar_spec.rb | UTF-8 | 686 | 2.8125 | 3 | [] | no_license | require "./lib/caesar.rb"
describe Caesar do
include Caesar
describe "#caesar_cipher" do
it "shifts a single word" do
expect(caesar_cipher("Hello", 1)).to eql("Ifmmp")
end
it "shifts multiple words" do
expect(caesar_cipher("Hello There", 1)).to eql("Ifmmp Uifsf")
end
it "shifts wi... | true |
08acf69eb79fca8da65d8c5652f8a5c9f60fe610 | Ruby | ndelforno/1---Reinforcement-Exercises-Data-Types-Variables-Conditionals | /exercise2.rb | UTF-8 | 1,369 | 3.640625 | 4 | [] | no_license | documentary = "bowling for colombine"
drama = "The Godfather"
comedy = "Hangover"
dramedy = "Titanic"
puts "how much do you like documentaries from 1 to 5 ?"
user_answer1 = gets.chomp.to_i
puts "how much do you like dramas from 1 to 5 ?"
user_answer2 = gets.chomp.to_i
puts "how much do you like comedies from 1 to 5 ?"... | true |
16733d310a7aba9433d866a5a6cd03d37b588016 | Ruby | byrage/algorithm | /src/main/ruby/q10869.rb | UTF-8 | 103 | 3.203125 | 3 | [] | no_license | class Q10869
x, y = gets.split.map(&:to_i)
puts x+y
puts x-y
puts x*y
puts x/y
puts x%y
end | true |
dc680d6d8b1a69cab46c66a7703adb0a8bdc8cf0 | Ruby | pgharts/trusty-cms | /app/models/status.rb | UTF-8 | 818 | 2.96875 | 3 | [
"MIT"
] | permissive | class Status
attr_accessor :id, :name
def initialize(options = {})
options = options.symbolize_keys
@id = options[:id]
@name = options[:name]
end
def symbol
@name.to_s.downcase.intern
end
def self.[](value)
@@statuses.find { |status| status.symbol == value.to_s.downcase.intern }
end... | true |
586835ffe5b08943c48d4f458dbc1c41df983a3e | Ruby | prashanth-sams/page-object-pattern | /GoogleDriver.rb | UTF-8 | 2,298 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | require 'rspec'
require 'selenium-webdriver'
include RSpec::Expectations
class GoogleDriver
@driver = nil
def initialize (driver)
@driver = driver
@driver.manage.timeouts.implicit_wait = 10
end
def visit
@driver.navigate.to('https://www.google.co.in/')
@driver.manage.timeouts.page_load = 10
... | true |
e2baa592ab384b384226954939add88aeaa49ae4 | Ruby | matpalm/audioscrobbler-experiments | /path/visited_graph_writer.rb | UTF-8 | 562 | 2.765625 | 3 | [] | no_license | require 'dot_writer'
class VisitedGraphWriter < DotWriter
def initialize(filename)
@dot_file = File.open(filename,'w')
@dot_file.write preamble
@flush_freq = 0
end
def flush_if_required
@flush_freq +=1
if @flush_freq > 20
@dot_file.flush
@flush_freq = 0
end
end
def new... | true |
69d0494abae84f50c2cf1552b69b8f2c866d7d86 | Ruby | Estebandelaciudad/jour_7_ruby | /exo_02.rb | UTF-8 | 235 | 3.421875 | 3 | [] | no_license | puts "Bonjour, Monde ! "
puts "Et avec une voix sexy, ça donne : Bonjour, monde !"
# La différence principale réside dans le fait que puts revient a la ligne après l'éxécution de sa commande et print ne revient pas à la ligne
| true |
838b5dc453f5a08c12088a6e0a0e9d73ccad320b | Ruby | Katee/certificates | /lib/cache_strategy.rb | UTF-8 | 678 | 2.796875 | 3 | [
"MIT"
] | permissive | # encoding:UTF-8
require 'fileutils'
# Decides which cache to use based on a given path
module CacheStrategy
def self.build_from(path = nil)
if path
PDFCache.new(path)
else
NoCache.new
end
end
# Caches PDFs into a cache folder
class PDFCache
def initialize(cache_path)
@path =... | true |
c41319d281e1090603f716ffd36914c0cebfa877 | Ruby | saifulAbu/ProgrammingRuby | /9/break-redo-next.rb | UTF-8 | 508 | 3.296875 | 3 | [] | no_license | # break - exits current block, runs next statement after current block
# redo - begins execution without reevaluating loop condition
# next - starts a new iteration of loop
while line = gets
next if line =~ /~\s#/
break if line =~ /^END/
redo if line.gsub!(/`(,*?)`/) {eval ($1)}
#process line
end
i = 0
loop do
... | true |
9f950cdeb5f7d7420af16f47d2a9e0593e193837 | Ruby | PattyGeorgi/Torti | /app/controllers/pie_controller.rb | UTF-8 | 1,407 | 2.8125 | 3 | [] | no_license | require 'chunky_png'
class PieController < ApplicationController
def drawLine(x,y,x2,y2,image)
w = x2 - x
h = y2 - y
dx1 = 0
dy1 = 0
dx2 = 0
dy2 = 0
if (w<0)
dx1 = -1
elsif (w>0)
dx1 = 1
end
if (h<0)
dy1 = -1
elsif (h>0)
dy1 = 1
end
if (w<... | true |
f525d113b29b7da6eb0a7e2a40d16e049dfe81fc | Ruby | aknighttran/lunch_lady | /lunch_lady.rb | UTF-8 | 1,034 | 3.75 | 4 | [] | no_license |
require "pry"
$VERBOSE = nil
@@main = [
{ dish: "Meatloaf", price: 5.00 },
{ dish: "Mystery Meat", price: 3.00 },
{ dish: "Slop", price: 1.00 }
]
@@side = [
{ dish: "Carrots", price: 1.75 },
{ dish: "Mystery Yogurt", price: 1.00 },
{ dish: "Beef Jerkey", price: 0.50 }
]
@@final = []
class Meal
d... | true |
3ee6461e9c9b23a7cde3e9285057c8e04af68f0f | Ruby | Micaonthego/cartoon-collections-nyc-web-career-010719 | /cartoon_collections.rb | UTF-8 | 651 | 3.390625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(dwarves)
dwarves.each_with_index do |dwarf, index|
puts "#{index + 1}. #{dwarf}"
end
end
def summon_captain_planet(planeteer_calls)# code an argument here
planeteer_calls.map { |call| call.capitalize + '!'}# Your code here
end
def long_planeteer_calls(planeteer_calls)# code an argume... | true |
23e69a3e32547560eb533b431faf157e703af4fa | Ruby | kawausokun/qiita-sample | /dsa/elgamal.rb | UTF-8 | 2,405 | 3.0625 | 3 | [] | no_license | require './base.rb'
module MyExample
class ElgamalEncryptionEngine
attr_accessor :debug_enable
attr_reader :gamma,:n,:ft,:ftinv
def initialize(gamma,n,ft,ftinv,debug_enable=true)
raise ArumentError.new("gamma**n should be equal to epsilon") if gamma**n!=gamma.class.epsilon
@gamma,@n,@debug_ena... | true |
8b1beed50a3c9b7759fbf4d346c715e5e2f63b1d | Ruby | TrevorAbram/Exercism_exercises | /ruby/gigasecond/gigasecond.rb | UTF-8 | 366 | 3.046875 | 3 | [] | no_license | class Gigasecond
# Using tests, we can see that the "time" argument needs to accept the info from tests.
# We can then create a variable called new_time that equals our time argument plus
# the gigaseconds formula (10**9 or 10^9). Then we print the solution and run tests accuracy.
def self.from(time)
new_... | true |
e673b6a241074b0d7068a8fcb38df4463a1574c9 | Ruby | teoucsb82/pokemongodb | /lib/pokemongodb/pokemon/electabuzz.rb | UTF-8 | 1,319 | 2.75 | 3 | [] | no_license | class Pokemongodb
class Pokemon
class Electabuzz < Pokemon
def self.id
125
end
def self.base_attack
198
end
def self.base_defense
160
end
def self.base_stamina
130
end
def self.buddy_candy_distance
3
end
... | true |
fa42d3c5d695fcc75fe524a7474984faf4fe8495 | Ruby | camisoul/atcoder | /ABC/060/C/ruby/test.rb | UTF-8 | 224 | 2.640625 | 3 | [] | no_license | #!/usr/bin/env ruby
# frozen_string_literal: true
n, t = gets.split.map(&:to_i)
ts = gets.split.map(&:to_i)
if n == 1
p t
else
p n * t - ts.each_cons(2).map { |i| i[1] - i[0] }.map { |i| [t - i, 0].max }.inject(:+)
end
| true |
b92878a6888683d7cc1bf79fea25b58b01a14b32 | Ruby | uhlarmd/NBody | /Challenge2.rb | UTF-8 | 1,637 | 3.96875 | 4 | [] | no_license | puts "We're trying to write a farily tale, but we could use a litle bit of help. Give us a hand by filling out a few words:"
puts " "
puts "Type in a girl's name and press enter"
girl_name = gets.chomp
puts "Type in a living thing and press enter"
living_thing = gets.chomp
puts "Type in an adjective (big, cold, smelly)... | true |
e42d0235ec1fb36e958ade6dc803a13ca43c8b63 | Ruby | krohrbaugh/dotfiles | /ruby/irb.d/01-usage.rb | UTF-8 | 550 | 2.703125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# -*- ruby -*-
# Original author: Jim Weirich - http://github.com/jimweirich/irb-setup
unless Object.const_defined?("HELP")
Object.const_set("HELP", [])
end
def usage(method_name=nil, comment=nil)
if method_name.nil?
width = HELP.collect { |pair| pair[0].size }.max
HELP.sort.each do |... | true |
ae906b9491ac10a95a9c112dbad5c9ef4e195d9c | Ruby | yokolet/tranquil-beach-ruby | /spec/graph_spec.rb | UTF-8 | 3,942 | 3.078125 | 3 | [] | no_license | require 'rspec'
Dir["./lib/graph/*.rb"].each {|file| require file }
describe 'Graph' do
context NumberOfIslands do
let(:obj) { NumberOfIslands.new }
it 'should count islands, 1' do
grid = [["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]
expected = 1
... | true |
18bf26f835bbaa19e859da460c9a8f11b243b9cd | Ruby | itiswhatitisio/rb101 | /small_problems/easy_3/counting.rb | UTF-8 | 261 | 3.640625 | 4 | [] | no_license | def prompt(message)
puts message
end
def count_words(string)
string.delete(' ').size
end
# Main program
prompt('Please write word or multiple words')
user_words = gets.chomp
prompt("There are #{count_words(user_words)} characters in \"#{user_words}\".") | true |
f1007931ee622696afc21249dd0d3f6fd6531e5f | Ruby | Justo84/ruby_blackjack | /card.rb | UTF-8 | 223 | 3.234375 | 3 | [] | no_license | class Card
attr_reader :value, :rank
def initialize(value, rank)
@value = value
@rank = rank
end
def to_string
"#{rank} #{value}"
end
def face_card?
['J', 'K', 'Q'].include?(value)
end
end
| true |
e999c372b99d09cb509abeb6ef756ed852f64c86 | Ruby | corinneling/apprentice-notes | /Ruby Exercises/whys-poignant-guide/hannah.rb | UTF-8 | 197 | 3.09375 | 3 | [] | no_license | final-verb = 'rescued'
['sedated', 'sprinkled', 'electrocuted'].each do |poop|
puts "Dr. Cham " + poop + " his niece Hannah."
end
puts "Finally, Dr. Cham " + final-verb + " his niece Hannah."
| true |
ad25d0239c4871e7ff4ef18cf18a8d2ac95d51a6 | Ruby | thuyihan1206/contact-management | /spec/requests/api_helper.rb | UTF-8 | 694 | 2.671875 | 3 | [] | no_license | module ApiHelper
# parsed body (expecting json format)
def parsed_body
JSON.parse(response.body)
end
# automates the passing of payload bodies as json
['post', 'put', 'patch', 'get', 'head', 'delete'].each do |http_method_name|
define_method("j#{http_method_name}") do |path, params = {}, headers = {}... | true |
8438b9e418f67370c4496c20d880cc1fc616f2f7 | Ruby | katrpilar/ttt-with-ai-project-v-000 | /lib/game.rb | UTF-8 | 2,421 | 3.765625 | 4 | [] | no_license | class Game
attr_accessor :board, :player_1, :player_2
WIN_COMBINATIONS = [ [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8], [0,4,8], [6,4,2] ]
def initialize (player_1=Players::Human.new("X"),player_2=Players::Human.new("O"),board=Board.new)
@player_1 = player_1
@player_2 = player_2
... | true |
9cc3766d527877a9f2a847cf66b95c832daf2550 | Ruby | GuettnerBianca/bio2rdf-scripts | /toxkb/toxnet/archival2rdf.rb | UTF-8 | 10,585 | 2.78125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'rubygems'
require 'rdf'
require 'rdf/ntriples'
require 'nokogiri'
require 'digest/md5'
require 'cgi'
require 'ostruct'
require 'optparse'
require 'logger'
include RDF
class Archival
def initialize(args)
@arguments = args
@options = OpenStruct.new()
@log = Logger.new(STDOUT)... | true |
37793bb482ba48b8a22cb07d58f6567b7233513c | Ruby | DougMG/my_Playlist | /app/services/spotify_service.rb | UTF-8 | 775 | 2.796875 | 3 | [] | no_license | require 'base64'
require 'rest-client'
require 'json'
class SpotifyService
AUTHORIZE_URI = 'https://accounts.spotify.com/authorize'.freeze
TOKEN_URI = 'https://accounts.spotify.com/api/token'.freeze
def initialize(client_id, client_secret)
@client_id = client_id
@client_secret = client_secret
end
... | true |
bc89e78a53aa3d6437a1079579000b7edc8fddbe | Ruby | fsladkey/Freddit | /app/models/vote.rb | UTF-8 | 718 | 2.515625 | 3 | [] | no_license | # == Schema Information
#
# Table name: votes
#
# id :integer not null, primary key
# value :integer not null
# user_id :integer not null
# votable_id :integer
# votable_type :string
# created_at :datetime not null
# updated_at :datetime not ... | true |
2e7b69ed177a75c9a804633614ff8908268318ba | Ruby | judo2000/RB101_Programming_Foundations | /lesson_4/loops_2/stop_counting.rb | UTF-8 | 212 | 3.890625 | 4 | [] | no_license | # The method below counts from 0 to 4. Modify
# the block so that it prints the current
# number and stops iterating when the current
# number equals 2.
5.times do |index|
puts index
break if index == 2
end | true |
29e26b7900d6375a49746d022b05b7e80d4eb667 | Ruby | oeyiowuawi/lekanmastermind | /bin/CLI/set_player.rb | UTF-8 | 743 | 3.390625 | 3 | [] | no_license | require 'lekanmastermind/player'
class SetPlayer
def initialize(message)
@message = message
end
def player_collection
loop do
puts @message.number_of_players
@number_of_players = gets.chomp
break if check_input(@number_of_players)
puts @message.error_input
end
generate_play... | true |
0f8aa6fc29f61010870968d9c2eba8a669a40748 | Ruby | aagooden/ultimate_tictactoe | /minitest_files/random_tests.rb | UTF-8 | 1,128 | 3.109375 | 3 | [] | no_license | require "minitest/autorun"
require "./classes/game.rb"
require "./classes/human.rb"
require "./classes/board.rb"
require "./classes/random.rb"
require "./classes/sequential.rb"
require "./classes/unbeatable.rb"
require "./classes/player.rb"
class Tictactoe_test < Minitest::Test
def test_random_level_1
board = Boar... | true |
5ca2655953f86535ec29562c7f02aa761ea7b60b | Ruby | tmtmtmtm/capitani-reggenti-wikipedia-scraper | /scraper.rb | UTF-8 | 1,562 | 2.828125 | 3 | [] | no_license | #!/bin/env ruby
# frozen_string_literal: true
require 'pry'
require 'scraped'
require 'scraperwiki'
require 'wikidata_ids_decorator'
require_relative 'lib/unspan_all_tables'
require 'open-uri/cached'
OpenURI::Cache.cache_path = '.cache'
class HoldersPage < Scraped::HTML
decorator WikidataIdsDecorator::Links
dec... | true |
27ad84e098bdb83eb2c67cd1b424755c73089e42 | Ruby | kmcd/refactoring_ruby | /simple_queue/simple_queue.rb | UTF-8 | 275 | 2.71875 | 3 | [] | no_license | require 'forwardable'
class SimpleQueue
extend Forwardable
def initialize
@elements = []
end
def_delegator :@elements, :shift, :remove_front
def_delegator :@elements, :push, :add_rear
def_delegators :@elements, :clear, :first, :length
end
| true |
dfd99ae30f5902568fd716dd7dfaf3b1a50c63f2 | Ruby | AlekseyZmitrykevich/tic_tac_toe | /lib/player.rb | UTF-8 | 197 | 3.484375 | 3 | [] | no_license | class Player
attr_reader :name, :mark
def initialize(name,mark)
@name=name
@mark=mark
@winner=false
end
def winner!
@winner=true
end
def winner?
@winner
end
end | true |
3087d49555e64039258d3061ece9d83b25302c77 | Ruby | mugwump/rotten_tomatoes_api | /lib/rotten_tomatoes_api.rb | UTF-8 | 1,006 | 2.6875 | 3 | [] | no_license | require 'rotten_tomatoes_api/version'
require 'httparty'
require 'recursive_open_struct'
module RottenTomatoesApi
API_KEY = "sesenwn6zqegzseyhfw2bg49"
MOVIES_SEARCH ='http://api.rottentomatoes.com/api/public/v1.0/movies.json'
def self.version_string
"RottenTomatoesApi version #{RottenTomatoesApi::VERSIO... | true |
e12e22530e2dbed3b68f3533aa83cd7cafce398d | Ruby | david-ricketts/programming-univbasics-4-array-methods-lab-nyc-web-012720 | /lib/array_methods.rb | UTF-8 | 443 | 3.65625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_include(array, element)
array.include?(element)
end
def using_sort(array)
sorted_array = array.sort
sorted_array
end
def using_reverse(array)
reversed_array = array.reverse
return reversed_array
end
def using_first(array)
first_element = array.first
return first_element
end
def using_last(... | true |
401d556a851f432126dcd020e11aee0cfa712d31 | Ruby | encoreshao/china_regions | /lib/tasks/china_regions.rake | UTF-8 | 3,627 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
namespace :china_regions do
desc 'Download and import regions into tables'
task all: :environment do
Rake::Task['china_regions:download'].invoke
Rake::Task['china_regions:import'].invoke
end
desc 'Download regions from `Administrative-divisions-of-China`'
task download:... | true |
75d4df50e7320ebb3fd5464b69e252c964f905e0 | Ruby | henrygarciaospina/challengers-ruby | /hashes_more.rb | UTF-8 | 702 | 3.890625 | 4 | [] | no_license | system("clear")
hash = {"one" => "Uno", 2 => "dos", :three => "tres", true => "cuatro"}
puts "*" * 60
puts hash
puts
puts "*" * 60
puts hash["one"]
puts hash[2]
puts hash[:three]
puts hash[true]
puts
#Adicionar elementos al hash
puts "*" * 60
hash["five"] = "cinco"
hash["six"] = "seis"
hash[:seven] = "siete"
puts ha... | true |
ea9474bd44c2ff6a8a1a5c9cdd6076ac533a6047 | Ruby | Aeon/spree-dropdown-variants | /app/models/variant_decorator.rb | UTF-8 | 593 | 2.546875 | 3 | [] | no_license | Variant.class_eval do
def self.find_by_option_types_and_product(option_types, product)
join_clause = ''
and_clause = ''
option_types.each_with_index do |option_type, i|
join_clause << " INNER JOIN option_values_variants ovv#{i}
ON v.id = ovv#{i}.variant_id "
and_clause ... | true |
3d9305dee98c3a3ecb41494a64f78bddb994bbb6 | Ruby | botanicus/logging4hackers | /lib/logging/logger.rb | UTF-8 | 3,201 | 3.140625 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require_relative 'io'
require_relative 'formatters'
module Logging
# Main class. Instantiate it to start logging.
# In reality all this class does is to provide
# convenience proxy to {file:lib/logging/io.rb io objects}
# and {file:lib/logging/formatters.rb formatters}.
class Logger
# ... | true |
d3680922d0d40fc0462ef4fa29acccfbe20d4630 | Ruby | mneedham/neo4j-1 | /example/imdb/batch_insert.rb | UTF-8 | 1,799 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'movie'
# Remove old database if there is one
FileUtils.rm_rf Neo4j::Config[:storage_path] # this is the default location of the database
IMDB_FILE = 'data/test-actors.list'
movies = {}
current_actor = nil
actors = 0
no_films = 0
inserter = Neo4j::Batch::Inserter.new
File.open(IMDB_FIL... | true |
debfc728fce8fae11831299f3218802b23f0f4d2 | Ruby | elipinska/codeclan_wk2_day2_bus_lab | /specs/bus_stop_spec.rb | UTF-8 | 411 | 2.9375 | 3 | [] | no_license | require("minitest/autorun")
require_relative("../bus_stop")
require_relative("../person")
class BusStopTest < MiniTest::Test
def setup
@bus_stop = BusStop.new("Princes St")
@ewa = Person.new("Ewa", 27)
end
def test_bus_stop_has_name
assert_equal("Princes St", @bus_stop.name)
end
def test_add_t... | true |
c7272073bfb79b95c1f6c9896044407dc876e219 | Ruby | jhnegbrt/aA_Classwork | /w4d1/skeleton/lib/tic_tac_toe_node.rb | UTF-8 | 790 | 3.359375 | 3 | [] | no_license | require_relative 'tic_tac_toe'
class TicTacToeNode
attr_reader :board, :next_mover_mark
def initialize(board, next_mover_mark, prev_move_pos = nil)
@board = board
@next_mover_mark = next_mover_mark
@prev_mov_pos = prev_mov_pos
end
def losing_node?(evaluator)
end
def winning_node?(evaluator)... | true |
a5649580947e0c194ae809e66a18647abbecb69a | Ruby | domtriola/nim-game | /ruby/lib/game.rb | UTF-8 | 1,162 | 3.859375 | 4 | [] | no_license | require_relative 'board'
require_relative 'human_player'
require_relative 'computer_player'
class Game
attr_accessor :board, :player_one, :player_two,
:current_player, :last_move
def initialize(rows = [3, 4, 5])
@board = Board.new(rows)
@player_one = HumanPlayer.new
@player_two = Compu... | true |
d6237135602629ed0833ee3464cfdfb933d6a296 | Ruby | cha63506/googlecodejam2014 | /old/2012/round1a/q1/q1.rb | UTF-8 | 599 | 2.640625 | 3 | [] | no_license | require 'bundler'
Bundler.require(:default)
file = File.new('q1data.txt', 'r')
n = file.gets.to_i
n.times.each do |cas|
a, b = file.gets.split.map(&:to_i)
ps = file.gets.split.map(&:to_f)
expected = []
p = 1
(0..a).each do |i|
p*= ps[i-1] if i > 0
nb_right = b-a +2*(a-i)+1
nb_wrong = nb_right... | true |
54155620816518fa6ec8f4c0d1758258403f31eb | Ruby | tbonesteak/the_url_shortener | /app/models/url.rb | UTF-8 | 600 | 2.734375 | 3 | [] | no_license | class Url < ActiveRecord::Base
attr_accessible :long_url, :short_code
validates :long_url, presence: true, format: { with: URI::regexp}
before_create :short_code_generator
def short_code_generator
logger.info { "BEFORE SHORT CODE GENERATOR:"}
logger.info { self.short_code }
self.short_code ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.