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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
d017f8ced884c42413467fbc131a6d07a83326d9 | Ruby | conyekwelu/rb101 | /basics_review/basics_strings.rb | UTF-8 | 1,010 | 4.34375 | 4 | [] | no_license | CORE CONCEPTS
Create a String
empty_string = ""
empty_string = String.new
Quote Confusion
puts "It's now 12 o'clock."
puts %Q(It's now 12 o'clock.)
Ignoring Case
name = "Roger"
puts name.downcase == "RoGer".downcase
puts name.casecmp("RoGer") == 0 #regardless of case
puts name == "DAVE"
puts name.casecmp("DAVE") =... | true |
c2a761ce40cc317f68032ee9dfb28a8bd275de14 | Ruby | Cyfon7/Piedra-Papel-Tijera | /juego.rb | UTF-8 | 909 | 3.75 | 4 | [] | no_license | #Toma de jugada
user_temp = ARGV[0].chomp
cpu_play = rand(3)
if user_temp == "piedra"
user_play = 0
elsif user_temp == "papel"
user_play = 1
elsif user_temp == "tijera"
user_play = 2
else
user_play = 5 #Valor para finalizar programa
end
if (user_play >=0 && user_play <=2) #Validación de Entrada
#... | true |
5868f9a0c81bad2b215adb19b2f5015e2536e9ab | Ruby | asalves07/space-code-platform | /app/serializers/travel_route_serializer.rb | UTF-8 | 633 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
class TravelRouteSerializer
def serializable_hash
routes = []
planets.each do |origin|
planets.each do |destiny|
route = route_hash(origin, destiny)
routes << route if origin != destiny && route[:cost] < CalculateRoutes::INFINITE
end
end
ro... | true |
8c848052e28114f40b3f12b04efdfd299afef961 | Ruby | rallyb13/tOXic_tac_toe | /lib/space.rb | UTF-8 | 327 | 2.71875 | 3 | [] | no_license | class Space
@@spaces = []
attr_reader(:x_coordinate, :y_coordinate)
define_method(:initialize) do |attributes|
@x_coordinate = attributes.fetch(:x)
@y_coordinate = attributes.fetch(:y)
end
define_singleton_method(:all) do
@@spaces
end
define_method(:create) do
@@spaces.push(self)
en... | true |
5166ac79d2700045dd33bf46090b3fa4d8555351 | Ruby | watashi/AlgoSolution | /codeforces/ac/2/219/Dgen.rb | UTF-8 | 62 | 2.90625 | 3 | [] | no_license | n = 200000
puts n
1.upto(n - 1) do |i|
puts "#{i} #{n}"
end
| true |
79510df05c6d82b24dad28c33d12856befdbb107 | Ruby | destro1234/GOAT-CLI-Gem-Project | /GOAT_CLI/lib/GOAT_CLI/cli.rb | UTF-8 | 2,378 | 3.859375 | 4 | [
"MIT"
] | permissive | require 'nokogiri'
require 'pry'
class GOATCLI::CLI
@@team = {:pg => "", :sg => "", :sf => "", :pf => "", :c => ""}
def call
make_players
puts "The Dream Team was the greatest team of NBA superstars ever formed. Here you can compare players and create your own Dream Team starting 5.\n"
puts "\n"
... | true |
6e13654a32750494ddecc85fbe2e2632d9f89f0f | Ruby | mcarpenter/solaris-patch | /lib/solaris/exception.rb | UTF-8 | 1,029 | 2.640625 | 3 | [
"BSD-2-Clause"
] | permissive | module Solaris
class Patch
# Superclass for all throwable exceptions.
class Exception < ::Exception ; end
# Exception is raised when the terminal (non-obsolete) succesor
# to a patch has been withdrawn (is bad).
class BadSuccessor < Exception ; end
# Raised if the "obsoleted by" value for ... | true |
00d8cec3c755d887b51c54ba394800e69f4c2560 | Ruby | dshevtsov/whatsup_github | /lib/whatsup_github/row_collector.rb | UTF-8 | 2,026 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative 'row'
require_relative 'pulls'
require_relative 'config_reader'
module WhatsupGithub
# Creates Row objects for the future table
class RowCollector
attr_reader :repos, :since
def initialize(args = {})
@repos = config.repos
@since = args[:since]
... | true |
384190269dfdd387d2402a10378d8fc382021933 | Ruby | Sandthorn/sandthorn | /spec/default_attributes_spec.rb | UTF-8 | 1,776 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
# class DefaultAttributes
# include Sandthorn::AggregateRoot
# def initialize
# end
# end
describe "when the initialize-method changes" do
before do
class DefaultAttributes
include Sandthorn::AggregateRoot
def initialize
end
end
end
#Make sure the Defaul... | true |
959e8e122cf5d71f32ac17c1e62d681eaba7974f | Ruby | mattissf/Makk | /examples/draw/grid/item/movable_spec.rb | UTF-8 | 1,029 | 2.578125 | 3 | [] | no_license | require 'rubygems'
require 'rubygame'
require 'spec'
require 'app/draw/grid/item/movable'
require 'app/logic/grid.rb'
require 'examples/makk_helper'
describe Grid::Item::Movable do
include MakkHelper
def getMovable
grid = Grid.new(mockScreen(:width => 30, :height => 30))
Grid::Item::Movable.new(Grid:... | true |
c27d9113b520db5e96bb5ce4dbb7aba1e9d9876e | Ruby | bradgessler/jack | /vendor/gems/gems/dm-validations-0.10.1/lib/dm-validations/contextual_validators.rb | UTF-8 | 2,076 | 2.90625 | 3 | [
"MIT"
] | permissive | require "forwardable"
module DataMapper
module Validate
##
#
# @author Guy van den Berg
# @since 0.9
class ContextualValidators
extend Forwardable
#
# Delegators
#
def_delegators :@contexts, :empty?, :each
include Enumerable
attr_reader :contexts
... | true |
d842311a1eb13896bfbf43d3fb5e093580686e1b | Ruby | Cbo-11/Ruby-Basics-Project | /05_book_titles/book.rb | UTF-8 | 422 | 3.375 | 3 | [] | no_license | class Book
# write your code here
def title= (str)
word = str.split(' ')
newTitle = []
exceptions = ['a','an','and','or','the','in','of']
word.each_with_index do |word,index|
if !exceptions.include?(word) or index == 0
newTitle.push(word.capitalize)
else
newTitle.push(word... | true |
d80359eb8bd183d49d2600cf5efe1e1a6ebe7277 | Ruby | xuanchien/sudoku_sat_solver | /Program/sudoku.rb | UTF-8 | 631 | 3.40625 | 3 | [] | no_license | require_relative 'sudoku_solver'
if ARGV.length == 0
puts "Please specify input file"
exit
end
input_file = ARGV.first
#read problem from the input file
grid = []
text = File.open(input_file, "r").read
text.gsub!(/\r\n?/, "\n")
text.each_line do |line|
grid << line.split(/\s+/).map(&:to_i)
end
sudoku_solver ... | true |
94bcc6c780c400331ed1e95a2d43dd5125003db5 | Ruby | hvasanth/etsy-cucumber | /features/pages/SearchResultsPage.rb | UTF-8 | 513 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require "selenium-webdriver"
class SearchResultsPage
def initialize browser
@browser=browser
end
def verifySearchResultsPresent
begin
@browser.find_element(:xpath, "//div[@id='search-header']/h1[@class='summary' and contains(text(), 'results for')]")
rescue
raise "No search results foun... | true |
6e35a9426e237c7299199a67ee865e7203829452 | Ruby | jkurisu/omnibus-gitlab | /files/gitlab-cookbooks/gitlab/libraries/helpers/shell_out_helper.rb | UTF-8 | 484 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | require 'mixlib/shellout'
module ShellOutHelper
def do_shell_out(cmd, user = nil, cwd = nil)
o = Mixlib::ShellOut.new(cmd, user: user, cwd: cwd)
o.run_command
o
rescue Errno::EACCES
Chef::Log.info("Cannot execute #{cmd}.")
o
rescue Errno::ENOENT
Chef::Log.info("#{cmd} does not exist.")
... | true |
612af541b42d8c7035430a2832dad9c94848ae9c | Ruby | jpmaHub/read-books | /lib/use_cases/save_book.rb | UTF-8 | 250 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
class SaveBook
def initialize(book_gateway:)
@book_gateway = book_gateway
end
def execute(book)
return { successful: false, errors: :no_book_to_save } if book == {}
@book_gateway.save(book)
end
end
| true |
239e3e65560ee1738a8ce29ab3ad6f99da5679e1 | Ruby | aldaeron/csci568 | /project09/matto/user_search/create_genre_training_rollup_sample.rb | UTF-8 | 2,644 | 2.78125 | 3 | [] | no_license | require 'sqlite3'
require_relative '../item_type.rb'
users_db = SQLite3::Database.open('KDD-genre-sample.db3')
items_db = SQLite3::Database.open('KDD-items.db3')
input_handle = File.open("sample_train.txt","r")
output_handle = File.open("sample_genre_rollup.txt","w")
num_genres = items_db.execute("SELECT * ... | true |
1b25c80e114ba06edbb642bcfc154708ead7c453 | Ruby | laxmi1/jobvox_sst | /suite_status.rb | UTF-8 | 3,339 | 2.515625 | 3 | [] | no_license | gem "test-unit"
require "test/unit"
require 'rubygems'
require 'time'
#require "active_support"
class Suite_Result < Test::Unit::TestCase
def test_read_log
i=0
@bugs = 0
@passed = 0
@failed = 0
@script_name = nil
@status = nil
@result = ""
@bugs_smok... | true |
f14156eaccbdd7dc90c8d9bc9d2d586624517c3f | Ruby | ajesler/octo-captioned-image | /test/test_caption_options_parser.rb | UTF-8 | 1,354 | 2.75 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require "octo-captioned-image/caption_options_parser"
class TestCaptionOptionsParser < Minitest::Test
IMAGE_PATH = "https://images/my_image.png"
def parse_options(markup)
Octopress::Tags::CaptionedImageTag::CaptionOptionsParser.new(markup)
end
def test_errors_if_no_source
begin
... | true |
510a09ff10c604a65a5b8cd3077c9fa3765bce52 | Ruby | nakhaury/SizeAdvisorFinal | /db/seeds.rb | UTF-8 | 988 | 2.84375 | 3 | [] | no_license | User.destroy_all
["Nitesh", "Jeff"].each do |name|
u = User.new
u.first_name = name
u.password = "password"
u.save
end
puts "There are now #{User.count} users in the database."
# Seeds based on my sizing
jcrew.destroy_all
jcrew_size = [ { :user_id => 1,
:size => 'small',
... | true |
9009f0df915c06bfcd3b580bfbb71985c6dbc736 | Ruby | dark-arc/AdventOfCode | /day09/mapCodeParser.rb | UTF-8 | 613 | 3.015625 | 3 | [] | no_license | require 'strscan'
require_relative 'map'
class MapCodeParser
attr_reader :map
def initialize(code, map)
@map = map
@buffer = StringScanner.new code
end
def run
until @buffer.eos?
skip_whitespace
parse_line
@buffer.skip_until /$/
end
end
def parse_line
@buffer.scan /... | true |
29b39521c23ae79dce9fc5d89d20b74a07fb769b | Ruby | theshannonclark/learn_ruby | /07_hello_friend/friend.rb | UTF-8 | 138 | 3.125 | 3 | [] | no_license | class Friend
def greeting(name = nil)
message = "Hello!"
if name
message = "Hello, #{name}!"
end
message
end
end | true |
208143af9aa35718f4809b161925ad5265bb6f1b | Ruby | jacobey3/fa15-hw1 | /foobar.rb | UTF-8 | 122 | 3.0625 | 3 | [] | no_license | class Foobar
def self.baz(arr)
arr.uniq.map{|s| s.to_i}.select{|n| n%2==0 && n<10}.map{|s| s+2}.inject(:+)
end
end
| true |
fc50c3ae9050dbbffcf3bafc4a8248fe0437e2f7 | Ruby | Doode1524/legends_CLI | /lib/config/list.rb | UTF-8 | 1,205 | 2.890625 | 3 | [
"MIT"
] | permissive | # def list_champions
# col1 = 0
# col2 = 38
# col3 = 76
# col4 = 114
# standardize
# while col1 < 38
# puts " #{col1+1}.#{Champions.all[col1].name} \t\t #{col2+1}.#{Champions.all[col2].name} \t\t #{col3+1}.#{Champions.all[col3].name} \t\t #{col4+1}.#{Champions.all[col4].name}"
# ... | true |
43524260d8e239c6c96261ef07c9573139860bc3 | Ruby | waterlink/confident.ruby | /lib/confident/null_object.rb | UTF-8 | 281 | 2.59375 | 3 | [
"MIT"
] | permissive | module Confident
class NullObject
def method_missing(*)
self
end
end
module AutoNullObject
class << self
def wrap(value)
return value unless NilClass === value
NullObject.new
end
alias_method :[], :wrap
end
end
end
| true |
5c8fc5040868a1867329e0ce368a3f8ae1a71a55 | Ruby | RubyCamp/rc2018sp_g1 | /old/player_2.rb | UTF-8 | 2,466 | 2.953125 | 3 | [] | no_license | # require_relative 'level'
require 'dxruby'
# buki = Level.buki
class Player
attr_accessor :x
attr_accessor :push_button # push 1
def initialize(haba)
# @board = board
@image_player = Image.load('./gamescene/a.png')
@image_ball = Image.load('./gamescene/b.png')
... | true |
c29580bc89f583b411dc909d186d0d3afe1ff473 | Ruby | songgz/tumugi | /lib/tumugi/plugin/file_system_target.rb | UTF-8 | 533 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | require 'tumugi/target'
require 'tumugi/file_system'
require 'tumugi/error'
module Tumugi
module Plugin
class FileSystemTarget < Target
attr_reader :path
def initialize(path)
@path = path
end
def fs
raise NotImplementedError, "You must implement #{self.class}##{__method_... | true |
94f5f4738f66919045c04eac83b59463c64323d0 | Ruby | sadiqmmm/geared_pagination | /lib/geared_pagination/portion.rb | UTF-8 | 537 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'geared_pagination/ratios'
module GearedPagination
class Portion
attr_reader :page_number, :ratios
def initialize(page_number: 1, per_page: GearedPagination::Ratios.new)
@page_number, @ratios = page_number, per_page
end
def from(scope)
scope.limit(limit).offset(offset)
end
... | true |
9cbcdd8f3b2df196c6318541185138ea3530c7f7 | Ruby | satoyos/Shuffle100 | /app/models/poem.rb | UTF-8 | 692 | 2.765625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Poem
DEFAULT_LABEL_PATTERN = 'poem%03d'
DEFAULT_STR_OUT_PATTERN = '%d. %s %s %s %s %s'
PROPERTIES = [:number, :poet, :liner, :in_hiragana, :in_modern_kana, :kimari_ji, :living_years]
PROPERTIES.each do |prop|
attr_accessor prop
end
def initialize(attributes = {})
attributes.each do |key, va... | true |
4217b69ec3c14f2caba77e14d5bf839b355b971d | Ruby | Swati24/algorithms | /LinkedList/multiplication.rb | UTF-8 | 2,992 | 3.46875 | 3 | [] | no_license | class Node
attr_accessor :data, :next
def initialize(data = nil)
@data = data
@next = nil
end
end
class LinkedList
attr_accessor :head
def initialize
@head = nil
end
def self.length(node = head)
if node.nil?
return 0
end
1 + length(node.next)
end
end
class Multipl... | true |
299bdcec5ffe854262d423d676a2e87b070ae0ef | Ruby | JLPhillips/linked_list_cohort3 | /lib/linked_list.rb | UTF-8 | 3,768 | 3.46875 | 3 | [] | no_license | require "linked_list_item"
class LinkedList
def initialize(*args)
@first_item = nil
@count = 0
for arg in args
self.add_item(arg)
end
end
def add_item(payload)
item = @first_item
if item
while item.next_list_item do
item = item.next_list_item
end
item.nex... | true |
fe434921c6a568f20de7e5d49c181ff374dd27b6 | Ruby | klauern/puzzlenode_answers | /1-international_trade/lib/xml_parser.rb | UTF-8 | 2,759 | 3.28125 | 3 | [] | no_license | require 'nokogiri'
require 'bigdecimal'
require_relative 'currency_model'
class XmlRatesParser
attr_accessor :doc, :rates
def initialize(filepath)
@doc = create_doc(filepath)
create_rates_hash
end
def create_rates_hash
xml = get_rates_from_xml(@doc)
@rates = map_rates(xml)
end
def create... | true |
3454d4e527a57a35c9d0b3ddc95f37af6cd6c8ce | Ruby | fairplace/rubyfiles1 | /skillcrush-104/ruby/olisa.rb | UTF-8 | 42 | 2.90625 | 3 | [] | no_license | puts "enter name"
name=gets
puts "#{name}" | true |
995808248828f5100c219de297a699c9841b7600 | Ruby | Glovo/kennel | /lib/kennel/unmuted_alerts.rb | UTF-8 | 2,949 | 2.59375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "kennel"
# Show Alerts that are not muted and their alerting scopes
module Kennel
class UnmutedAlerts
COLORS = {
"Alert" => :red,
"Warn" => :yellow,
"No Data" => :cyan
}.freeze
class << self
def print(api, tag)
monitors = filtered_mon... | true |
574cd341f4e468865231ff141ee9eadf88ff3fde | Ruby | CoreyHalicke/oo-student-scraper-online-web-sp-000 | /lib/scraper.rb | UTF-8 | 1,534 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'open-uri'
require 'pry'
class Scraper
def self.scrape_index_page(index_url)
students = []
doc = Nokogiri::HTML(open(index_url))
doc.css("div.student-card").each do |student|
students_hash = {
:name => student.css("h4.student-name").text,
:location => student.css("p.student-loc... | true |
3b54df592f1c708547089094c1316fd94b3de30b | Ruby | gischy/awe | /hangman/hang_man.rb | UTF-8 | 1,582 | 3.984375 | 4 | [] | no_license | class String
def is_upper?
self == self.upcase
end
def is_lower?
self == self.downcase
end
end
def startgame
puts ""
puts "game started!"
wordlist = File.open('dictionary.txt')
words_array = wordlist.readlines
while (true)
number = Random.new.rand(words_array.size-1)
word = words_array[number].chomp... | true |
b690ee91c22b79b0c33a4e2f0fd3ad883a498c47 | Ruby | hiremathm/JavascriptKit | /day14-function-pass-by-value-and-pass-by-reference/function.rb | UTF-8 | 292 | 3.25 | 3 | [] | no_license | a = 10
b = 20
c = [1,2,3]
d = {name: "shiva"}
def add(c,d)
a = 100
b = 200
c << 4
d["age"] = 20
puts "c"
return a + b, c, d
end
puts "a : #{a}, b : #{b}"
puts "Add :: #{add(c,d)}"
puts "a : #{a}, b : #{b}, c : #{c}, d : #{d}"
z = Array.new([10,20,30])
puts "z : #{z}" | true |
26e6d2c841078e2d005f7c0e0d4318cdb951a741 | Ruby | twifno/algorithm-puzzles | /events/hackercup19/qual/3.rb | UTF-8 | 1,454 | 3.484375 | 3 | [] | no_license | def getResult(s)
if(s[0] != "(") then return s end
if(s[1] != "(")
r1 = s[1];
op = s[2];
r2 = getResult(s[3..-2])
else
n = nextV(s, 1)
r1 = getResult(s[1..n])
op = s[n+1]
r2 = getResult(s[n+2..-2])
end
#puts r1
#puts op
#puts r2
return cal(r1, op, r2)
end
def nextV(s,idx)
... | true |
7236408bf2562e02899a58f23a7f3f9f1a9c7e37 | Ruby | ccarruitero/sunat_books | /test/pdf/utils_test.rb | UTF-8 | 1,098 | 2.609375 | 3 | [] | no_license | # frozen_string_literal: true
require_relative "../helper"
require "sunat_books/pdf/utils"
include Utils
setup do
@widths = [{ xyz: [20, 23], abc: [41] }]
@column_widths = get_column_widths(@widths, :xyz)
end
test "#get_column_widths return an empty obj when dont match key" do
column_widths = get_column_width... | true |
46979e998815557c2370612f6c02ac35e8f9934c | Ruby | whence/powerlife | /ruby/powercards/pile.rb | UTF-8 | 415 | 3.34375 | 3 | [
"MIT"
] | permissive | class Pile
attr_reader :sample, :remaining
def initialize(card_factory, card_count)
@factory = card_factory
@remaining = card_count
@sample = card_factory.new
end
def empty?
@remaining <= 0
end
def push
@remaining += 1
end
def pop
fail "#{@sample} pile is empty" if empty?
... | true |
80eff261ae6b5a6cb8ca6f2d07f5e6e85ffea03a | Ruby | dcrosby42/conject | /lib/conject/object_factory.rb | UTF-8 | 3,257 | 2.71875 | 3 | [
"MIT"
] | permissive |
module Conject
class ObjectFactory
construct_with :class_finder, :dependency_resolver
def construct_new(name, object_context)
object = nil
config = object_context.get_object_config(name)
lambda_constructor = config[:construct]
alias_for = config[:is]
klass = config[:class]
... | true |
979b59fe105edaea4c69459a43d7004024d1250b | Ruby | xhispams/Desafio_patrones_y_ciclos_anidados | /numeros.rb | UTF-8 | 228 | 3.265625 | 3 | [] | no_license | # n = ARGV[0].to_i
# (n+1).times do |i|
# i.times do |j|
# print "\n"
# print (j+1)
# end
# print "\n"
# end
n = ARGV[0].to_i
n.times do |i|
j = 0
while j <= i
j += 1
print "#{j}"
end
print " "
end
print "\n"
| true |
ac72dc1fbb67d361f46406c8bf72b60839c4796d | Ruby | tigerlily/columns | /lib/columns/extended_content.rb | UTF-8 | 360 | 2.578125 | 3 | [
"MIT"
] | permissive | module Columns
# Extends a content (column names and types) with some meta data.
class ExtendedContent
# Public: Get the extended content.
#
# content - The String content (from a ModelData object).
#
# Returns the String extended content.
def self.from(content)
"\n# == Schema Inform... | true |
10053542c2335ea2a63f5361634e474610b4f0d7 | Ruby | lloydclosson/business_time | /lib/business_time/config.rb | UTF-8 | 2,553 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'active_support/core_ext'
module BusinessTime
# controls the behavior of this gem. You can change
# the beginning_of_workday, end_of_workday, and the list of holidays
# manually, or with a yaml file and the load method.
class Config
# You can set this yourself, either by the load method below, or... | true |
30c331a3813a511cd23f82e68d41b613a715d980 | Ruby | cse-sim/cse | /doc/lib/template.rb | UTF-8 | 1,713 | 3.015625 | 3 | [] | permissive | require 'ostruct'
require 'erb'
module Template
# An example class that can be used to return a binding context
class Namespace
def initialize(hash)
hash.each do |key, value|
singleton_class.send(:define_method, key) { value }
end
end
def get_binding
binding
end
end
#... | true |
4ad71390fbb8514f83276ce9fbfb14dc4451efba | Ruby | Ahndaehwan/code | /random/permutation.rb | UTF-8 | 2,818 | 3.625 | 4 | [] | no_license | require 'debugger'
require 'colorize'
# all permutation of str, there are n! where n is size of the string
def permutation(str)
str_length = str.size
result = " "*str_length
used_chars = Array.new(str_length, 0)
recursiveLev = 0
do_permutation(str, result, used_chars, str_length, recursiveLev)
end
def do_p... | true |
f9bcbb8522ffc4945e8645c546b8bed1fc4d180e | Ruby | VirtualLindsey/StringManipulationInterviewPractice | /CSFUNstring_manipulation.rb | UTF-8 | 2,419 | 4.34375 | 4 | [] | no_license |
#String manipulation
#1 reverse single word in place
def reverse(word)
length = word.length/2.floor
length.times do |i|
temp = word[i]
word[i] = word[(i+1) *-1]
word[(i+1)*-1] = temp
end
puts s
end
#reverse('apples')
#2 reverse words in sentence in place
def reverseWords(sentence)
if senten... | true |
003498c6820ed30d293edb500828646a5d755c5e | Ruby | chrishunt/exercises | /2020-02-18-longest-path/solution.rb | UTF-8 | 480 | 3.03125 | 3 | [] | no_license | class Solution
def self.longest_path(filesystem)
dirs = []
longest_path = 0
filesystem.split("\n").each do |line|
tabs = 0
while line.match(/^\t/)
tabs += 1
line.gsub!(/^\t/, '')
end
dirs.pop while dirs.count > tabs
if line.match(/\./)
path = "#{di... | true |
311da69cf108614ddbcb0f1f71d25e9f19cdba61 | Ruby | patrickjonesdotca/ruby-red-ink | /test/original_spec_test.rb | UTF-8 | 7,971 | 2.625 | 3 | [
"MIT"
] | permissive | require_relative "test_helper"
# tests ported from the main Ink API
class OriginalSpecTest < Minitest::Test
# include PrettyDiffs
# Minitest::Test.make_my_diffs_pretty!
def test_arithmetic
json = load_json_export("test/fixtures/original-specs/arithmetic.ink.json")
story = RubyRedInk::Story.new(json)
... | true |
6c1b53880f0ebfaa928e9b570d843032f107548f | Ruby | CrisKP/Ruby_LearnToProgram | /leap_year.rb | UTF-8 | 1,141 | 4.5625 | 5 | [] | no_license | # Leap Years. Write a program which will ask for a starting year and an ending year, and then puts all of the leap years between them (and including them, if they are also leap years). Leap years are years divisible by four (like 1984 and 2004). However, years divisible by 100 are not leap years (such as 1800 and 1900)... | true |
b2c501eeaebddbbcfb7a8d84ff9ae1e8656de85e | Ruby | dlee16/crud-with-validations-lab-nyc-web-career-021819 | /app/models/song.rb | UTF-8 | 476 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ApplicationRecord
validates :title, presence: true, uniqueness: true
validate :missing_release_year, :future_release_year
def missing_release_year
if self.released == true && self.release_year == nil
errors.add(:release_year, "must have a release year")
end
end
def future_release... | true |
e35b92a86dbe5247e47e99755e1c7017689153f9 | Ruby | cavu757/activerecord-validations-lab-online-web-pt-021119 | /app/models/post.rb | UTF-8 | 1,182 | 3.25 | 3 | [] | no_license | class TitleValidator < ActiveModel::Validator
def validate(post)
if post.title
post.errors.add(:title, "not clickbaity enough") unless post.title.include?("Won't Believe") || post.title.include?("Secret") || post.title.include?("Guess") || post.title.match?(/(Top)\s(\d)+/)
else
post.errors.add(:t... | true |
db6ab9ee8caa69e37bea244db01b0a3ec259bf1e | Ruby | learningearnings/Mayhem | /lib/sti/async_importer.rb | UTF-8 | 2,964 | 2.640625 | 3 | [] | no_license | # This class should be called like so:
# sti_link_token = StiLinkToken.first
# client = STI::Client.new(base_url: sti_link_token.api_url, username: sti_link_token.username, password: sti_link_token.password)
# STI::AsyncImporter.new(client: client, district_guid: sti_link_token.district_guid).run!
load 'lib/sti/... | true |
461c48f36ff1b3e70662d57eb5c4688cb4c7dad8 | Ruby | ben-amor/rails-hangman-2 | /spec/Game_spec.rb | UTF-8 | 1,898 | 3.296875 | 3 | [] | no_license | require 'rails_helper'
describe Game do
def create_guesses(letters)
result = []
characters = letters.split('')
characters.each do |char|
result << Guess.create(value: char)
end
result
end
let(:secret_word) { 'hello' }
let(:guesses) { [] }
subject(:game) { described_class.new(secre... | true |
092e64c228915b8368b14faf1f65a5d052a4f59f | Ruby | shelleyyz/WDi28-Homework | /tim_caldwell/week_04/day_01/mortgage.rb | UTF-8 | 621 | 3.984375 | 4 | [] | no_license | # M is your monthly payment.
# P is your principal.
# r is your monthly interest rate, calculated by dividing your annual interest rate by 12.
# n is your number of payments (the number of months you will be paying the loan)[6]
# M = P * ( (r*(1+r)^n ) / ((1 + r)^n - 1))
puts "Welcome ot the mortgage repayment calcul... | true |
0d719917126db1e919be6f11a041cb5b4416a0c4 | Ruby | powerhome/playbook | /playbook/app/pb_kits/playbook/pb_progress_simple/progress_simple.rb | UTF-8 | 2,452 | 2.625 | 3 | [
"ISC"
] | permissive | # frozen_string_literal: true
module Playbook
module PbProgressSimple
class ProgressSimple < Playbook::KitBase
class ProgressError < StandardError; end
prop :align, type: Playbook::Props::Enum,
values: %w[left center right],
default: "left"
prop :value, ty... | true |
93a2321cf86deeae3649b3a6e61c6ade9f49cc86 | Ruby | karlwitek/launch_school_rb101 | /main_review/video_exercises/print_primes.rb | UTF-8 | 737 | 4.9375 | 5 | [] | no_license | # Write a method that takes two numbers as arguments. It should print all prime numbers between
# the two numbers. Don't use Ruby's Prime class.
# define method to test if number is prime.
def is_prime?(number)
(2...number).each do |num|
return false if number % num == 0
end
true
end
puts is_prime?(7) # tr... | true |
d44d9c33178e7dffa76ab811d6aae9cedccb21ae | Ruby | saramoohead/airport_challenge_wk2 | /lib/airport.rb | UTF-8 | 261 | 3.03125 | 3 | [] | no_license | class Airport
attr_reader :store
def initialize
@empty
@store = []
end
def empty?
@empty = true
end
def land! plane
plane.land!
store << plane
end
def take_off! plane
plane.take_off!
store.delete(plane)
end
end
| true |
c9d9bb514205ce0f83d2c64a3e782cea14eea364 | Ruby | Sillhouette/oo-cash-register-v-000 | /lib/cash_register.rb | UTF-8 | 869 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :total, :discount, :items, :last_transaction
def initialize(discount = 0.0)
@total = 0.0;
@discount = discount;
@items = [];
@last_transaction = [];
end
def add_item(item, price, quantity = 1)
quantity > 1 ? quantity.times{@items << item} : @items << item;... | true |
5955b18076ce3b391b1efddb5aa14668ee2b4a1b | Ruby | isaiah/jruby-stream | /test/test_lazy.rb | UTF-8 | 650 | 2.921875 | 3 | [
"MIT"
] | permissive | $:.unshift(File.expand_path("../../lib", __FILE__))
require 'minitest/autorun'
require 'lazy'
class TestLazyEnumerator < MiniTest::Unit::TestCase
def setup
r = 1..Float::INFINITY
@s = r.lazy
end
def test_map
assert_equal([101,102,103], @s.map{|x| x + 100}.take(3).force)
end
def test_select
... | true |
d13946b0f73a50b22f0ef4f1394e58d20520fa29 | Ruby | grassdog/klipbook | /lib/klipbook/commands/command.rb | UTF-8 | 818 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Klipbook
module Commands
class Command
def initialize(logger=Logger.new)
@logger = logger
end
def run!(options)
run_command!(book_source(options), options)
end
def run_command!
raise "Implement me"
end
private
attr_reader :logger
... | true |
64b9aa1d64cb1a88456efed6c122f963c5f9c52a | Ruby | vkurnavenkov/algorithms | /leetcode/dynamic-programming/knapsack.rb | UTF-8 | 504 | 3.34375 | 3 | [] | no_license | #!/usr/bin/env ruby
def knapsack(capacity, weights)
values = Array.new(capacity + 1) { Array.new(weights.size + 1, 0) }
(1..capacity).to_a.each do |w|
(1..weights.size).to_a.each do |i|
values[w][i] = values[w][i - 1]
if weights[i - 1] <= w
values[w][i] = [values[w][i], values[w - weights[i... | true |
9a185dd0a89c8401784b3c81474da10f095ae476 | Ruby | vijayendran91/Comcast | /Task 2/add_apple_to_basket.rake | UTF-8 | 783 | 2.796875 | 3 | [] | no_license | namespace :basket do
desc 'Add apple to the baskets'
task add_apples_to_basket: :environment do
Baskets.find_each do |basket|
Apples.find_each do |apple|
if basket.fillrate = 0
basket.fillrate=((((basket.fillrate)/100)*basket.capacity)+apple.count)/basket.capacity
else if basket.... | true |
2a4722f009c281932575f7b70f768aa908198cfe | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/filtered-submissions/063bd4313c644988b7ecdd552b595300.rb | UTF-8 | 222 | 3.046875 | 3 | [] | no_license | def compute(first_strand, second_strand)
length = [first_strand.size, second_strand.size].min
(0...length).reduce(0) do |error, n|
error += 1 if (first_strand[n] != second_strand[n])
error
end
end | true |
de04a430493d0ce8fa5fcdf629f867228da520e1 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/secret-handshake/a57f3fe31dc444e1b336b807228ddc62.rb | UTF-8 | 1,063 | 3.4375 | 3 | [] | no_license | class SecretHandshake
def initialize(args)
@binary_number = args.to_i.to_s(2)
end
def commands
if @binary_number.to_i > 10_000
return match((@binary_number.to_i-10_000).to_s)
else
return match(@binary_number).reverse
end
end
def match(x)
return ["wink"] if x == "1"
retur... | true |
a498f3da7951601e856fa65e5046ba1a66740b3d | Ruby | irmercaldi/Coding-Exercises | /30.rb | UTF-8 | 320 | 2.90625 | 3 | [] | no_license | require 'rspec'
class Hash
def param_converter
self.map { |x| x * "="} * "&"
end
end
describe 'HTML Param Converter' do
it 'Adds an HTML param converter to the Hash class' do
hash = { :topic => "baseball", :team => "astros" }
expect(hash.param_converter).to eq('topic=baseball&team=astros')
end
end | true |
748e61c01b9138d3458e89b282fe8ccf625eb2af | Ruby | blinkboxbooks/ios-test | /features/pages/model/model_helpers.rb | UTF-8 | 871 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module PageModelHelpers
include Logging
# Determine page class name based on page name
#
# @param [String] page_name page name in plain text. possible page name in the step: AllInclusive, All-Inclusive, All Inclusive, AllInclusivePage, All-Inclusive Page, All Inclusive Page
# @return an instance of p... | true |
678c31823064863e0023c51ebad6505eef5eb483 | Ruby | JethroF22/odinproject | /Rails/Sinatra/resources/app.rb | UTF-8 | 1,772 | 3.09375 | 3 | [] | no_license | require "sinatra"
require "rerun"
require "erb"
require_relative "name_validator"
enable :sessions
# index route
get "/members" do
@members = read_members
erb :index
end
# new route
get "/members/new" do
erb :new
end
# create route
post "/members/new" do
@name = params["name"]
@members = read_members
va... | true |
8cfd6d6cc7119aefc0f25c9d86c2df807205fcd6 | Ruby | anisssoudki/oo-banking-onl01-seng-pt-021020 | /lib/bank_account.rb | UTF-8 | 937 | 3.984375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # #initialize
# can initialize a Bank Account (FAILED - 1)
# initializes with a name (FAILED - 2)
# always initializes with balance of 1000 (FAILED - 3)
# always initializes with a status of 'open' (FAILED - 4)
# #deposit
# can deposit money into its account (FAILED - 5)
# #display_balance
# c... | true |
2fe1b6504b883831fff2bccdda011d2e4ef86238 | Ruby | anuradha2396/new | /Assignment 3/protected.rb | UTF-8 | 408 | 3.546875 | 4 | [] | no_license | # Example of protected method
class Example
def initialize
self.Prot
end
def Public
puts "Public method"
end
protected
def Prot
puts "protected method"
end
end
#creation of object
E1 = Example.new
#calling of public class
E1.Public
#calling of P... | true |
5a1c1b2896c30e459f4226cd1d65832a744e13bf | Ruby | husathap/Inuvik | /lib/ui.rb | UTF-8 | 1,690 | 3.375 | 3 | [] | no_license | # Button file!
class Button
def initialize(x, y, text_or_image, size=30)
@x = x
@y = y
@color = Gosu::Color.argb(255, 255, 255, 255)
@over_color = Gosu::Color.argb(255, 255, 255, 0)
if text_or_image.is_a? String
@text_image = Gosu::Image.from_text($window, text_or_image, "Arial", size)
else
@... | true |
9dbda1dd94646c0939d47f18b9a49bf637f0c626 | Ruby | auroranockert/narray | /ext/mkmath.rb | UTF-8 | 7,728 | 2.5625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | require 'erb'
require "#{File.dirname(__FILE__)}/generator/ntype"
require "#{File.dirname(__FILE__)}/generator/nfunction"
NFunctions = [
{
:name => :square, :kind => :scalar, :visibility => :private,
:documentation => "Calculates _x^2_.",
:implementation => {
[:complex] => { :code => 'complex.c',... | true |
f961444937d6321611ff251e41dc01bd12c8b859 | Ruby | squareteam/yodatra | /spec/data/model.rb | UTF-8 | 1,067 | 2.640625 | 3 | [
"MIT"
] | permissive | # Mock model constructed for the tests
class Model
ALL = %w(a b c)
class << self
def all; ALL.map{ |e| Model.new({:data=> e }) }; end
def find(id)
if id.to_i < ALL.length
Model.new({:data => ALL[id.to_i]})
else
raise ActiveRecord::RecordNotFound
end
end
def create(p... | true |
c81999c41bc858658a08870db55e647074e958f8 | Ruby | Wcapers/thinknetica_ruby | /do_op_metaprogramming/pass_train.rb | UTF-8 | 311 | 2.875 | 3 | [] | no_license | # frozen_string_literal: true
# PassTrain
class PassTrain < Train
def initialize(number)
super(number)
@type = 'cargo'
end
def add_carriage(carriage)
super if carriage.is_a?(PassCarriage)
raise 'Неподходящий тип вагона' unless carriage.is_a?(PassCarriage)
end
end
| true |
7c865f44ac2e95a490349f696434b7e659a47674 | Ruby | jahde/test-first-ruby | /08_book_titles/book.rb | UTF-8 | 823 | 4.25 | 4 | [] | no_license | # Initially had trouble with multiple "Title" methods which were overriding each other and causing an error. Corrected this by removing the extra "title" and overwriting the method
class Book
attr_accessor :title
LITTLE_WORDS = %w{the a an and or in of} # array of unwanted capitalized words
def title=(book)
... | true |
bb9709eefa1919ea30b37e194cea9a7c080741d7 | Ruby | aumi9292/ruby_exercises | /procedural/basic/easy1.rb | UTF-8 | 2,058 | 4.375 | 4 | [] | no_license | # repeat yourself
def repeat(string, repeat)
repeat.times { puts string }
end
repeat('Hello', 3)
# odd
def is_odd?(integer)
integer.remainder(2) != 0
end
puts is_odd?(2) # => false
puts is_odd?(5) # => true
puts is_odd?(-17) # => true
puts is_odd?(-8) # => false
puts is_odd?(0) # => false
puts is_odd... | true |
4ab3393b5505a110f2d5e2064aae3ee28dd7ae66 | Ruby | sreedevk/game0flife | /bin/game0flife | UTF-8 | 2,349 | 3.21875 | 3 | [] | no_license | #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../lib/grid.rb'
require_relative '../lib/cell.rb'
require_relative '../lib/display.rb'
# main application class
class Game0fLife
DEF_FRAMERATE = 60
DEF_PATTERN_X = 20
DEF_PATTERN_Y = 20
def initialize
@grid = Grid.new
@framerat... | true |
b056dd0b1a466560a55ce5355441730b02b06274 | Ruby | Fancikey/coin | /coin.rb | UTF-8 | 167 | 2.90625 | 3 | [] | no_license | num = rand(10)
if num > 5
puts "Выпал орел"
elsif num < 5
puts "Выпала решка"
else
puts "Монетка встала на ребро"
end
| true |
252f5f908aa03a6904f0f76a7761e98c98c93d4f | Ruby | mecampbellsoup/flatiron | /jukebox_debugger/jukebox_spec.rb | UTF-8 | 658 | 2.8125 | 3 | [] | no_license | # run this file at the command line: rspec jukebox_spec.rb
# remember that tests can be your to-do list, and that you should get one
# test to pass at a time, doing the simplest thing you can for each one.
# read your rspec output carefully to find what you need to fix. the errors
# will guide you!
require_relative ... | true |
da2a554a7271a446c33636dbb9ba332fba42a98d | Ruby | dsh0416/rubychina-twitter-bot | /relay.rb | UTF-8 | 1,235 | 2.8125 | 3 | [
"MIT"
] | permissive | require "faraday"
require "twitter"
require "json"
require "date"
finished = File.readlines("finished.log").map(&:chomp).map(&:to_i)
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
config.consumer_secret = ENV["CONSUMER_SECRET"]
config.bearer_token = EN... | true |
41fe25953b9643f946b729e9e6160da756e323f5 | Ruby | lightspeedretail/castor | /lib/castor/cli.rb | UTF-8 | 2,250 | 2.703125 | 3 | [
"MIT"
] | permissive | require_relative 'config'
require_relative 'logging'
require_relative 'utils'
require_relative 'rds'
require_relative 'version'
require 'aws-sdk'
require 'fileutils'
module Castor
class CLI
include Logging
include RDS
include Utils
def initialize
config
@data_dir = @config[:data_directo... | true |
067277919983dc7b9ab5dd575776eb23d13c6d86 | Ruby | walidwahed/ls | /exercises/101-109_small_problems/medium2/06-tri-angles.rb | UTF-8 | 1,713 | 4.875 | 5 | [] | no_license | # Tri-Angles
# A triangle is classified as follows:
# right One angle of the triangle is a right angle (90 degrees)
# acute All 3 angles of the triangle are less than 90 degrees
# obtuse One angle is greater than 90 degrees.
# To be a valid triangle, the sum of the angles must be exactly 180 degrees, and all angles m... | true |
37c8c0b92e9f0a35dce66d756f9b55432389921e | Ruby | masavo/rails-bbs | /app/models/post.rb | UTF-8 | 835 | 2.71875 | 3 | [] | no_license | class Post < ApplicationRecord
# commentモデルと紐付いてることを表現
# 1.記事とコメントが1対nの関係なのでhas_many
# 2. 記事を作事をするとcommentsも削除する
has_many :comments,dependent: :destroy
# @post.commentsで引っ張ってこれる
# messageがある場合、presenceはtureと書かなくてもerror検出する
validates :author, length: {maximum: 10, message: '10文字以内で入力してください'}... | true |
07533b988610d3eb412eaccf4a39c5c1b705d3a6 | Ruby | alesouto-it/toys | /toys/lib/toys/templates/clean.rb | UTF-8 | 1,748 | 2.734375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Toys
module Templates
##
# A template for tools that clean build artifacts
#
class Clean
include Template
##
# Default tool name
# @return [String]
#
DEFAULT_TOOL_NAME = "clean"
##
# Create the template settings fo... | true |
724c370383d0d785b44bab11af7aa4ef1e275577 | Ruby | samycici/cs-webautomator | /bin/cs-webautomator-helpers.rb | UTF-8 | 1,478 | 2.6875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# encoding: UTF-8
def create_feature_file(name)
# options used to generate the file in the template function
opts = { name: camelize(name) }
# Feature
file_path = File.join(FileUtils.pwd, 'features', 'specifications', "#{name.downcase}.feature")
# Thor creates a file based on the templa... | true |
7fd775c04727bd6b9fbe2a27187af280654566a4 | Ruby | brendanoneill2016/ttt-game-status-online-web-sp-000 | /lib/game_status.rb | UTF-8 | 1,425 | 3.59375 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
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 won?(board)
winner_ = []
WIN_COMBINATIONS.each d... | true |
476be0d2ed7d8a05319e71761238d6d202b96038 | Ruby | chriswhitehouse/boris-bike-3 | /lib/docking_station.rb | UTF-8 | 571 | 3.359375 | 3 | [] | no_license | require './lib/bike.rb'
class DockingStation
attr_reader :stored_bikes
def initialize
@stored_bikes = []
end
def release_bike
raise StandardError.new "no bikes left" unless empty?(@stored_bikes) == false
#alternatively fail "no bikes available" ...
@stored_bikes.pop
end
def dock(bike)
... | true |
9de516e21a8178c07efe3ed4ed6866f164b6a371 | Ruby | ramlang/rb-101 | /lesson_6/twenty_one_final.rb | UTF-8 | 6,482 | 3.578125 | 4 | [] | no_license | GAME_TITLE = 'Twenty One'
NEW_LINE = "\n"
DASHED_LINE = "---------------------"
SUITS = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
VALUES = ('2'..'9').to_a + ['Jack', 'Queen', 'King', 'Ace']
WINNING_SUM = 21
STAY = 17
WINNING_POINTS = 3
def header(title)
puts "~ #{title} ~"
puts DASHED_LINE
end
def continue?
put... | true |
34453a41399a46738ded629ed9b51571e8c57813 | Ruby | nethacker/processwatch | /lib/processwatch/pw_setup.rb | UTF-8 | 3,150 | 2.625 | 3 | [
"MIT"
] | permissive | #License: (MIT), Copyright (C) 2013 Process Watch Author Phil Chen.
module Processwatch_setup
def setup
if File.directory?("/usr/local/processwatch")
puts "Process Watch Is Already Been Installed In /usr/local/processwatch"
else
`mkdir -p /usr/local/processwatch/conf`
general_restart_contact ... | true |
5b85cd6b3219ca08a1de9994454cb565be8d3ede | Ruby | rranshous/rollerring | /solver/mater.rb | UTF-8 | 1,130 | 3.5625 | 4 | [] | no_license | class Mater
def self.mate i1, i2
case rand(3)
when 0
[i1, i2].sample
when 1
self.uniform_crossover i1, i2
when 2
self.linear_mate i1, i2
end
end
def self.uniform_crossover i1, i2
indexes = []
[(i1.length/5),1].max.times do
while !indexes.include?(index = rand(... | true |
f8d82c72f1b946026deadeceb4e4aef1bc81845d | Ruby | hhabakuk/procrastination | /main.rb | UTF-8 | 3,831 | 2.8125 | 3 | [] | no_license | require 'sinatra'
require 'time_diff'
require 'httparty'
require 'json'
require 'pg'
require_relative 'db_config'
require_relative 'models/user'
enable :sessions
after do
ActiveRecord::Base.connection.close
end
get '/' do # first page, gets user activity
erb :index
end
post '/save_activity' do #saves a... | true |
df5d0a7d8e32a951aa0930b88d21b1041096a5e3 | Ruby | npolar/oceanography-ruby | /lib/oceanography/id_generator.rb | UTF-8 | 3,014 | 2.921875 | 3 | [
"MIT"
] | permissive | # Base64 implmentation of sequentail UUIDS
#
# 10⁻¹⁵ is the uncorrectable bit error rate of a typical hard disk.
# so this is our acceptable collision probability.
#
# CouchDbs sequentail ids have a 26 char hex random followed by
# a 6 hex char sequential. 26 chars => 16^26 = 2*10^31 hash space.
#
# The collinsion appr... | true |
a5d44df5d037af597085e494ab120b1bd3b91335 | Ruby | dbbrandt/squarespace | /squarespace.rb | UTF-8 | 1,188 | 2.9375 | 3 | [] | no_license | require 'nokogiri'
require 'json'
require './artwork.rb'
class Wordpress
attr_accessor :xml, :categories, :artworks
def initialize(file = "")
xml_file = File.read(file)
@xml = Nokogiri::XML.parse(xml_file)
category_elements = xml.xpath("//item[wp:post_type = 'page']")
item_pages = category_ele... | true |
67dadb118203c3ede448de918e957187922a3c66 | Ruby | orderedlist/solidus | /core/spec/lib/spree/money_spec.rb | UTF-8 | 8,297 | 2.796875 | 3 | [
"BSD-3-Clause"
] | permissive | # coding: utf-8
require 'spec_helper'
require 'spree/money'
RSpec.describe Spree::Money do
before do
configure_spree_preferences do |config|
config.currency = "USD"
end
end
describe '#initialize' do
subject do
Spree::Deprecation.silence do
described_class.new(amount, currency: c... | true |
5b42e05e72876708e8a4243beb30e5b45ea29b3c | Ruby | gellieb/workspace | /return_lesson.rb | UTF-8 | 174 | 3.1875 | 3 | [] | no_license | def greeting
# bunch of code
"hello world"
end
def leaving
"goodbye!"
end
def counter
iter = 0
while iter < 10
"hello"
iter += 1
end
end
puts counter | true |
4adeaf9643e1ffac9b2b5403072a1aec3a52cd49 | Ruby | punsammy/OOP-inheritance- | /exercise1.rb | UTF-8 | 1,088 | 4.21875 | 4 | [] | no_license | #Class Time
class Person
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{first_name} #{last_name}"
end
def greeting
"Bonjour, je m'appelle #{full_name} "
end
end
class Student < Person
... | true |
23d75b55e61560ff761450165c84bf8c5d0a20f3 | Ruby | edean11/NSS-cal | /lib/cal_month.rb | UTF-8 | 1,766 | 3.65625 | 4 | [
"MIT"
] | permissive | require_relative 'cal_day'
require_relative 'cal_year'
class Month
attr_reader :month,:year
def initialize(month,year)
@month = month
@year = year
end
Translate_month_table = [nil,"January","February","March","April",
"May","June","July","August","September","October","Novembe... | true |
5cd2a6e9a1ad436fe69c879640df8cdaf0e94475 | Ruby | mrbgems/m2x-mruby | /mrblib/m2x-client-device.rb | UTF-8 | 4,549 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module M2X; end
class M2X::Client; end
class M2X::Client::Resource; end
# Wrapper for {https://m2x.att.com/developer/documentation/v2/device M2X Device} API
class M2X::Client::Device < M2X::Client::Resource
# The API path of the device.
def path
@path ||= "/devices/#{HTTP::URL.encode(@attributes["id"])}"
end... | true |
d6469d397d4ba58f30336823fa8a6ffacaa466b4 | Ruby | tylerpporter/neos | /start.rb | UTF-8 | 2,376 | 3.4375 | 3 | [] | no_license | require_relative 'near_earth_objects'
class NearEarthObjectsDisplay < NearEarthObjects
def self.start
intro_dashboard
@@date ||= gets.chomp
@@asteroid_info ||= NearEarthObjects.find_neos_by_date(@@date)
return_dashboard
end
private
def self.intro_dashboard
puts "_________________________... | true |
8366f3edf74ce592b4fb320f48c73bfbfc72dac2 | Ruby | trizen/sidef | /scripts/Tests/unicode_support.sf | UTF-8 | 586 | 4.03125 | 4 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
#
## Example taken from: http://en.wikipedia.org/wiki/Falcon_(programming_language)#.22Hello_World.22_example
#
# International class; name and street
class 国際( なまえ, Straße ) {
# Say who am I!
method 言え {
say "I am #{self.なまえ} from #{self.Straße}";
}
}
# all the people of the wor... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.