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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
11df08cd511839f8df2e58519c87d3223783f9fd | Ruby | outlyerapp/dataloop-chef-handler | /files/default/dataloop_annotations.rb | UTF-8 | 2,123 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | require "chef"
require "chef/handler"
require "timeout"
require "net/http"
require "net/https"
require "uri"
class Chef::Handler::Dataloop < Chef::Handler
attr_writer :api_token, :host, :org, :account, :stream
def initialize(options = {})
@host = options[:host] || 'app.dataloop.io'
@api_toke... | true |
69e4ed310f87a7da9081881db7ae905bccb0fe39 | Ruby | tayloredwebsites/curriculum | /app/models/tree.rb | UTF-8 | 10,517 | 2.578125 | 3 | [] | no_license | class Tree < BaseRec
# Note: Found english version of letters mixed in with cryllic
# mapped english version of aejko cyrillic letters to match the corresponding english letter so both versions of the letter would map out properly to the english
# then mapped cyrillic letters, so english to cyrillic would return... | true |
570039566722b4f53f3a897061b16731af1e9424 | Ruby | litvinok/mongo-meta-driver | /ruby/lib/bson/extensions/time.rb | UTF-8 | 389 | 2.515625 | 3 | [] | no_license | module BSON
module Extensions
module Time
BSON_TYPE = "\x09"
def to_bson
[BSON_TYPE, [(to_i * 1000) + (usec / 1000)].pack(INT64_PACK)]
end
module ClassMethods
def from_bson(bson)
seconds, fragment = bson.read(8).unpack(INT64_PACK).first.divmod 1000
at(... | true |
f87ba3c35d819eb6344dd7bcb1879a6e91d39933 | Ruby | mfeinLearn/OO-Art-Gallery-dumbo-web-080618 | /tools/console.rb | UTF-8 | 2,504 | 3.03125 | 3 | [] | no_license | require_relative '../config/environment.rb'
require 'pry'
def reload
load 'config/environment.rb'
end
# Declare variables here
pablo_picasso = Artist.new("Pablo Picasso", 1)
leonardo_da_vinci = Artist.new("Leonardo da Vinci", 1)
vincent_van_gogh = Artist.new("Vincent van Gogh", 1)
peter_paul_rubens = Artist.new(... | true |
18773c647f80cc263c36d426a02c0f4166fe8299 | Ruby | ptn/chess_validator | /lib/chess_validator/board/invalid_move.rb | UTF-8 | 566 | 2.890625 | 3 | [] | no_license | module ChessValidator
class Board
# Raised when a board is asked to validate a move that is not in algebraic
# notation.
class InvalidMove < Exception
def self.for_origin(origin)
new("Origin move '#{origin}' is not in valid algebraic notation")
end
def self.for_destination(desti... | true |
72a4dee6ca2f63f58760eb618e319e4baa7a2f89 | Ruby | kasperbn/failsafe-control-for-DTUSat2 | /server/link_fs/link_fs_devel.rb | UTF-8 | 1,583 | 2.6875 | 3 | [] | no_license | require 'serialport'
require ROOT_DIR + "/lib/logger"
require ROOT_DIR + "/lib/constants"
module Link_fs
class << self
include Constants
include Loggable
DEVICE = "/dev/ttyUSB0"
BAUD = 9600
DATA_BITS = 8
STOP_BITS = 1
PARITY = SerialPort::NONE
def link_fs_init(rw)
begin
$sp = SerialPo... | true |
122c9fbb4174ba3e4547a322c8eb881e12b1ce60 | Ruby | blarxfj/deli-counter-cb-gh-000 | /deli_counter.rb | UTF-8 | 539 | 4.09375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def line(katz_deli)
string = "The line is currently:"
if katz_deli.empty?
string = "The line is currently empty."
else
katz_deli.each_with_index { |e, i| string << " #{i+1}. #{e}" }
end
puts string
end
def take_a_number(katz_deli, name)
katz_deli << name
puts "Welcome, #... | true |
b6084a45af97dcc01c27adbffe23293be8616edf | Ruby | xbenjii/YuelaBot | /app/bot/commands/time_command.rb | UTF-8 | 804 | 2.859375 | 3 | [] | no_license | module Commands
class TimeCommand
class << self
def name
:time
end
def attributes
{
description: "Displays the current time in a timezone",
usage: "time <timezone>",
aliases: []
}
end
def command(event, *args)
return if ... | true |
a1a1eb83c9295b2e36ab4c3113d434987b211eea | Ruby | kristofkovacs/meetup.sch | /app/Rakefile | UTF-8 | 748 | 2.53125 | 3 | [] | no_license | require "bundler/setup"
require "sequel"
require "yaml"
require "digest"
namespace :db do
task :create do
env = ENV['RACK_ENV'] || 'development'
DB = Sequel.sqlite "#{env}.db"
DB.create_table :attendees do
primary_key :id
column :name, String, :null => false
column :organization, String... | true |
1856d4422234e0a7ad9e62ac0259b6a39c1b3ef2 | Ruby | Envek/snils | /spec/snils_spec.rb | UTF-8 | 3,500 | 3.046875 | 3 | [
"MIT"
] | permissive | require 'rspec'
require 'snils'
describe Snils do
# DISCLAIMER: All SNILS used there ARE GENERATED AND RANDOM. Any coincidences are accidental.
describe '#initialize' do
it 'should initialize with formatted snils' do
snils = described_class.new('963-117-158 08')
expect(snils.raw).to eq('96311715... | true |
3726f866e1fd5db674fbfc4508315c39c17a4b79 | Ruby | travis-ci/travis-conditions | /lib/travis/conditions/v1/helper.rb | UTF-8 | 659 | 2.671875 | 3 | [
"MIT"
] | permissive | module Travis
module Conditions
module V1
module Helper
QUOTE = /["']{1}/
OPEN = /\(/
CLOSE = /\)/
SPACE = /\s*/
def quoted
return unless quote = scan(QUOTE)
scan(/[^#{quote}]*/).tap { scan(/#{quote}/) || err(quote) }
end
def par... | true |
8325885456ffde025a4fc8d71ab0a9f160a5454d | Ruby | Emmyn5600/PrivateEvent | /app/helpers/user_helper.rb | UTF-8 | 1,542 | 2.53125 | 3 | [
"MIT"
] | permissive | module UserHelper
# rubocop:disable Layout/LineLength
def show_user_event_list(events)
out = ''
events.each do |event|
out += '<div class="box">'
out += "<ul class=\"is-flex is-justify-content-space-between is-align-content-center\"><li class=\"mt-2 has-text-weight-bold\">#{event.title}</li>"
... | true |
49912bf496a441e40ff116a52deee30011d2286b | Ruby | kenhys/hibahub-client | /lib/yomou/config.rb | UTF-8 | 1,886 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "yaml"
module Yomou
class Config
YOMOU_CONFIG = 'yomou.yaml'
DOT_YOMOU = '.yomou'
def initialize
@keys = []
if File.exist?(path)
load
else
src = File.dirname(__FILE__) + "/../../examples/#{YOMOU_CONFIG}"
FileUtils.cp(src, p... | true |
40a3ac58a7d4f20aacb9946efe2567a04308a457 | Ruby | shawnkaku/Blackjack_Webapp | /classes/player.rb | UTF-8 | 828 | 3.53125 | 4 | [] | no_license | class Player
#includ calculate_point
attr_accessor :name, :status, :hold_cards, :money, :turn_bet
def initialize(name)
@name = name
self.money = 500
self.turn_bet = 0
# Player got all cards.
@hold_cards = Array.new
init
end
def init
# "RUN" => OK, "BST" => bust
@status = "RUN... | true |
a67359eb3f247c2791154f91caff2c40bbee12e7 | Ruby | elivickery/phase-0-tracks | /ruby/iteration_drill.rb | UTF-8 | 5,012 | 3.53125 | 4 | [] | no_license | # Array Drills
zombie_apocalypse_supplies = ["hatchet", "rations", "water jug", "binoculars",
"shotgun", "compass", "CB radio", "batteries"]
# 1. Iterate through the zombie_apocalypse_supplies array,
# printing each item in the array separated by an asterisk
# ----
def print_the_array(a... | true |
5adc36eda6cdf6156cba345dddeeb12bd59c1c26 | Ruby | Khetti/homework_w2d1 | /team/team.rb | UTF-8 | 1,177 | 3.421875 | 3 | [] | no_license | class Team
attr_accessor :team_name, :players, :coach, :points
# constructor
def initialize(input_team_name, input_players, input_coach)
@team_name = input_team_name
@players = input_players
@coach = input_coach
@points = 0
end
# does a methods
def add_new_player(new_player)
@players ... | true |
bcb34d723bb351212f4437ac80c95dfc93115331 | Ruby | brendannee/bikesy-server | /rbgs/extension/tiger_gtfs/link_tiger_gtfs_extend.rb | UTF-8 | 5,389 | 2.578125 | 3 | [
"BSD-3-Clause"
] | permissive | class Graphserver
SEARCH_RANGE = 0.0006 #degrees
#returns the next stop id and location each time that is called
def each_stop
stops = conn.exec "SELECT stop_id, location FROM gtf_stops"
stops.each do |stop_id, location|
yield stop_id, location
end
end
def nearest_tiger_line( stop_geom, se... | true |
39642abff4884348750c9c7af5db8207c40375cc | Ruby | Aryk/dead_simple_cms | /lib/dead_simple_cms/attribute/type/base.rb | UTF-8 | 2,819 | 2.640625 | 3 | [
"MIT"
] | permissive | module DeadSimpleCMS
module Attribute
module Type
class Base
include Util::Identifier
class << self
# Public: the method name used to identify this type in the Builder
attr_writer :builder_method_name
# If not provided on the subclass infer it from the class ... | true |
9f46ad44d802f095a5cc0dde688a1dbb9bbf6fec | Ruby | TominagaRyuto/ruby | /lesson7-2.rb | UTF-8 | 400 | 3.65625 | 4 | [] | no_license | p "計算を始めます"
p "何回計算を繰り返しますか"
kaisuu = gets.to_i
x = 1
while x <= kaisuu do
p "#{x}回目の計算"
p "2つの値を入力して下さい"
a = gets.to_i
b = gets.to_i
p "a=#{a}"
p "b=#{b}"
p "計算結果を出力します"
p "a+b=#{a + b}"
p "a-b=#{a - b}"
p "a*b=#{a * b}"
p "a/b=#{a / b}"
x += 1
end
p "計算を終了します"
| true |
711748cf8bc45433a5d36cbdb806a6eea3e95d8d | Ruby | jeffreyguenther/olympics | /app/models/import/athlete_with_records.rb | UTF-8 | 584 | 2.6875 | 3 | [] | no_license | class Import::AthleteWithRecords
def initialize(athlete, records = {})
@athlete = athlete
@records = records
end
delegate :id, to: :@athlete
def opening_weight(meet_type, movement)
current_max = @records[movement]
if current_max.blank? || current_max <= 0
meet_type.opening_weight_for(mo... | true |
b990e2ef6b2814a18455c490623742e23a0f8dc6 | Ruby | mpletcher/phase-0-tracks | /ruby/hashes.rb | UTF-8 | 3,185 | 4.625 | 5 | [] | no_license | =begin
5.2 Arrays and Hashes
Author: Marcos Pletcher
-------------Pseudocode -----------------
Prompt the user for his/her name, age, number of children, decor theme,
If user inputs unvalid data, re-promt the user
Convert any user input to the appropriate data type
Prompt the user if any information needs to be chang... | true |
a883b6cf8047fb0e4f4a21c742e596a6f017317a | Ruby | mlibrary/heliotrope | /app/services/json_web_token.rb | UTF-8 | 1,279 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module JsonWebToken
# secret to encode and decode token
HMAC_SECRET = Rails.application.secrets.secret_key_base
# https://github.com/jwt/ruby-jwt
#
# JSON Web Token defines some reserved claim names
# and defines how they should be used.
#
# JWT supports these reserved cl... | true |
24be153304d7b0050db3c8dd70aacf61ac1f789d | Ruby | aliasmac/ruby-collaborating-objects-lab-london-web-082718 | /lib/song.rb | UTF-8 | 353 | 3.296875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
class Song
attr_accessor :name, :artist
@@all = []
def initialize(name)
@name = name
@@all << self
end
def artist_name=(artist_name)
self.artist.name = artist_name
end
def self.new_by_filename(filename)
song_name = filename.split(" - ")
song = self.new(song_name[1])
# song.a... | true |
c89305df6303c655bfa85309b161462cded6d109 | Ruby | abuisman/tukey | /lib/tukey/data_set/label.rb | UTF-8 | 824 | 2.96875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'ostruct'
class DataSet
class Label
attr_accessor :id
attr_accessor :name
attr_accessor :meta
def initialize(name, id: nil, meta: {})
@name = name
@id = id || name
raise ArgumentError, 'DataSet::Label meta must be a Hash' unless meta.is_a?(Has... | true |
cc68ff86ccbeb6312e96dde6849abcf672f63c4d | Ruby | jmansor/mars_rover | /lib/mars_rover/rover_controller.rb | UTF-8 | 420 | 2.90625 | 3 | [
"MIT"
] | permissive | module MarsRover
class RoverController
def move(current_position)
orientation = current_position.orientation
new_position = current_position.clone
case orientation
when 'N'
new_position.y +=1
when 'S'
new_position.y -=1
when 'W'
new_position... | true |
e9da9630e0e83691c929bd7e7887dbd63f512339 | Ruby | eregon/project_euler | /065.rb | UTF-8 | 1,127 | 3.71875 | 4 | [] | no_license | =begin
The square root of 2 can be written as an infinite continued fraction.
The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates that 2 repeats ad infinitum.
In a similar way, √23 = [4;(1,3,1,8)].
It turns out that the sequence of partial values of continued fractions for square roots provide... | true |
af5b2b44755cb41aa1751df25c9a70afe66f34aa | Ruby | vgvinay2/ruby_programme | /thread/program-1.rb | UTF-8 | 2,156 | 4.65625 | 5 | [] | no_license | def calculate_sum(arr)
sum = 0
arr.each do |item|
sum += item
end
sum
end
@items1 = [12, 34, 55]
@items2 = [45, 90, 2]
@items3 = [99, 22, 31]
puts "items1 = #{calculate_sum(@items1)}"
puts "items2 = #{calculate_sum(@items2)}"
puts "items3 = #{calculate_sum(@items3)}"
## The output of the above program wo... | true |
53fec716a2c45e7afb3210bcfae7f75cf6508d96 | Ruby | gpatuwo/chess | /board.rb | UTF-8 | 2,129 | 3.578125 | 4 | [] | no_license | require_relative "pieces"
require 'colorize'
class Board #1. make grid 2.populate grid 3. moves pieces (if valid move from Pieces) 4. game over?
# def self.populate_board(board)
# # create all the different pieces
# # place the 16 pieces on each side
# # place nil in remaining pos
# end
attr_accesso... | true |
aba8870be7c1e6eb8d77968d7d277e9601afc355 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/robot-name/3f42d76fca02419bae249d5fb709b58f.rb | UTF-8 | 231 | 3.28125 | 3 | [] | no_license | class Robot
def initialize
@name = random_name
end
def name
@name
end
def reset
@name = random_name
end
def random_name
('A'..'Z').to_a.shuffle[0..1].join + (0..9).to_a.shuffle[0..2].join
end
end
| true |
24d091c497f11e0fb3583ba3bfb7712e81fdc2bd | Ruby | kellyarwine/iterator_example | /spec/vegetable_iterator_spec.rb | UTF-8 | 1,874 | 2.984375 | 3 | [] | no_license | require 'vegetable_iterator'
describe VegetableIterator do
context "next" do
before(:all) do
vegetable_hash = {"Carrot" => "Fresh",
"Red Bell Pepper" => "Expired",
"Celery" => "Fresh"}
@vegetable_iterator = VegetableIterator.new(vegetable_hash)
end
it "ret... | true |
aa5d26b5bccffeb04006f766c26963ab5cf6b671 | Ruby | Hpanora101/badges-and-schedules-online-web-pt-021119 | /conference_badges.rb | UTF-8 | 481 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(name)
name.collect do |name|
badge_maker(name)
end
end
def assign_rooms(speakers)
speakers.collect.each_with_index do |speaker, index|
"Hello, #{speaker}! You'll be assigned to room #{index+1}!"
end
end
def print... | true |
2251869ebafab9e4e489d1fc011a09c60b2a332d | Ruby | eegrok/cleanify-epub | /lib/mapping.rb | UTF-8 | 5,101 | 2.640625 | 3 | [] | no_license | require 'crypt'
module Mapping
extend self
@@mappings = nil
@@phrases = nil
@@substring_phrases = nil
# if the value is an array, then it's one we want to display when we replace (we'll display them all if we do verbose)
# if it's not an array, we don't display it
MAPPINGS =
{'9768634b51ca38a98892c7086c9e3122' => ['... | true |
61dc91c04de4f05ea2b0c2d85f0453b9f6ccdc60 | Ruby | PhilHuangSW/Leetcode | /valid_parentheses.rb | UTF-8 | 2,403 | 4.46875 | 4 | [] | no_license | #################### VALID PARENTHESES ####################
# Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
# determine if the input string is valid.
# An input string is valid if:
# Open brackets must be closed by the same type of brackets.
# Open brackets must be closed in the c... | true |
3e6f5e48cc7523e3dbdd5d0986386d15e1bff45c | Ruby | NurfitraPujo/cli-turnbased-game | /lib/CharacterFactory.rb | UTF-8 | 574 | 3 | 3 | [
"MIT"
] | permissive | require_relative './Character'
require_relative './Hero'
require_relative './Soldier/Archer'
require_relative './Soldier/Spearman'
require_relative './Soldier/Swordsman'
def create_char(name, hit_point, attack_dmg, options = {})
return Hero.new(name, hit_point, attack_dmg) if options[:is_hero]
return Archer.new(na... | true |
1b5ad16347461a6f712d7bad58d2d741548f378f | Ruby | xaviershay/dominion-solitaire | /lib/dominion/ui/ncurses/window.rb | UTF-8 | 693 | 2.6875 | 3 | [] | no_license | module Dominion::UI::NCurses
class Window
include FFI::NCurses
attr_accessor :window, :game
def initialize(game)
self.game = game
end
def print(color, text, bold = false)
color_index = colors[color] || raise("Unknown color: #{color}")
wattr_set window, bold ? A_BOLD : A_NORMAL... | true |
20cd698f2b4769a5322a2cd474307265173015b1 | Ruby | jobberslayer/Prayer-Journal | /app/models/prayer_request.rb | UTF-8 | 3,437 | 2.578125 | 3 | [] | no_license | require 'lib/myconfig'
class PrayerRequest < ActiveRecord::Base
has_many :prayer_updates
validates_presence_of :title, :request
def belongs_to_user?(user_id)
super_user_id = get_super_user_id()
return (self.user_id == user_id or user_id == super_user_id)
end
def can_be_viewed?(user_id)
i... | true |
518ec2cc4b999aeb76b9f30ea6192891d586081b | Ruby | nxdf2015/odin-serialization | /event_manager/lib/event_manager.rb | UTF-8 | 1,203 | 3.03125 | 3 | [] | no_license | require "csv"
require 'sunlight/congress'
require "erb"
Sunlight::Congress.api_key = "e179a6973728c4dd3fb1204283aaccb5"
content =CSV.open "event_attendees.csv" , headers: true ,header_converters: :symbol
def clean_zip_code(zipcode)
zipcode.to_s.rjust(5,"0")[0..4]
end
def clear_phone(phone)
phone = phone.g... | true |
2f6effc852d2eb76a06079ea0dac906243844a4f | Ruby | Tkam13/atcoder-problems | /abc169/d.rb | UTF-8 | 179 | 2.875 | 3 | [] | no_license | n = gets.to_i
require 'prime'
factor = Prime.prime_division(n)
ans = 0
factor.each do |_,i|
cnt = 0
while cnt * (cnt + 1) <= 2 * i
cnt += 1
end
ans += cnt - 1
end
puts ans | true |
0f9c5a8ada5c8ad334c659cc8ae94849ffa7f6c9 | Ruby | jparkSF/algorithms | /jiwoo_park_heap/lib/heap.rb | UTF-8 | 2,326 | 3.5 | 4 | [] | no_license | class BinaryMinHeap
attr_reader :store, :prc
def initialize(&prc)
@store = []
@count = 0
@prc = prc ? prc : Proc.new {|el1, el2| el1 <=> el2}
# @prc = prc
end
def count
@count
end
def extract
val = @store[0]
@store[0], @store[@store.length-1] = @store[@store.length-1], @store... | true |
5be06827aa4e91cf99681dec10ee0a761adaae44 | Ruby | Slaan/seic | /lib/tracks_deserializer_mark.rb | UTF-8 | 420 | 2.625 | 3 | [] | no_license | class TracksDeserializerMark
def self.deserialize(track)
Track.build_from_hash("name" => track["track_name"],
"description" => track["track_description"],
"keywords" => track["track_keywords"],
"waypoints" => track["track_geojson"])
end
def self.deserialize_all(trac... | true |
98288bf7b18bb973cd4dab46c0860a7d9149b2f3 | Ruby | ysawa/sengine | /app/models/hand.rb | UTF-8 | 2,373 | 3.765625 | 4 | [] | no_license | # -*- coding: utf-8 -*-
class Hand
# Hand means the numbers of pieces in hands of players
KEY_NAMES = %w(fu ky ke gi ki ka hi ou)
attr_reader *KEY_NAMES
def to_a
[nil, @fu, @ky, @ke, @gi, @ki, @ka, @hi, @ou]
end
def generate_name(key)
case key
when 0
nil
when Integer
KEY_NAME... | true |
d08fd39d7cd157ce778c259ea17c47a0b94b5821 | Ruby | xm-71/ConcertTickets | /app/models/concert.rb | UTF-8 | 330 | 2.59375 | 3 | [] | no_license | class Concert < ActiveRecord::Base
has_many :purchases
belongs_to :venue
def tickets_remaining
a = self.tickets_available
b = self.purchases.sum(:ticket_quantity)
return a-b
end
def tickets_percentage
a = self.tickets_available
b = tickets_remaining
return (b.to_f / a.to_f) * 100
... | true |
49cb28773cf85bf5be3cb2ffc8f7edf9f09292d6 | Ruby | SketchUp/ruby-api-stubs | /lib/sketchup-api-stubs/stubs/Sketchup/RenderingOptionsObserver.rb | UTF-8 | 1,489 | 2.9375 | 3 | [
"MIT"
] | permissive | # Copyright:: Copyright 2023 Trimble Inc.
# License:: The MIT License (MIT)
# This observer interface is implemented to react to rendering options events.
#
# @abstract To implement this observer, create a Ruby class of this type, implement the
# desired methods, and add an instance of the observer to the objects of... | true |
649ace3d4c7e206572f4f33245a8777e92f135af | Ruby | devico/learning-ruby | /imdb_budgets.rb | UTF-8 | 550 | 2.6875 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'yaml'
require 'ruby-progressbar'
module ImdbBudgets
def take_budget_from_file(file_name)
YAML::load_file(File.open(file_name))[file_name[5,9]]
end
def take_budget_from_imdb(id)
data = take_info
data = if data =~ /^(\$|\€|\£|DEM|AUD|FRF)/
dat... | true |
b14f29196b46e36bf3b294cc617464fb0588c8ba | Ruby | stevenchanin/find-unique-files | /file_record.rb | UTF-8 | 563 | 2.96875 | 3 | [
"MIT"
] | permissive | class FileRecord
attr_reader :path, :name, :size, :create_datetime, :modify_datetime
def initialize(path)
@path = path
load_file_details
end
def ==(other)
name == other.name &&
size == other.size &&
modify_datetime == other.modify_datetime
end
def to_s
"#{name} [#{path}, #{si... | true |
e2e1706d5176d06935a1981b85ea0e89da08c418 | Ruby | thisduck/griddle | /lib/griddle/processor/image_magick.rb | UTF-8 | 1,650 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Griddle
class Processor
class ImageMagick
def crop
`convert #{File.expand_path(@destination_file.path)} -crop #{geometry} -gravity Center #{@destination_file.path}`
end
def crop?
@style.geometry =~ /#/
end
def file_width
file_dimens... | true |
40582f13ad3b30e8a2b299b5cf6a86199313e370 | Ruby | AJFaraday/ruby-buzz | /lib/ruby_buzz/button.rb | UTF-8 | 2,042 | 3.265625 | 3 | [
"MIT"
] | permissive | module RubyBuzz
#
# Handles a single button on the Buzz controllers.
#
# Identified by event code, all between 704 and 723.
# Also identifiable by pad and name.
#
# Possible names:
#
# * buzz
# * yellow
# * green
# * orange
# * blue
#
# Initialized in RubyBuzz::Pad.init_mappings
#
# Ea... | true |
78cd37edaebed138b44af78fd58d70e560aa7c87 | Ruby | chris-ma/WDI_SYD_7_NEW | /chris/w03/d01/chris/blog_app/app.rb | UTF-8 | 1,241 | 2.53125 | 3 | [] | no_license | require "pry"
require "sinatra"
require "sinatra/reloader"
require "pg"
def run_sql(sql_string)
connection = PG.connect(dbname: "my_blog", host: "localhost")
result = connection.exec(sql_string)
connection.close
return result
end
get '/' do
@posts = run_sql("SELECT * FROM posts;")
erb :home
end
get '/po... | true |
c51832324728d11abb73d97666fee476c84df5e0 | Ruby | Lyle-Tafoya/entity_handler | /examples/systems/graphics_ncurses.rb | UTF-8 | 1,223 | 2.53125 | 3 | [] | no_license | # Created on 10/22/2016 by Lyle Tafoya
#
require "entity_handler"
require "ncurses"
module EntityHandler
class GraphicsNcurses < System
@screen = nil
def initialize()
self.components_register(['position', 'scene_ncurses'])
System.callback_register('shutdown', self.method(:shutdown))
Syst... | true |
8b42f4a0757e99167342adb9eaa482e8d51e1aed | Ruby | hejinxu/docverter | /lib/docverter-server/manifest.rb | UTF-8 | 2,633 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'yaml'
class DocverterServer::Manifest
def pdf
@pdf
end
def pdf_page_size
@pdf_page_size
end
def self.load_file(filename)
File.open(filename) do |f|
self.load_stream(f)
end
end
def self.load_stream(stream)
self.new(YAML.load(stream))
end
def initialize(options... | true |
c5106addc48eb9bf81af959a71b1bd1d066683fb | Ruby | darkogj/rambling-trie | /lib/rambling/trie/tasks/performance/flamegraph.rb | UTF-8 | 3,205 | 2.53125 | 3 | [
"MIT"
] | permissive | namespace :performance do
include Helpers::Path
include Helpers::Time
def performance_report
@performance_report ||= PerformanceReport.new
end
def output
performance_report.output
end
class FlamegraphProfile
def initialize filename
@filename = filename
end
def perform times, ... | true |
364bbd3c94748feb4ed812239c563e9b34ca171a | Ruby | yone0000/furima35821 | /spec/models/item_spec.rb | UTF-8 | 3,832 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, type: :model do
before do
@item = FactoryBot.build(:item)
@item.image = fixture_file_upload('app/assets/images/IMG_1368.JPG')
end
describe '商品出品機能' do
context '商品出品できるとき' do
it 'image,name,info,category_id,sales_status_id,shipping_fee_status_id,pref... | true |
bdba86c5074b17e42cc77d1ea1b9eafb88385133 | Ruby | CodeCoreYVR/apr-2016-fundamentals | /ruby_day_2/method_return.rb | UTF-8 | 86 | 3.0625 | 3 | [] | no_license | def my_method
end
def method_1(a, b)
c = a + b
a * c
end
puts method_1(3,4) * 3
| true |
7cf0104675404c1ad67084a28e2778184a656402 | Ruby | mdnsean/lyrics | /app/helpers/scraper.rb | UTF-8 | 448 | 2.78125 | 3 | [] | no_license | module Scraper
def search_azlyrics(artist)
agent = Mechanize.new
artist = artist.gsub(' ', '')
artist_url = artist[0] + '/' + artist + '.html'
page = agent.get('http://azlyrics.com/' + artist_url)
song_links = page.links_with(href: /lyrics\/#{artist}/)
song = song_... | true |
38d33766f996645a516e5076351373c6527ed53c | Ruby | MattLemmon/cat-game | /bckgrnd/cpncat_gmst/CATCORE.rb | UTF-8 | 2,414 | 3.015625 | 3 | [] | no_license | #
# PAUSE CLASS
#
class Pause < Chingu::GameState
def initialize(options = {})
super
@title = Chingu::Text.create(:text=>"PAUSED (press 'p' to un-pause)", :x=>200, :y=>200, :size=>20, :color => Color.new(0xFF00FF00))
self.input = { :p => :un_pause, :q => DrdCat, :r => :reset }
end
def un_pause
po... | true |
33116ba9f094d4dbf53dbd7d241547b40de3735b | Ruby | ndlib/sipity | /app/services/sipity/services/administrative/update_who_submitted_work.rb | UTF-8 | 5,930 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | module Sipity
module Services
module Administrative
# @api private
#
# Please Note: I have not written tests for this. In part because I chose to add an audit (e.g. "Are you sure you want to do this?")
class UpdateWhoSubmittedWork
class ErrorState < RuntimeError
end
... | true |
ba4fa6059f06aee4f2214768e83431ee1fbb2e83 | Ruby | chatulli/sampleCodeRuby | /c1_hello_currentTime.rb | UTF-8 | 160 | 3.625 | 4 | [] | no_license | puts "Hello, Ruby Programmer"
puts "It is now #{Time.now}"
def say_goodnight(name)
result = "Good night," + name
return result
end
puts say_goodnight("ed")
| true |
f98ff2df5b8cba4ab5bcecefd4f954b79ad011bb | Ruby | datacite/base32 | /lib/base32/crockford.rb | UTF-8 | 4,648 | 3.453125 | 3 | [] | no_license | # encoding: UTF-8
#
# (c) 2008, Levin Alexander <http://levinalex.net>
#
# This file is released under the same license as ruby.
require 'enumerator'
module Base32
end
# encode a value with the encoding defined by _Douglas_ _Crockford_ in
# <http://www.crockford.com/wrmg/base32.html>
#
# this is *not* the same as th... | true |
59c2938c1a0fbaf4f247d7353135f03bc28e7673 | Ruby | BohanHsu/leetcode | /first_missing_positive.rb | UTF-8 | 898 | 3.734375 | 4 | [] | no_license | # Given an unsorted integer array, find the first missing positive integer.
# For example,
# Given [1,2,0] return 3,
# and [3,4,-1,1] return 2.
# Your algorithm should run in O(n) time and uses constant space.
# @param {Integer[]} nums
# @return {Integer}
def first_missing_positive(nums)
nums.length.times do |i|
... | true |
ea578f02d8362b1527dc9f27d8d70ebacc9322d9 | Ruby | zhshi/isjournals | /lib/journal.rb | UTF-8 | 3,218 | 2.796875 | 3 | [] | no_license | require 'sequel'
require 'open-uri'
require 'nokogiri'
require 'pdf-reader'
class Journal
def initialize(code, publisher, url)
@code = code
@publisher = publisher
@url = url
end
def check(articles, authors, abstracts)
case @publisher
when "informs"
puts "checking #{@code}"
check_... | true |
23d8b9df13dd10809cfef76612cff5e5e400c2e4 | Ruby | jas0nmjames/jas0nmjames.github.io | /vendor/bundle/ruby/3.2.0/gems/ttfunk-1.7.0/lib/ttfunk/table/hmtx.rb | UTF-8 | 1,498 | 2.53125 | 3 | [
"GPL-2.0-only",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-2.0-or-later",
"GPL-3.0-only",
"Ruby",
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../table'
module TTFunk
class Table
class Hmtx < Table
attr_reader :metrics
attr_reader :left_side_bearings
attr_reader :widths
def self.encode(hmtx, mapping)
metrics =
mapping.keys.sort.map do |new_id|
metric... | true |
3e72a76a936c5223b1559cdd1ca546ac79cbda27 | Ruby | miguelfajardoc/ruby_excercises | /test_dome/change.rb | UTF-8 | 576 | 3.75 | 4 | [] | no_license | # given an amount of money, return the minimum cuantity of coins
# with this options: 25, 10, 5, 2 and 1 cent. Returned in a hash
# if there are not some type coin used, the key must not be in the hash
def change(money)
change = {}
coins = [25, 10, 5, 2, 1]
unless money
puts "error"
return
end
money... | true |
b4bcc362c14c1e579b888728ac0b79ae5e74f1f0 | Ruby | marksweston/acts_as_raytracer | /lib/acts_as_raytracer/plane.rb | UTF-8 | 539 | 2.5625 | 3 | [] | no_license | class Plane < Shape
def self.default_material
return Material.new(
ambient: 0.30,
diffuse_reflection: 0.9,
specular_reflection: 0,
shininess: 0
)
end
def intersect(ray:)
return [] if object_space(ray).vector.y.round(epsilon).zero?
t = (-object_space(ray).origin.y) / objec... | true |
c2c38e3167c9be13cdad9ceda8d49c6ce0b3b0f8 | Ruby | dkubb/ice_nine | /spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb | UTF-8 | 2,961 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: utf-8
require 'spec_helper'
require 'ice_nine/freezer'
require 'ice_nine/freezer/object'
require 'ice_nine/freezer/array'
require 'ice_nine/freezer/struct'
describe IceNine::Freezer, '.[]' do
subject { object[mod] }
let(:object) { described_class }
let(:freezer) { object::Object }
describe 'wh... | true |
3681474b51457d47a45081659be7852ad74b4bf4 | Ruby | Vlado90/Unfuddled | /lib/unfuddled/error.rb | UTF-8 | 310 | 2.546875 | 3 | [] | no_license | module Unfuddled
class Error < StandardError
class << self
# Create an Error from an Erroneous HTTP Response
#
# @param response[Hash]
# @return [Unfuddled::Error]
def from_response(response = {})
new(response[:response_headers])
end
end
end
end
| true |
1aefda5370a319f196cc4b2a239c9fe7ed420ba2 | Ruby | protochron/Colonists-vs-Pirates | /lib/cannon.rb | UTF-8 | 1,318 | 3.171875 | 3 | [] | no_license | #
# Dan Norris and Cody Miller, 2011
require File.dirname(__FILE__) + '/game_object'
require File.dirname(__FILE__) + '/projectile'
# Implements a cannon object. This is a basic defensive structure for the player to destroy enemy ships with.
class Cannon < GameObject
attr_accessor :health, :projectiles
attr_r... | true |
290eb48ca878f78a251493c9b334eae89ab16133 | Ruby | mSourire/pla | /spec/controllers/products_controller_spec.rb | UTF-8 | 4,630 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe ProductsController, type: :controller do
let(:existing_product) { Product.create({ id: 5, name: 'Cucumber', price: 20, description: 'Green and crispy' }) }
describe "GET index" do
context "when a format is HTML" do
it "renders the index template" do
get :in... | true |
97ecca6c99086b6e187aa646a14e7356d874dee7 | Ruby | M1CH43L-S1M30N/Projects | /Michael_Chang_W6D5/Poker/spec/card_spec.rb | UTF-8 | 478 | 2.703125 | 3 | [] | no_license | require 'rspec'
require 'card'
describe Card do
describe '#initialize' do
subject(:card) {Card.new(:hearts, :deuce)}
it 'creates the card correctly' do
expect(card.value).to eq(:deuce)
expect(card.suit).to eq(:hearts)
end
it 'raises an error if invalid suit' do
expect (Card.new(... | true |
a0e8533795221d54f1b0f4641a69ed43426be1ad | Ruby | ArcWhiz/Ruby | /Arrays/two_arrays.rb | UTF-8 | 67 | 3.0625 | 3 | [] | no_license | arr1 = [1,2,3,4,5,6]
arr2 = arr1.map {|val| val+2}
p arr1
p arr2 | true |
ed7f164409feabeccd4f578ab37acad296c91d19 | Ruby | monodelic/study | /test/exercise/fp2/solution.rb | UTF-8 | 1,032 | 3.46875 | 3 | [] | no_license | module Exercise
module Fp2
class MyArray < Array
# Использовать стандартные функции массива для решения задач нельзя.
# Использовать свои написанные функции для реализации следующих - можно.
# Написать свою функцию my_each
def my_each
for element in self
yield element
... | true |
4ee0cad8827df170fda1bdbd869cfef7d8446aaf | Ruby | Mariana-21/launchschool_v2 | /101_109_small_problems/easy_6/03_fibonacci_location.rb | UTF-8 | 1,001 | 3.96875 | 4 | [] | no_license | # fibonacci_location.rb
def find_fibonacci_index_by_length(length)
first = 1
second = 1
fibonacci_number = first + second
index = 3
until fibonacci_number.to_s.size >= length
first = second
second = fibonacci_number
fibonacci_number = first + second
index += 1
end
index
end
p find_fibona... | true |
b35efec2dd5c3e9ece32289c908a7f615ab6861c | Ruby | bean00/Ruby-Tic-Tac-Toe | /spec/view_spec.rb | UTF-8 | 2,131 | 3.28125 | 3 | [] | no_license | require 'board'
require 'view'
describe 'display_board' do
let(:b) { Board.new(3) }
context 'when all positions are "x"s' do
it 'displays a formatted board' do
b.move(1, "X")
b.move(2, "X")
b.move(3, "X")
b.move(4, "X")
b.move(5, "X")
b.move(6, "X")
b.move(7, "X")
... | true |
ff23b6a5f2414bc5af5e7d3fdaea1990b1c03c71 | Ruby | pctj101/write_xlsx | /lib/write_xlsx.rb | UTF-8 | 1,948 | 2.96875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # -*- coding: utf-8 -*-
require 'write_xlsx/workbook'
#
# write_xlsx is gem to create a new file in the Excel 2007+ XLSX format,
# and you can use the same interface as writeexcel gem.
# write_xlsx is converted from Perl’s module github.com/jmcnamara/excel-writer-xlsx .
#
# == Description
# The WriteXLSX supports the... | true |
fe1777706c7553ed8ed49da36590a29fa0a8b34a | Ruby | sato0208/Ruby_lesson | /lesson5/lesson5_2_2.rb | UTF-8 | 439 | 3.609375 | 4 | [] | no_license | # ハッシュを使った繰り返し処理
currencies = ['japan' => 'yen', 'us' => 'dollar', 'india' => 'rupee']
currencies.each do |key, value|
puts "#{key} : #{value}"
end
# ブロック引数を一つにするとキーと値が配列に格納されます
currencies ={'japan' => 'yen', 'us' => 'dollar', 'india' => 'rupee'}
currencies.each do |key_vaule|
key = key_vaule[0]
value = key_va... | true |
68d337c02b7837f15b4fe422af1b8e3ed668509b | Ruby | exp-ndrew/survey | /main.rb | UTF-8 | 494 | 2.546875 | 3 | [] | no_license | require './cli/helper_cli'
@current_survey = nil
@current_question = nil
@current_user = nil
def main_menu
header
puts "T > Take a survey!"
puts "A > Create a survey!"
puts "E > Edit a survey!"
puts "D > Delete a survey"
puts "V > View survey results"
puts "X > Exit"
case gets.chomp.upcase
when 'T'
... | true |
2e84969ca11ca3aa684b94d93d276cbb8ef5ba02 | Ruby | OursDavid/Exercice-Scrapper | /lib/mairie-christmas.rb | UTF-8 | 871 | 2.859375 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
def get_townhall_email(townhall_url)
page = Nokogiri::HTML(URI.open(townhall_url))
commune = page.css("body > div > main > section.text-center.well.well-sm > div > div > div > h1").text
email= page.xpath('//*[contains(text(),"@")]').text.split
arr =[]
arr << {... | true |
419918ee40d94422639d4713d33b681a72d4fa3d | Ruby | tibbon/battle | /lib/battle/player.rb | UTF-8 | 1,407 | 3.28125 | 3 | [] | no_license | # Player
# represents a player for the game, human or computer
class Player
attr_accessor :money, :troops, :camp
INITIAL_SOLDIERS = 1
INITIAL_SCOUTS = 0
def initialize(money: 100)
@money = money
@troops = []
initialize_camp
initialize_army
end
def to_s
"Money: #{money} \n" +
arm... | true |
b940f7507510034361cee3f507b8736ed1b88e32 | Ruby | thebravoman/software_engineering_2015 | /c13_trees_2.0_before_ast/A_19_Nikolay_Rangelov.rb | UTF-8 | 368 | 2.578125 | 3 | [] | no_license | require 'rexml/document'
include REXML
xml_file = File.new("A_19_Nikolay_Rangelov.xml");
xml_doc = Document.new(xml_file);
xml_doc.root.elements.each do |school|
puts school.attributes["name"]
school.elements.each do |school_class|
puts "- " + school_class.attributes["name"]
school_class.elements.each do |stud... | true |
55144516f7f488225a46de3166050257f79ae04d | Ruby | apoc64/know_me | /lib/router.rb | UTF-8 | 4,340 | 3 | 3 | [] | no_license | require 'pry'
require_relative 'file_io'
require_relative 'game'
class Router
attr_reader :should_continue
def initialize
@hello_counter = -1
@total_counter = 0
@should_continue = true
@response_code = 200
@game = nil
@req = nil
@cm = nil
end
def response(request)
@total_count... | true |
e7cc9d8d3358ec22b87f23220989e3e68dec0712 | Ruby | clees227/rubypractice | /ProjectEuler/digit5thpowers.rb | UTF-8 | 437 | 3.328125 | 3 | [] | no_license | #Problem 30
startTime = Time.now
total = 0
totNums = 0
nums = []
#Honestly, the bounds were guess and check
(2...300000).to_a.each do |num|
sum = 0
num.to_s.each_char {|c| sum += (c.to_i ** 5)}
if sum == num
totNums += 1
nums << num
end
end
nums.each{|i| total += i}
endTime = Time.now
puts "Answer: Total Nums :... | true |
dd05aea52b317a23446dc1f604b00b9bb608bdc7 | Ruby | alexmalus/Codility_code_dojo | /counting_elems/max_counters.rb | UTF-8 | 629 | 3.796875 | 4 | [
"MIT"
] | permissive | # https://app.codility.com/programmers/lessons/4-counting_elements/max_counters/
# array A of M integers
# output: array of integers with value of counters.
# N and M are integers within the range [1..100,000];
# each element of array A is an integer within the range [1..N + 1].
def solution(number, arr)
max = 0
c... | true |
73473b4ee10753d67238f49bd532b882b9c96efc | Ruby | dsaenztagarro/interpreter | /lib/interpreter.rb | UTF-8 | 658 | 3.328125 | 3 | [] | no_license | Dir[File.join(".", "lib/**/*.rb")].each do |f|
require f
end
##
# This class translate a block message into a String message
#
# Reader and Translator ared loaded using dependency injection
# Reader translates the block message into a system "control information"
# Translator takes the "control information" to build... | true |
bd5621e5a56d57a89ac8bb3a67a7361f60e90603 | Ruby | aaronsweeneyweb/boris-bikes | /spec/docking_station_spec.rb | UTF-8 | 861 | 2.671875 | 3 | [] | no_license | require 'docking_station'
describe DockingStation do
it { is_expected.to respond_to :release_bike }
docking_station = DockingStation.new
bike = Bike.new
docking_station.docks_bike(bike)
bike1 = docking_station.release_bike
describe bike1 do
it { is_expected.to respond_to :working?}
end
it { is_e... | true |
a0b9e0d12c6706da68f1df86b2448f4cd26e7f81 | Ruby | acquia/sf-sdk-ruby | /lib/sfrest/site_update_priority.rb | UTF-8 | 1,190 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module SFRest
# We need to keep this naming due to the way connection.rb autoloads things.
# rubocop: disable Naming/ClassAndModuleCamelCase
# Manage the site update priority feature.
class Site_update_priority
# rubocop: enable Naming/ClassAndModuleCamelCase
# @param [SF... | true |
f902b4af7cb10f517ffc892bdf471bc42b1a8d5f | Ruby | mogest/prawn-svg | /lib/prawn/svg/gradients.rb | UTF-8 | 1,142 | 2.59375 | 3 | [
"MIT"
] | permissive | module Prawn::SVG
class Gradients
def initialize(document)
@document = document
@gradients_by_id = {}
end
def [](id)
id &&= id.strip
return unless id && id != ''
if element = @gradients_by_id[id]
element
elsif raw_element = find_raw_gradient_element_by_id(id)
... | true |
c1ba23ccc3bb910ee4289eb27e3f05d7ed22296f | Ruby | team-umlaut/umlaut | /app/controllers/umlaut_configurable.rb | UTF-8 | 16,283 | 2.625 | 3 | [
"MIT"
] | permissive | # meant to be included in _controllers_, to get an
# umlaut_config method as a class_attribute (avail on class, overrideable
# on instance), exposed as helper method too,
# that has a Confstruct configuration object that starts out
# holding global config. (right now via a direct refernce to the global
# one).
requi... | true |
0209f3fa1567a411caad586b4f3ebf3ddd66bcf0 | Ruby | Tkam13/atcoder-problems | /abc122/c.rb | UTF-8 | 326 | 2.9375 | 3 | [] | no_license | n,q = gets.chomp.split.map(&:to_i)
s = gets.chomp
qs = q.times.map{gets.chomp.split.map(&:to_i)}
array = Array.new(s.size,0)
count = 0
1.upto(s.size-1) do |i|
if s[i-1..i] == "AC"
count += 1
array[i] = count
else
array[i] = count
end
end
qs.each do |l,r|
puts array[r-1] - array[l-1]
... | true |
66dfa6518aeda6622745e059ee7a5262302c173f | Ruby | marcelobarbosaO/avaliacao_desenvolvedor | /spec/models/sale_spec.rb | UTF-8 | 2,343 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
describe Sale do
describe '#save' do
before do
@customer = Customer.create!(customer_params)
@address = Address.create!(address_params)
@vendor = Vendor.create!(vendor_params)
@sale = Sale.new(sale_params.merge({
customer: @customer, address: @address, vend... | true |
3c6f9bc38c9a78e8e9d1c62aa5142fdf525b69d7 | Ruby | blakewright1/learn-ruby | /Quizgame/question.rb | UTF-8 | 648 | 4.03125 | 4 | [] | no_license | class Question
#initializer run upon creation of a new Question
def initialize(s, a, b, c, d, correct)
@sentence = s
@option1 = a
@option2 = b
@option3 = c
@option4 = d
@correct_answer = correct
end
def display_question
puts @sentence
puts "1: " + @option1
puts "2: " + @opti... | true |
2d7329670ac5286b8625d6f3eb3c2f04c18db129 | Ruby | sammarten/prag_studio_blocks_course | /enumerable/flyer.rb | UTF-8 | 1,588 | 3.546875 | 4 | [] | no_license | class Flyer
attr_reader :name, :email, :miles_flown
attr_accessor :status
def initialize(name, email, miles_flown, status=:bronze)
@name = name
@email = email
@miles_flown = miles_flown
@status = status
end
def to_s
"#{name} (#{email}): #{miles_flown} - #{status}"
end
end
flyers = []
... | true |
2e3429f967f533e6ba3fc9c60ed1aa0fb753e2ee | Ruby | tmaher/corefoundation | /spec/extensions_spec.rb | UTF-8 | 3,018 | 2.859375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # -*- coding: utf-8 -*-
require 'spec_helper'
describe 'extensions' do
context 'with an integer' do
it 'should return a cfnumber' do
1.to_cf.should be_a(CF::Number)
end
end
context 'with a float' do
it 'should return a cfnumber' do
(1.0).to_cf.should be_a(CF::Number)
end
end
con... | true |
ab3a33f3dfaab73bf42adfa2077c936a14c9f6a8 | Ruby | walterdavis/kno-ruby | /lib/kno.rb | UTF-8 | 2,393 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | require 'erb'
require 'faraday'
module Kno
class Helpers
def initialize(persona_id, config)
@persona_id = persona_id
@config = config
@template = """
<% if @persona_id %>
<form action=\"/session/terminate\" method=\"post\">
<button type=\"submit\">Sign out</button>
</for... | true |
f143718ce78652b9d90346b73c12f992ba3885ca | Ruby | alanyeh20001/leetcode_ruby | /palindrome_number.rb | UTF-8 | 545 | 4.09375 | 4 | [] | no_license | =begin
Determine whether an integer is a palindrome. Do this without extra space.
=end
# @param {Integer} x
# @return {Boolean}
# 只 loop integer 長度的一半,依序比對第一&最後,第二&倒數第二...,如果有不相等的就直接 return false。
def is_palindrome(x)
return false if x < 0
chars = x.to_s.chars
length = chars.length
result = true
for i in ... | true |
b79eac8272f222dbd6ec98e710e138d62ef94185 | Ruby | ttilberg/sequel | /lib/sequel/plugins/skip_saving_columns.rb | UTF-8 | 3,654 | 2.8125 | 3 | [
"MIT"
] | permissive | # frozen-string-literal: true
module Sequel
module Plugins
# The skip_saving_columms plugin allows skipping specific columns when
# saving. By default, it skips columns that the database schema
# indicates are generated columns:
#
# # Assume id column, name column, and id2 generated column
... | true |
c2a45be467ea6fe37cb3802ebae58ab4d97af340 | Ruby | davidrb/config | /status/rss | UTF-8 | 421 | 2.625 | 3 | [] | no_license | #!/bin/env ruby
require_relative 'color'
require 'rss'
require 'open-uri'
# arch rss
begin
open('https://www.archlinux.org/feeds/news/') do |rss|
feed = RSS::Parser.parse(rss)
item = feed.items.first
elapsed = ((Time.now - item.date)/60/60/24).to_i
puts green("Arch News: #{feed.items.fir... | true |
0879f1829ea78484b9e64131ff677e7f7c715397 | Ruby | dbalatero/queue_stick | /lib/queue_stick/counter.rb | UTF-8 | 308 | 3.140625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module QueueStick
class Counter
attr_reader :name, :count
def initialize(name, starting_value = 0)
raise ArgumentError,
'Name must not be nil!' if name.nil?
@name = name
@count = starting_value
end
def increment!(by = 1)
@count += by
end
end
end
| true |
5f90514a3104528310863c814a82e110c024a1ad | Ruby | sensu-plugins/sensu-plugins-monit | /bin/check-monit-email.rb | UTF-8 | 3,133 | 2.84375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #! /usr/bin/env ruby
#
# check-monit-email.rb
#
# DESCRIPTION:
# what is this thing supposed to do, monitor? How do alerts or
# alarms work?
#
# OUTPUT:
# plain text, metric data, etc
#
# PLATFORMS:
# Linux, Windows, BSD, Solaris, etc
#
# DEPENDENCIES:
# gem: sensu-plugin
# gem: mail
#
# USAGE:
# examp... | true |
8b96587ddbe7ec311e7344a2406fb9bc1154402d | Ruby | popsun007/Algorithms_and_Data_Structure | /power_of_three.rb | UTF-8 | 461 | 3.8125 | 4 | [] | no_license | # @param {Integer} n
# @return {Boolean}
def is_power_of_three(n)
if n < 1
return false
end
for i in 0...n
if 3 ** i === n
return true
elsif 3 ** i > n
break
end
end
return false
end
#Math O(1):
def is_power_of_three(n)
test_num = Math.log10(n) / Math.log10(3)
puts test_nu... | true |
d9634b88fc37c9368833b7f02b152efe1ce7dd09 | Ruby | mohammadaliawan/ls-prep | /ruby_basics_3rd/debugging/reading_error_msgs.rb | UTF-8 | 217 | 3.828125 | 4 | [] | no_license | def find_first_nonzero_among(numbers)
numbers.each do |n|
return n if n.nonzero?
end
end
# Examples
p find_first_nonzero_among([0, 0, 1, 0, 2, 0]) # ArgumentError
p find_first_nonzero_among(1)# NoMethodError | true |
002ca897e28bc03c32fe24fcbc8c52d3fee16518 | Ruby | alexreisner/smart_chart | /lib/smart_chart/charts/pie.rb | UTF-8 | 706 | 2.84375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module SmartChart
class Pie < SingleDataSetChart
# number of degrees to rotate start of first slice from 12 o'clock
attr_accessor :rotate
private # ---------------------------------------------------------------
##
# Specify the Google Chart type.
#
def type
case st... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.