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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ded54bc908b9df817a4068e9ba0e04830ac4214e | Ruby | ceciwang/sevenWeeks | /ruby/random.rb | UTF-8 | 175 | 3.671875 | 4 | [] | no_license | puts "Let's guess the random number:"
random = rand(10)
guess = gets().to_i
puts "bigger" if guess > random
puts "smaller" if guess < random
puts "success" if guess == random | true |
7d572cb90a914661ff2cd5563a6f98b89d79a04f | Ruby | csphere/ruby-tricks | /fetch_data.rb | UTF-8 | 131 | 2.609375 | 3 | [] | no_license | params = {var: 42}
p params.fetch(:var)
p params.fetch(:missing, 42)
p params.fetch(:missing) { 40 + 2 }
params.fetch(:missing)
| true |
70131d4fac76e08f1849115307d36e3d5bae5b4b | Ruby | cheshire137/kappa | /lib/kappa/team.rb | UTF-8 | 3,987 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'cgi'
require 'time'
module Twitch::V2
# Teams are an organization of channels.
# @see Teams#get Teams#get
# @see Teams#all Teams#all
# @see Teams
# @see Channel
class Team
include Twitch::IdEquality
# @private
def initialize(hash)
@id = hash['_id']
@info = hash['info']... | true |
256f2a09b2cf3f54959248bed02c2510bae6fc86 | Ruby | dephillips5262/http-class | /02.0-not-quite-as-simple-server/server.rb | UTF-8 | 400 | 3.078125 | 3 | [] | no_license | require 'socket' # A library built into Ruby - provides the TCPServer class
$stdout.sync = 1 # Line-buffer output to STDOUT.
listener = TCPServer.open(8080)
socket = listener.accept # Wait til a client connects, then open a socket.
puts "FROM THE CLIENT: " + socket.read
socket.puts("Hello, world")
puts "SERVER: Sent... | true |
691d39a91e76dcd19c5d54c1b18ab9d4b8fddb35 | Ruby | janlelis/clipboard_formatter | /lib/clipboard_formatter.rb | UTF-8 | 604 | 2.546875 | 3 | [
"MIT"
] | permissive | require_relative "clipboard_formatter/version"
require 'rspec/core/formatters'
require 'clipboard'
class ClipboardFormatter
RSpec::Core::Formatters.register self, :dump_summary
def initialize(*)
end
def dump_summary(notification)
if notification.failed_examples.present?
locations = Hash.new{ |h,k|... | true |
99022b361344f113fd86a4156e9b1e1ce9677b90 | Ruby | matao0214/Demo | /1227.rb | UTF-8 | 256 | 3.015625 | 3 | [] | no_license | def kids_with_candies(candies, extra_candies)
# highest_candy = candies.max
# candies.map do |candy|
# candy + extra_candies >= highest_candy
# end
max = candies.max
candies.map do |candy|
candy + extra_candies >= max
end
end
| true |
43251945f9ea715e70985e140851a43dea6b4dcd | Ruby | brandonhilkert/awesome_print | /spec/awesome_print_spec.rb | UTF-8 | 6,477 | 2.921875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "AwesomePrint" do
describe "Array" do
before(:each) do
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
end
it "empty array" do
[].ai.should == "[]"
end
it "plain multiline" do
@arr.ai(:plain => tr... | true |
b3b51e42a8b99583f903a537e19c8fda18e2ff82 | Ruby | 1powechri2/Near-Earth-Objects | /app/models/near_earth_object.rb | UTF-8 | 616 | 2.78125 | 3 | [] | no_license | class NearEarthObject
attr_reader :name, :magnitude, :diameter, :date,
:speed, :miss_distance, :hazard, :sentry_object
def initialize(data)
@name = data[:name]
@magnitude = data[:absolute_magnitude_h]
@diameter = data[:estimated_diameter][:miles]
@date = data[:close_approach_data].fir... | true |
59279d2ab0c0a6b87b3a6c0a17fb569a7d934a2a | Ruby | katheroine/languagium | /ruby/control_flow/while_loop/while_loop_statement_modifier.rb | UTF-8 | 58 | 2.671875 | 3 | [] | no_license | #!/usr/bin/ruby
i = -1
puts("#{i += 1}...") while i < 9
| true |
d01874ff590a2d356ab0141983a1a9bae2191ef1 | Ruby | sammilechman/reddit-clone | /app/models/user.rb | UTF-8 | 1,146 | 2.546875 | 3 | [] | no_license | # == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# username :string(255) not null
# password_digest :string(255) not null
# session_token :string(255)
# created_at :datetime
# updated_at :datetime
#
class User < ActiveRecord::B... | true |
0eb196cbcaaa4e82f7843be8a160016a38604b69 | Ruby | g13013/js_module_transpiler | /lib/js_module_transpiler/amd_compiler.rb | UTF-8 | 1,702 | 2.546875 | 3 | [
"MIT"
] | permissive | require "js_module_transpiler/abstract_compiler"
module JsModuleTranspiler
class AMDCompiler < AbstractCompiler
def stringify
arguments, preamble = build_preamble(dependency_names)
unless @exports.empty?
dependency_names << "exports"
arguments << "__exports__"
end
output... | true |
36731642f7443b83e864d9b47360a26389559c84 | Ruby | a2ikm/ruby-sandbox | /fiber/fiber.rb | UTF-8 | 281 | 3.3125 | 3 | [] | no_license | #!/usr/bin/env ruby
@fibers = {}
def create_fiber
Fiber.new do
puts Fiber.yield
sleep 3
puts Fiber.yield
end
end
fibers = []
fibers << create_fiber
fibers << create_fiber
puts "begin"
fibers.each(&:resume)
puts "end"
fibers.each { |f| f.resume 1; f.resume 2 }
| true |
7e90b7ca22ad38e085772c265581a6ddaa7f7329 | Ruby | SuzanneHuldt/GR-tech-test | /spec/gildedrose_spec.rb | UTF-8 | 953 | 2.953125 | 3 | [] | no_license | require './lib/gilded_rose.rb'
require './lib/item.rb'
describe GildedRose do
let(:items) {[Item.new('Backstage passes to a TAFKAL80ETC concert', 5, 5),
Item.new('Aged Brie', 5, 3), Item.new('Sulfuras, Hand of Ragnaro', 5, 5), Item.new('Conjured', 5, 5), Item.new('duck', 5, 5)]
}
let(:gilded_rose) {Gilde... | true |
167fb0b4ff4d6f322f8f16284f68c6f0c4235a54 | Ruby | nikkiHelloThp/rails_basic_app | /test/models/relationship_test.rb | UTF-8 | 812 | 2.515625 | 3 | [] | no_license | require 'test_helper'
class RelationshipTest < ActiveSupport::TestCase
def setup
@relationship = Relationship.new(follower_id: authors(:one).id,
followed_id: authors(:two).id)
end
test "should be valid" do
assert @relationship.valid?
end
test "should require a follower_id" do
@relatio... | true |
f5bf9ab6a9cd00abad9bf7bd20fed6f0e1f14082 | Ruby | giffin94/ruby-math-game | /game.rb | UTF-8 | 1,474 | 3.984375 | 4 | [] | no_license | class Game
attr_accessor :current_player
attr_reader :turn
def initialize()
print "Welcome! If you're here to pit your mathematical chops against your friend, enter a name for Player 1: "
@player_1 = Player.new(gets.chomp)
print "Player 2: "
@player_2 = Player.new(gets.chomp)
# @player_1 = p... | true |
98f92de285ea9a0afd84e02e7a1a0d68b708dcb2 | Ruby | EdmundMai/stop_limit | /spec/bank_account_spec.rb | UTF-8 | 1,559 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe BankAccount do
subject { BankAccount.new(balance: 2000) }
it { should respond_to(:balance) }
it "has a default file path" do
BankAccount::RECORDS.should eq(File.basename(Dir.getwd))
end
describe "#initialize" do
it "sets the balance" do
bank_account = BankAccount.new(bala... | true |
414f13e7958f341395646f18ed08498b900ec6f3 | Ruby | philippt/rhcp | /test/rhcp/request_test.rb | UTF-8 | 5,287 | 2.65625 | 3 | [] | no_license | $:.unshift File.join(File.dirname(__FILE__),'..','..','lib')
require 'test/unit'
require 'rhcp'
require 'rubygems'
require 'json'
class RequestTest < Test::Unit::TestCase
def test_construction
command = RHCP::Command.new("test", "a test", nil)
assert_raise(RHCP::RhcpException) { RHCP::Request.new(nil, Has... | true |
69b428555e982b9700322730c716b55af7b6b999 | Ruby | jgeorgex/bonus | /lib/bonus.rb | UTF-8 | 111 | 3.28125 | 3 | [] | no_license | def bonus(salary, bonus)
if bonus == true
"$#{salary*10}"
else
"$#{salary}"
end
end | true |
6c635ab5fb234a91dc0186eae89c3a764136e693 | Ruby | fortuneonyeka/Tic_tac_toe | /spec/game_logic_spec.rb | UTF-8 | 1,782 | 3.25 | 3 | [
"MIT"
] | permissive | require './lib/game_logic'
describe Board do
let(:play) { Board.new }
describe '#display_board' do
it 'should display number from 1-9' do
expect(play.display_board).to eql(
" 1 | 2 | 3 \n" \
"------------\n" \
" 4 | 5 | 6 \n" \
"------------\n" \
" 7 | 8 | 9 \n"
... | true |
dc0c0de0773f9a9ac19c33bccfa76f4b02a36d04 | Ruby | skroll/puppet-networking | /lib/puppet/parser/functions/iprandchoice.rb | UTF-8 | 453 | 2.796875 | 3 | [] | no_license | # iprandchoice(VALUE...)
#
# Choose pseudo-randomly between arguments, based on hash of ipaddress fact.
#
# e.g.,
# iprandchoice(192.168.6.1, 192.168.6.2) -> 192.168.6.1 or 192.168.6.2
require 'ipaddr'
require 'digest/md5'
Puppet::Parser::Functions.newfunction(:iprandchoice, :type => :rvalue) do |args|
hash = Di... | true |
fbd09e2753eb5cacdee7f304a81821f9898d751c | Ruby | nog/atcoder | /contests/abc183/b/main.rb | UTF-8 | 77 | 2.875 | 3 | [] | no_license | SX, SY, GX, GY = gets.split.map(&:to_f)
puts SX + SY * (GX - SX) / (SY + GY) | true |
23efc576ad213a81a94d6dbb05c4f0510f6868ca | Ruby | placeit-envato/lunetas | /lib/lunetas/bag.rb | UTF-8 | 2,210 | 2.984375 | 3 | [
"MIT"
] | permissive | # This is the module that keeps the register of all the Lunetas. It will add the
# classes to a register, and whenever rack receives a call, it delegates it.
# If Lunetas is not run as a stand alone rack application, then this module
# lacks of responsability, ie. Running as a Rails Metal.
module Lunetas::Bag
# Regi... | true |
24e594341ab5674382aa8bb5fe3839b0e9681481 | Ruby | tetetratra/contest | /abc153/e/e.rb | UTF-8 | 830 | 3.296875 | 3 | [] | no_license | require 'pp'
# 4 100 139815
H, N = gets.split.map(&:to_i)
# p [H, N]
a = [] # 減らせる体力
b = [] # 使う魔力
N.times do
a_, b_ = gets.split.map(&:to_i)
a << a_
b << b_
end
ab = a.zip(b)
ab.sort_by!{|(aa,bb)|aa}
a = ab.map{|x|x[0]}
b = ab.map{|x|x[1]}
# p a
# p b
dp = Array.new(N){ Array.new(H+1, 0) } # nまでの技でhp:hの敵を倒すのにか... | true |
4f9aab01029a3c89068ced33ecc5869bcc2099ea | Ruby | cvoulgaris/ruby0 | /challenge_week3.rb | UTF-8 | 1,144 | 4.1875 | 4 | [] | no_license | class Square
attr_accessor :color, :side
def initialize (side, color=:red)
@color = color
@side = side
end
def area
@area = @side * @side
end
def can_fit(value)
return self.area/value.area
end
def can_fit?(value)
self.area/value.area >= 1 ? true : false
end
end
class Circle < Square
... | true |
3b34b2266b2c4795d07a05bb972e5176e092cd05 | Ruby | fanjieqi/LeetCodeRuby | /1401-1500/1403. Minimum Subsequence in Non-Increasing Order.rb | UTF-8 | 249 | 3.21875 | 3 | [
"MIT"
] | permissive | # @param {Integer[]} nums
# @return {Integer[]}
def min_subsequence(nums)
nums.sort!
n, sum = nums.size, [0]
nums.each_with_index { |num, i| sum[i+1] = sum[i] + num }
i = n
i -= 1 while sum[i] >= sum[n] - sum[i]
nums[i..n-1].reverse
end
| true |
5e26353b4422b36f8932fb8885ae52e8e4fe4c14 | Ruby | pdg137/tsumego | /spec/board_spec.rb | UTF-8 | 1,768 | 3.03125 | 3 | [] | no_license | require_relative '../lib/board.rb'
describe Board do
let(:board) { Board.parse(next_player, board_string) }
let(:next_player) { Board::Black }
context 'very simple fight' do
let(:board_string) { 'x o' }
context 'black next' do
it 'kills black' do
board.remove_captures!
expect(boar... | true |
9ebdfbceb02496e6e90fed246adbe94cd87ac655 | Ruby | mvidner/adventofcode | /2022/13/ruby/solution.rb | UTF-8 | 1,471 | 3.40625 | 3 | [] | no_license | #!/usr/bin/env ruby
class Packet
include Comparable
attr_reader :value
def self.parse(s)
val = eval(s)
new(val)
end
def initialize(val)
@value = val
end
def <=>(other)
a, b = @value, other.value
# puts "<=> #{a.inspect} #{b.inspect}"
cmp2(a, b)
end
def cmp2(a, b)
# pu... | true |
abf61ab5ddf6a60312cf2188a7fb5deb0a4a2c16 | Ruby | akavi/Macaronic | /do_block.rb | UTF-8 | 1,383 | 2.9375 | 3 | [] | no_license | require './macaronic.rb'
class Array
def and_then(&block)
self.flat_map do |a|
block.call(a)
end
end
def within(&block)
and_then do |value|
[block.call(value)]
end
end
end
def do_block(&block)
Macaronic.on(block){ |f| do_blockify(f) }.call
end
def do_blockify(frame)
# find li... | true |
7a088058328fb6a72e8381f42196263f11d1e116 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/3946.rb | UTF-8 | 904 | 3.59375 | 4 | [] | no_license | #!/usr/bin/ruby
def combine_anagrams(words)
ordered = Array.new(words)
anagramArray = Array.new
anagramMap = Hash.new
words.each_index do |x|
ordered[x] = words[x].downcase.unpack("c*").sort.pack("c*")
#puts ordered[x]
#puts words[x]
end
ordered.each_index do |x|
orderedLetters = orde... | true |
93206653a4959b9262f0afec23b1aef0b4fc48f7 | Ruby | timbo815/algorithms-practice | /data_structures/heap.rb | UTF-8 | 2,008 | 3.71875 | 4 | [] | no_license | class BinaryMinHeap
def initialize(&prc)
@store = []
end
def count
store.length
end
def extract
raise "no element to extract" if count == 0
if count > 1
extracted = store[0]
store[0] = store.pop
BinaryMinHeap.heapify_down(store, 0, store.length)
extracted
else
... | true |
5552fd27e1de7128a5fbf95f6b7d4b7d9622b926 | Ruby | jauricchio/zfra | /todaysshow.rb | UTF-8 | 761 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'erb'
require 'episodeexists'
require 'showdate'
require 'showdescription'
require 'bettershowurl'
class Show
def initialize(today)
d = show_date(today)
if(!episode_exists(d)) then
raise
end
@title = "The Show for #{d.strftime('%A, %b %e')}"
@summary = show_de... | true |
4cc8c522a667620c2bfc29e4c2f90c931c62442a | Ruby | IceDragon200/rgss_tk | /lib/rgss_tk/db/seed/dsl.rb | UTF-8 | 1,987 | 2.71875 | 3 | [] | no_license | require "rgss_tk/db/database"
require "rgss_tk/make_effect"
require "rgss_tk/make_feature"
require "rgss_tk/const"
module RgssTk
class Database
module DSL
def damage_type(sym = nil)
case sym
when :none then 0
when :hp_damage, :hpd then 1
when :mp_damage, :mp... | true |
55f26df9cffb9b4a59c24f43a2d74626fcb077d5 | Ruby | jvans1/swaptrack | /db/seeds.rb | UTF-8 | 2,331 | 2.53125 | 3 | [] | no_license | u1 = User.create(:name=>"James", :email=>"james@james.com", :password=>"poker")
u2 = User.create(:name=>"Dani", :email=>"dani@dani.com",:password=>"poker")
t = Tournament.create(:name=>"Main Event", :buy_in=>10000, :date=> DateTime.new(2012,12, 4))
t1 = Tournament.create(:name=>"5k 6max", :buy_in=>5000, :date=> DateT... | true |
99fab34aff66092ba2fdf9c72668528a58e291f9 | Ruby | samsohn28/advent_of_code | /2022/day9/part2.rb | UTF-8 | 1,153 | 3.40625 | 3 | [] | no_license | # frozen_string_literal: true
# frozen_string_literal: true
require 'byebug'
instructions = File.read('input.txt').split("\n").map { |instruction| instruction.split(' ') }
@knots = []
10.times do
@knots << [0, 0]
end
@visited = Hash.new(0)
def process_steps(direction, steps)
steps.times do
previous_knot = ... | true |
b650f15cd3fcf39ee37b4d16d8ebe41b2030a558 | Ruby | theodi/rummager | /bin/search | UTF-8 | 2,821 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-proprietary-license"
] | permissive | #!/usr/bin/env ruby
require "logging"
PROJECT_ROOT = File.dirname(__FILE__) + "/../"
DATA_DIR = PROJECT_ROOT + "data/"
File.join(PROJECT_ROOT, "lib").tap do |path|
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
end
require "search_config"
require "optparse"
options = {index_name: "government"}
OptionP... | true |
7fe31792d1b041724d23f9150a85ea9e7e4a673e | Ruby | Kite0301/atcoder | /Regular/042/a.rb | UTF-8 | 189 | 2.96875 | 3 | [] | no_license | n,m = gets.chomp.split.map(&:to_i)
arr = Array.new(m)
brr = Array.new(n) { |i| i+1 }
for i in 0..m-1 do
arr[i] = gets.chomp.to_i
end
arr.reverse!.uniq!
ans = arr + brr
ans.uniq!
puts ans | true |
6cc31b5c9cfc66635b5593a27a67fffc6c20f66e | Ruby | g4uk/BookStore | /app/services/new_order_item_service.rb | UTF-8 | 990 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
class NewOrderItemService < Rectify::Command
DEFAULT_QUANTITY = 1
def initialize(book_id:, quantity: DEFAULT_QUANTITY, cart:)
@book = Book.find(book_id)
@quantity = quantity
@cart = cart
@current_item = cart.order_items.find_by(book_id: book_id)
end
def call
... | true |
17264991abd0386de2a01271e6bb6a348b426aa0 | Ruby | chad/rubinius | /kernel/bootstrap/hash.rb | UTF-8 | 1,662 | 2.96875 | 3 | [] | no_license | # Requires: Object#hash
class Hash
ivar_as_index :__ivars__ => 0, :keys => 1, :values => 2, :bins => 3, :entries => 4, :default => 5, :default_proc => 6
def self.allocate
Ruby.primitive :allocate_hash
raise PrimitiveFailure, "Hash.allocate primitive failed"
end
def self.[](*args)
hsh = new()
... | true |
d41eaf4e8549928b6c3e171aa927be8c8b3bd170 | Ruby | no1fushi/procon | /2015/look_item.rb | UTF-8 | 10,056 | 3.03125 | 3 | [] | no_license | =begin
-*- coding: utf-8 -*-
仕様
2014の
・敵にブロックを置く #char
・ブロックを避ける(方向ランダム) #block
・アイテムを取りに行く(ランダム) # item
・アイテム,キャラ斜め判断,(横優先,ランダム) #item,char slanting
・go初期ランダム
・ループを避ける=ランダム
・ターンカウント
・敵,アイテム保存 #char,item save
・敵次ターンよける #char flee
・一定ターンアイテムがなかったらlookで多い方(実装予定)
=end
require 'CHaserConnect.rb' # CHaserConnect.rbを読み込む ... | true |
e3ccc0698121d469046d5cea06f492c3a6af31c7 | Ruby | dalyw01/Ruby | /arrays.rb | UTF-8 | 630 | 4.625 | 5 | [] | no_license | puts "#################### Arrays ####################"
array1 = [ "derp" , 6 , 1.0 , nil ]
puts array1
puts array1[1]
puts "#################### Arrays 2.0 ####################"
array1.each do | number |
puts "This is me printing the Ruby way: #{number}"
end
puts "#################### Arrays Push/Pop ##########... | true |
473f2cd95f509ad5337e5566eeb94d447964a3b4 | Ruby | marcwright/WDI_ATL_1_Instructors | /REPO - DC - Students/w02/d01/Alexi/03_shelter/main.rb | UTF-8 | 1,927 | 3.546875 | 4 | [] | no_license | require 'pry'
require_relative './Client'
require_relative './Shelter'
require_relative './Animals'
require_relative './Seeds'
# Birth of shelter --> instnace
shelter = Shelter.new("HappiTails")
animal_1 = Animals.new("BooRay", "dog")
animal_2 = Animals.new("Spot", "dog")
animal_3 = Animals.new("Dan", "cat")
shelte... | true |
0adab51bdabaa9af7fb9e7bebc7ca4d9a8055664 | Ruby | opuslogica/oli_comments | /app/models/comment.rb | UTF-8 | 1,497 | 2.609375 | 3 | [
"MIT"
] | permissive | class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
belongs_to :member
has_many :comment_markers, dependent: :destroy
validates_presence_of :body, :member
scope :find_comments_by_member, -> (member){where(:member_id => member.id).order('created_at DESC')}
scope :find_comments_... | true |
fc172b975216ff46a92947f513b7d6b8c333e7a9 | Ruby | boshnessy/Example_Exercises | /object_oriented_ruby/store_item.rb | UTF-8 | 815 | 4.09375 | 4 | [] | no_license | skirt1 = {
:pattern => "leopard",
:size => 3,
:price => 12
}
skirt2 = {
:pattern => "cheetah",
:size => 7,
:price => 20
}
skirt3 = {
:pattern => "plaid",
:size => 1,
:price => 5
}
p "The pattern is #{skirt1[:pattern]} and the price is $#{skirt1[:price]}."
class Skirt
attr_reader :pattern, :size... | true |
0c499c197c93cfbee511d6b96f8da4ddb43cec3a | Ruby | zero3smart/eagle-platform | /app/helpers/formatting_helper.rb | UTF-8 | 384 | 2.703125 | 3 | [] | no_license | module FormattingHelper
def f_date(date)
date && date.strftime('%m/%d/%Y').strip
end
def f_time_ago(time)
end
def f_money(amount)
return '' if amount.blank?
amount && "$#{number_with_precision(amount, separator: '.', precision: 2, delimiter: ',')}"
end
def f_phone(number)
"#{number[1]... | true |
c718bab9e7cde93817daaa751d6899c4a63a1f96 | Ruby | ahmedhassanien503/ruby | /lab1.rb | UTF-8 | 1,828 | 3.84375 | 4 | [] | no_license | class ComplexNum
@@countAdd = 0
@@countMult = 0
attr_reader :real, :imag
def initialize(real, imag)
@real = real
@imag = imag
end
def +(num)
@@countAdd+= 1
real = self.real + num.real
imag = self.imag + num.imag
puts "(#{self.real} + #{self.imag}i) + (#{num.real} + ... | true |
869800b831ba1e3a872ac82e81d2a62edb8f8a39 | Ruby | DmytroVasin/Shop | /db/seeds/gender.rb | UTF-8 | 190 | 2.5625 | 3 | [] | no_license | def add_gender
{:'Unisex'=> 'Унисекс', :'Womens' => 'Женское', :'Mens'=> 'Мужское'}.each do |type, rus|
Gender.create({ gender: type, gender_rus: rus })
end
end
| true |
441c2306b9bb016b0ab5137c030e76ac00f09d7a | Ruby | MPalhidai/Algorithms | /exercism/ruby/complete/alphametics/alphametics.rb | UTF-8 | 983 | 3.234375 | 3 | [] | no_license | class Alphametics
def self.solve(puzzle)
output = {}
chars = []
syms = []
sub = []
for i in 0..puzzle.length
if /[A-Z\=]/.match(puzzle[i])
output[puzzle[i]] = 0 if puzzle[i] != '='
sub << puzzle[i]
elsif /[\*\/\+\-]/.match(puzzle[i])
syms << puzzle[i].to_sym
... | true |
9ff349a536ec322d14d50100b0705cfb2a8830f7 | Ruby | cindyvandooren/app_academy_prepwork | /w2/w2d2/lib/12_rpn_calculator.rb | UTF-8 | 5,285 | 3.859375 | 4 | [] | no_license | class RPNCalculator
attr_accessor :stack
def initialize
@stack = []
end
def push(num)
@stack << num
end
def value
@stack[-1]
end
def plus
perform_op(:+)
end
def minus
perform_op(:-)
end
def divide
perform_op(:/)
end
def times
perform_op(:*)
end
def perform_op(symbol)
raise "calcu... | true |
e3e0a16a46b0a8ab3cb74750a38d887c9680b5b3 | Ruby | chelsearostonrappazzo/bach-games | /game.rb | UTF-8 | 2,099 | 3.328125 | 3 | [] | no_license | # frozen_string_literal: true
require "tty-prompt"
@prompt = TTY::Prompt.new
# file = "male_celebs.txt"
# file_two = "sara.txt"
# 20 total names
@all_names = []
@celeb_names = []
@filler_names = []
@mundane_names = []
@tops = []
@bottoms = []
@ind, @var = 0, 1
# File.readlines(file).each do |line|
# @celeb_names <<... | true |
3e67645d1c2dab71a0189476b61cb9ffcefbb09b | Ruby | henriquetatagiba/aps-topicos-especiais-ii | /Exercicio_02.rb | UTF-8 | 597 | 3.328125 | 3 | [] | no_license | print 'Digite o tipo de servio (Projeto ou Auditoria): '
resposta = gets.chomp.to_s.capitalize
print 'Número de dias trabalhados: '
dias_trabalhados = gets.chomp.to_i
print 'Número de viagens realizadas: '
viagens_realizadas = gets.chomp.to_i
if resposta.eql?('Projeto')
trabalho = 200
viagem = 1000
total = (di... | true |
03a7abd6905cbfcefad25239e1a6e19e008cf5b4 | Ruby | LessEverything/less_values | /test/less_values_test.rb | UTF-8 | 2,665 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class Person < Less::Value
attribute :first_name, String
attribute :last_name, String
attribute :single, Less::Bool
attribute :age, Integer
end
class AgelessPerson < Less::Value
attribute :first_name, String
attribute :last_name, String
attribute :single, Less::Bool
attribute :ag... | true |
0e02d1b5b75e3e25b4367bee12dd91cd9e9b94af | Ruby | mubarik/OMSAD | /development/test/unit/course_test.rb | UTF-8 | 3,994 | 2.6875 | 3 | [] | no_license | require 'test_helper'
class CourseTest < ActiveSupport::TestCase
fixtures :courses
# test "the truth" do
# assert true
# end
# called before every single test
def setup
@course = courses(:data1)
end
#course = Course.new(:coursetype =>@course.coursetype,:coursename=>@course.coursename,:coursecod... | true |
5bd803b2b23cfc9713d2763af90a8ac85f9b8303 | Ruby | autolab/Autolab | /app/models/annotation.rb | UTF-8 | 3,118 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | ##
# Annotations are Submission and Problem specific.
# Currently, they are just text, but it would be nice if they could be used in
# score calculations in the future.
#
class Annotation < ApplicationRecord
belongs_to :submission
belongs_to :problem
validates :comment, :value, :filename, :submission_id, :proble... | true |
5dda3b70513b7912fb45d643fd69ec4cb34c0021 | Ruby | s4nchez/card_games | /server/src/game_state.rb | UTF-8 | 5,525 | 2.84375 | 3 | [] | no_license | module CardGames
require 'logger'
require 'securerandom'
class GameState
attr_reader :groups, :players
def initialize(initial_cards = ["AS", "AC", "AD", "AH", "KS", "KC", "KD", "KH", "QS", "QC", "QD", "QH", "JS", "JC", "JD", "JH"],
initial_position = [10,10], hidden_card = "back", ow... | true |
4297cc2bc47e0c8154e1671ce553c922ca4ba207 | Ruby | jadedandroid/ttt-game-status-bootcamp-prep-000 | /lib/game_status.rb | UTF-8 | 1,493 | 3.53125 | 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],#top_row
[3,4,5],#middle_row
[6,7,8],#bottomrow
[0,3,6],# left_column
[1,4,7],#middle_column
[2,5,8],# right_column
[0,4,8],# di... | true |
76e176f110a63ab7f3b1abd5e7bac3d134db54d6 | Ruby | watchjazcode/oo-basics-online-web-sp-000 | /lib/book.rb | UTF-8 | 842 | 4.125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Book
#using accessor and reader simplifies our code
#attr_accessor :author, :page_count, :genre
#attr_reader : title
#can only set title once, not allowed to modify it afterwards
#turn_page is not an attribute, but a behavior..so not included
def initialize(title) #corresponds with .new takes wha... | true |
15b6978560a2080f84f147d3789ef2e0f256bfd9 | Ruby | mollybrown/Night-Writer-Project | /test/night_read_test.rb | UTF-8 | 604 | 2.78125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/night_read.rb'
class NightReadTest < Minitest::Test
def test_it_exists
assert NightReadTest
end
def test_it_reads_a_file_and_stores_contents
file = NightWriter.new("braille.txt", "r")
contents = file.read
assert contents != nil... | true |
b81da4b60084b7c9bf8f9417c14cdf3d7a375d18 | Ruby | markben77/tip_calc | /tip_calculator1.rb | UTF-8 | 438 | 3.546875 | 4 | [] | no_license |
meal = 20.0
tax = 9.0
tip = 20.0
tax_value = meal * (tax/100)
meal_with_tax = meal + tax_value
tip_value = (tip/100) * meal_with_tax
total_cost = meal_with_tax + tip_value
print "The pre-tax cost of your meal was $%.2f.\n" % meal
print "At %d%%, tax for this meal is $%.2f.\n" % [tax, tax_value]
print "For a %d%% tip... | true |
e08445bcb3dc5702438c82dfd35dec06de786ad5 | Ruby | wieczorek1990/tartak | /simulator.rb | UTF-8 | 1,129 | 3.25 | 3 | [] | no_license | require_relative 'event'
require_relative 'input_magazine'
require_relative 'scheduler_event'
require_relative 'transport_event'
class Simulator
def initialize(events, duration)
unless events.is_a?(Array)
event = events
events = [event]
end
for event in events
raise 'WRONG TYPE' unless ... | true |
667897a8c9595aacf0e88ac8533956ad9a1bb113 | Ruby | fnordfish/sinatra-swagger-exposer | /lib/sinatra/swagger-exposer/processing/swagger-request-preprocessor.rb | UTF-8 | 2,035 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'json'
require_relative '../swagger-invalid-exception'
module Sinatra
module SwaggerExposer
module Processing
# A preprocessor for a request, apply the parameters preprocessors then execute the query code
class SwaggerRequestPreprocessor
attr_reader :preprocessors_dispatchers
... | true |
ba68b778553f2514cd746c9752c5364f1ecfc8a8 | Ruby | google-code/bigvan | /elp/app/models/trace.rb | UTF-8 | 250 | 2.859375 | 3 | [] | no_license | class Trace
#this is a session class
attr_accessor :trace
@@MAX_LEN=10
def initialize()
@trace=[]
end
def add(url)
@trace<<url
if @trace.length()>@@MAX_LEN
@trace.slice!(0,@trace.length()-@@MAX_LEN)
end
end
end
| true |
e97d7cb0eb7f176c734864c47946180b81a47895 | Ruby | hoo89/busitu_now | /lib/twitter_bot.rb | UTF-8 | 520 | 2.796875 | 3 | [] | no_license | require 'twitter'
class TwitterBot
def initialize
@bot = Twitter::Client.new(
:consumer_key => $TWITTER_CONSUMER_KEY,
:consumer_secret => $TWITTER_CONSUMER_SECRET,
:oauth_token => $TWITTER_KEY,
:oauth_token_secret => $TWITTER_SECRET
)
end
#Post message to somewhere
#post("pos... | true |
2535afb991e3432a2cf504b142b9d44bb0ae365c | Ruby | singflan/Intro_Prog_Ruby_LS | /The_Basics/ex5.rb | UTF-8 | 181 | 3.140625 | 3 | [] | no_license | factorial_5 = 5*4*3*2*1
puts factorial_5
factorial_6 = 6 * factorial_5
puts factorial_6
factorial_7 = 7 * factorial_6
puts factorial_7
factorial_8 = 8 * factorial_7
puts factorial_8 | true |
2637eb785a0709a3c591d824210547555582f493 | Ruby | itspriddle/reamaze_api | /lib/reamaze_api/client.rb | UTF-8 | 4,922 | 2.6875 | 3 | [
"MIT"
] | permissive | require "faraday_middleware"
require "uri"
module ReamazeAPI
class Client
# Raises a ReamazeAPI::Error for any HTTP response code 400-599.
class RaiseErrorMiddleware < Faraday::Response::Middleware
private
# Private: Raises a ReamazeAPI::Error for any HTTP response code
# 400-599.
#
... | true |
d5b567ea3a752d27c1574cf9c19a6c64d13eb71a | Ruby | kirikak2/cfoundry | /lib/cfoundry/trace_helpers.rb | UTF-8 | 1,719 | 2.578125 | 3 | [
"Artistic-1.0-Perl",
"LGPL-2.0-or-later",
"Artistic-2.0",
"MIT",
"GPL-1.0-or-later",
"GPL-2.0-only",
"Apache-2.0",
"Ruby",
"LicenseRef-scancode-other-permissive",
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require "net/https"
require "multi_json"
module CFoundry
module TraceHelpers
PROTECTED_ATTRIBUTES = ['Authorization', 'credentials']
def request_trace(request)
return nil unless request
info = ["REQUEST: #{request[:method]} #{request[:url]}"]
info << "REQUEST_HEADERS:"
info << header... | true |
6a5c488b0ff8e7bc6b84f96d93a210fe708debee | Ruby | cho45/ruby-mh-z19 | /lib/mh-z19/serial.rb | UTF-8 | 2,251 | 2.9375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'serialport'
module MH_Z19
class Serial
STARTING_BYTE = 0xff
CMD_GAS_CONCENTRATION = 0x86
CMD_CALIBRATE_ZERO_POINT = 0x87
CMD_CALIBRATE_SPAN_POINT = 0x88
class GenericException < Exception; end
class InvalidPacketException < GenericException; end
def initialize(io, sensor_... | true |
91380d53e016c14af45760bd1426a19a80c37cdd | Ruby | zerobatu/comparador-unab | /app/validators/email_validator.rb | UTF-8 | 478 | 2.515625 | 3 | [] | no_license | class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.blank?
value.split(',').each do|v|
unless EmailValidator.validate(v)
record.errors[attribute] << (options[:message] || "no es un E-mail")
return
end
end
en... | true |
55d4cb16f705ca2bbce40a25711d1ec24d8d15f3 | Ruby | yousifhj/collections_practice-online-web-ft-100719 | /collections_practice.rb | UTF-8 | 673 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #1
def sort_array_asc(array)
array.sort do |a, b|
a <=> b
end
end
#2
def sort_array_desc(array)
array.sort do |a, b|
b <=> a
end
end
#3
def sort_array_char_count(array)
array.sort { |a, b| a.length <=> b.length }
end
#4
def swap_elements(array)
array[1], array[2] = array[2], array[1]
array
e... | true |
f6afc6ee273897f1138c8385a878f7befc7c633c | Ruby | carlthuringer/Serpukhov-15 | /game.rb | UTF-8 | 19,270 | 3.921875 | 4 | [] | no_license | # The game!
class GameBoard
# Generic 2-d game board.
# ALERT all code here should be agnostic to any rectangular board-based game.
# @board keeps an array of the current state of the board.
#TODO Implement 2-dimensional boards of variable dimension.
attr_reader :board
def initialize(board = [])
# We a... | true |
eaa528a04679f19f1fce8fc6932ab812ef390692 | Ruby | eekedm/bewd_sf_12 | /05_Classes_Objects/starter_code/ex_apartment_objects/lib/person.rb | UTF-8 | 517 | 2.75 | 3 | [] | no_license | #Person Class.
<<<<<<< HEAD
class Person
attr_accessor :name, :budget, :creditscore
=======
class Person
attr_accessor :name, :budget, :credit_score
def initialize (name, budget, c_score)
@name = name
@budget =budget
@credit_score = c_score
end
def to_s
@name
end
>>>>>>> d4d0371fc1b632c18c9608947c60508... | true |
0623609bde04c8d8264ecefd8fcd850a4896baa8 | Ruby | sanjeevs/algs1 | /dfs/node.rb | UTF-8 | 730 | 3.65625 | 4 | [] | no_license | #Node of a graph
class Node
attr_reader :name
attr_accessor :explored
attr_accessor :finish_time
attr_accessor :leader
def initialize(name)
@name = name
@explored = false
@finish_time = -1
end
def ==(other)
if other.instance_of?(Fixnum)
other = Node.new(other)
end
name == ... | true |
19d6b30ff2205f928d2636edaf1afc9d33cb86d5 | Ruby | codercr/gcp-encrypt | /lib/gcp_encrypt.rb | UTF-8 | 3,704 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'yaml'
require_relative 'gcp_encrypt/version'
class GcpEncrypt
class AlreadyInitialized < StandardError; end
class ConfigurationFileNotFound < StandardError; end
class GitNotFound < StandardError; end
CONFIG_FILE = '.gcp-encrypt.yml'
GIT_IGNORE_START = "### GCP ENCRYPT... | true |
d77675dfc2668d8536ddaf8806f4da63c4c78c67 | Ruby | alansparrow/learningruby | /yamlexample.rb | UTF-8 | 252 | 3.140625 | 3 | [] | no_license | require 'yaml'
class Person
attr_accessor :name, :age
end
fred = Person.new
fred.name = "Fred Bloggs"
fred.age = 45
laura = Person.new
laura.name = "Laura Smith"
laura.age = 23
test_data = [ fred, laura]
#puts YAML::dump(test_data)
puts test_data.to_yaml | true |
52da69ef7ae8ab2e47fc14bf327d75b267925663 | Ruby | JiangYongKang/tim_sdk | /lib/tim_sdk/sign.rb | UTF-8 | 1,899 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'tim_sdk/configuration'
require 'base64'
require 'openssl'
require 'json'
require 'zlib'
module TimSdk
class Sign
class << self
def signature(identifier, expire = 24 * 60 * 60)
do_signature(identifier, expire, nil)
end
def signature_with_user_buf(identifier, expire, user_buf)
... | true |
bc1cd7267e0a0f96768157f3b71b56889528ed4c | Ruby | tjarratt/turtleshell | /lib/turtleshell/device.rb | UTF-8 | 3,423 | 2.828125 | 3 | [
"MIT"
] | permissive | module TurtleShell
class DeviceNotFoundError < Exception; end
class Device
attr_reader :name
def initialize(n = 0)
raise ArgumentError.new('TurtleShell::Device.new expects a number') unless n.is_a? Fixnum
unless raw_device_attrs = TurtleShell::RTLSDR.nth_device(n)
raise TurtleShell::... | true |
5521b77cd837a39f1dc4d17acc441e8ffe7e42ab | Ruby | rwallett/Polls | /script/poll_app.rb | UTF-8 | 1,412 | 3.40625 | 3 | [] | no_license | puts "Please enter your username:"
username = gets.chomp
@logged_user = User.login(username)
input = nil
def take_questions(poll)
questions = poll.questions
responses = questions.map { |q| q.responses }
questions.length.times do |i|
puts "#{questions[i].question}"
responses[i].each {|response| puts "#{r... | true |
f7dff551add505a1cfe8651a110ddf20b9050d2f | Ruby | clejacquet/c2asmjs | /core/expr/bin_expr/shift_right_expr.rb | UTF-8 | 145 | 2.75 | 3 | [] | no_license | require_relative('shift_expr')
class ShiftRightExpr < ShiftExpr
def sym
:SHR
end
def eval_calc(val1, val2)
val1 >> val2
end
end | true |
3dfe991685afb1a99e1fadb85150689f735e099a | Ruby | gavinsharkey/prime-ruby-onl01-seng-ft-030220 | /prime.rb | UTF-8 | 268 | 3.296875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'benchmark'
# Add code here!
def prime?(number)
if number <= 3
return number > 1
end
if (2..number - 1).any? { |i| number % i == 0 }
return false
end
return true
end
guess = 37
puts Benchmark.measure { prime?(guess) }
puts prime?(guess)
| true |
33b5c8ffad8d595a738267f0e591d68271c3e033 | Ruby | MinasMazar/ultron | /lib/ultron.rb | UTF-8 | 689 | 2.53125 | 3 | [] | no_license | require "ultron/version"
require "yaml"
module Ultron
def __ultron_data
@__ultron_data
end
def __ultron_data=(data)
@__ultron_data = data
end
def __ultron_init
unless defined? DATA
f = File.new $0, "r+"
f.seek 0, File::SEEK_END
f.write "\n__END__\n"
@__ultron_data_pos = f.... | true |
dc0985662294fd078a318bfa36b5d19e3e4f2fde | Ruby | dandylionhead/ruby-challenges | /greeting.rb | UTF-8 | 389 | 4.1875 | 4 | [] | no_license | def get_time
current_time = Time.new
current_hour = current_time.hour
end
def greeting(name)
current_hour = get_time
if(current_hour > 5 && current_hour < 12)
time = "Morning"
elsif(current_hour > 12 && current_hour < 18)
time = "Afternoon"
elsif(current_hour > 18 || current_hour < 5)
time = "Night"
en... | true |
c1317c991f9b42c2233462f6964a83f3d40a4133 | Ruby | justchilly/learn-rails | /app/models/user.rb | UTF-8 | 829 | 2.59375 | 3 | [] | no_license | class User < ActiveRecord::Base
#this is to downcase all emails before being saved to ensure uniqueness
before_create :create_remember_token
before_save { self.email = email.downcase }
validates_presence_of :name
validates_length_of :name, :maximum => 50
validates_presence_of :email
validates_format_of :email,... | true |
107f818b233e04995eb49c5176ddea3fbb4ea389 | Ruby | brianhonohan/sketchbook | /ruby/console-art/lib/sketch.rb | UTF-8 | 2,191 | 3.140625 | 3 | [
"MIT"
] | permissive | require 'terminfo'
require 'tco'
require 'color'
# Inspired by Processing (https://processing.org)
class Sketch
attr_reader :frameCount, :context
def initialize
@target_fps = 30.0
@frameCount = 0
@frame_limit = 100
@context = self.class.default_context
@contexts = []
@contexts << @context
... | true |
f3b9af7411822988bb3022621545574d679894b2 | Ruby | ohtacaesar/stone | /lib/stone/tokens/str_token.rb | UTF-8 | 270 | 2.859375 | 3 | [] | no_license | # -*- coding: utf-8 -*-
module Stone
class StrToken < Token
attr :literal
def initialize(line_number, literal)
super(line_number)
@literal = literal
end
def is_string?
true
end
def get_text
@literal
end
end
end
| true |
755f9b56355b076ab21597ea2368f4989131b1d2 | Ruby | njh/ruby-playlist | /lib/playlist/format/jspf.rb | UTF-8 | 2,363 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'json'
require 'playlist/ext/compact_hash.rb' unless Hash.method_defined?(:compact)
# Module to parse and generate JSPF playlists
module Playlist::Format::JSPF
class << self
# Parse a JSPF file into a new Playlist object
# @param input [String, IO] the source of the JSPF file
# @return [Playlist... | true |
55fa41dabd6cd9aec67b1f5efafccfa805a4a753 | Ruby | tipsypastels/porygon | /lib/arguments/opt.rb | UTF-8 | 1,283 | 2.8125 | 3 | [] | no_license | class Arguments
class Opt
delegate :slice, :convert, to: :@type
def initialize(builder, long, type, default, optional)
@builder = builder
@long = long
@short = long[0]
@type = Converter.for(self, type)
@default = default
@optional = optional
end
def n... | true |
cf30ccddf0449c71866fff25af6c219a4645439d | Ruby | KBroloes/ruby-blockchain | /main.rb | UTF-8 | 685 | 3 | 3 | [
"MIT"
] | permissive | require 'digest'
require_relative './helpers/ec'
hello = "Hello World"
sha256 = Digest::SHA256.new
digest = sha256.digest hello
puts "Sha256:" + digest
def main
ec = EllipticCurve.new
puts "Keypair:"
puts "Priv: #{ec.pkey}"
puts "Publ: #{ec.pub}"
pub = ec.pub
components = ec.get_components(pub)
prett... | true |
4fa7323ebe953e02bf838af98c1abbc2289bf93a | Ruby | qingw/keyboard | /software/experimental/wxRuby/keydisplay.rb | UTF-8 | 18,238 | 2.515625 | 3 | [] | no_license | require 'wx'
require 'utils'
require 'model'
require 'notifications'
require 'displaykey'
$DRAG_MODE_NONE = 0
$DRAG_MODE_START = 1
$DRAG_MODE_DRAGGING = 2
$DISPLAY_MODE_DYNAMIC_RESIZE = 0
$DISPLAY_MODE_WRAPPED = 1
class KeyDisplayPane < Wx::ScrolledWindow
def initialize(parent, displayMode, bord... | true |
bfc39365e0d9fd7999826793c09527fc92fae29b | Ruby | pkallberg/bbtangcms | /config/initializers/bbtangcms.rb | UTF-8 | 158 | 3 | 3 | [
"MIT"
] | permissive | require 'lib_core'
class String
def cut_partial(length)
if self.length > length
self.first(length) + "..."
else
self
end
end
end
| true |
7b5fbc8b1c16636b2d7d4d3f6573db84b4229698 | Ruby | irene-george/Rexpns | /pgm3.rb | UTF-8 | 191 | 3.640625 | 4 | [] | no_license | def palindrome(s1)
if (s1 == s1.reverse) then
puts "#{s1} is a Palindrome"
else
puts "not a palindrome"
end
end
puts"enter the word"
s1=gets.downcase.chomp
palindrome(s1)
| true |
5c2189feae136d9f00471cf6118c2f8ac936d71e | Ruby | malditogeek/em-zeromq | /spec/pub_sub_spec.rb | UTF-8 | 1,761 | 2.515625 | 3 | [
"MIT"
] | permissive | require File.join(File.dirname(__FILE__), %w[spec_helper])
describe EventMachine::ZeroMQ do
class EMTestSubHandler
attr_reader :received
def initialize
@received = []
end
def on_readable(socket, messages)
@received += messages
end
end
it "Should instantiate a connection given val... | true |
df1c98ca919c87d1b195cbede5c3ef92796a7398 | Ruby | redbarron23/scripts | /ruby/helloname.rb | UTF-8 | 199 | 3.359375 | 3 | [] | no_license | #!/usr/bin/env ruby
print('Enter your name: ')
name = gets()
# Single quotes does not interpolates variable
#puts( 'Hello #{name}' )
# Double quotes interpolates variable
puts( "Hello #{name}" )
| true |
45e1533ba3c8ec53abe3b418dcfa7dcfd0938a8b | Ruby | meesern/What-Happened | /app/models/report.rb | UTF-8 | 1,591 | 2.609375 | 3 | [] | no_license | #
# requires in environment.rb do not seem to be enough here.
require 'rubygems'
require 'bundler/setup'
require 'pacecar'
class Report < ActiveRecord::Base
hobo_model # Don't put anything above this
validates_numericality_of :second, :allow_nil => true,
:greater_than_or_equal_to => 0.0, :less_than => 1.0... | true |
5507946b97e90221b3f7b9962a6719097d914a42 | Ruby | Henrychew/sinatra_sandbox_linkedme | /app/controllers/index.rb | UTF-8 | 714 | 2.578125 | 3 | [] | no_license | get '/' do
erb :index
end
get '/cool_url' do
puts params
@status = params[:status]
@sentence = params[:sentence]
@age = params[:age]
@select = params[:select]
@gender = params[:gender]
puts @status, @age, @select, @gender
erb :get_cool_url
end
post '/post_cool_url' do
sentence = params[:user_input]
... | true |
b15cfc45e3c6143012fd79520c410a2b3b47b79c | Ruby | srebalaji/100DaysOfAlgorithm | /day67/ice_cream_palor.rb | UTF-8 | 625 | 3.359375 | 3 | [] | no_license | # Ice Cream Parlour
# Complete the whatFlavors function below.
def whatFlavors(cost, money)
ha = {}
cost.each_with_index do |value, index|
# p "#{index} => #{money} #{money-index}"
if ha.key? (money-value)
# p "#{index} => #{money} #{money-index} value = #{value} and #{ha[money-index]}"
arr = [index+1... | true |
cb75d250424ff2a08040d9491af3e1aa513753a1 | Ruby | jfdimark/HigherLower-Game | /lib/shuffleable.rb | UTF-8 | 258 | 2.9375 | 3 | [] | no_license |
# The Shuffleable module contains methods that enable randomly shuffling an array
module Shuffleable
def shuffle_deck(deck)
# shuffle! is a built in array method
# could substitute an arbitrary shuffling algorithm here
return deck.shuffle!
end
end | true |
869ddda49c2b925c434d94ef62e7f279a21adc9f | Ruby | guotsuan/alfred-keepass | /crypt.rb | UTF-8 | 560 | 2.890625 | 3 | [
"Apache-2.0"
] | permissive | def decrypt(data, key, iv)
decode_cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
decode_cipher.decrypt
decode_cipher.key = Base64.decode64(key)
decode_cipher.iv = Base64.decode64(iv)
decode_cipher.update(Base64.decode64(data)) + decode_cipher.final
end
def encrypt(data, key, iv)
cipher_nonce = OpenSSL::Ciph... | true |
0f073e547450d16f65d3647bcae410bcec153493 | Ruby | sammy/tealeaf_challenges | /WK1/calculator.rb | UTF-8 | 478 | 4.53125 | 5 | [] | no_license | puts 'Simple calculator. Gimme a number:'
num1 = gets.chomp
puts 'Gimme another number'
num2 = gets.chomp
puts 'Select what do you want to perform: 1) Addition 2)Subtraction 3)Multiplication 4)Division'
selection = gets.chomp
if selection == '1'
puts num1.to_i + num2.to_i
elsif selection == '2'
puts num1.to_i - nu... | true |
7f676cbb680758b3d0780f961918ec28e4a2ba52 | Ruby | majioa/rdoba | /lib/rdoba/mixin/wait_if.rb | UTF-8 | 675 | 2.96875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'timeout'
module Rdoba::Mixin::Wait_ifKernel
##
# +wait_if+ waits for +timeout+ second to the condition passed via block,
# and in case if it failed, returns false, otherwise true. +timeout+ can
# be a float or integer number of seconds, but if passed 0 or nil it waits
... | true |
3d29389c8d290184e3d8423b2c4b8fb0f27c5260 | Ruby | bluepeartree/ruby_fundamentals1 | /exercise2.rb | UTF-8 | 663 | 3.765625 | 4 | [] | no_license | #Question 1########################################
meal_price = 55
tip_percentage = 0.15
tip_amount = meal_price * tip_percentage
puts "This meal cost $#{meal_price}."
puts "We are tipping #{tip_percentage}."
puts "The tip amount is $#{tip_amount}."
#Question 2#######################################
name = "Shar... | true |
e0e424a82220c599318378d4362ac1fb76c01514 | Ruby | karlseguin/Mongo-Web-Admin | /app/models/context.rb | UTF-8 | 1,038 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | class Context
attr_accessor :host, :port, :database, :user, :password
def initialize(arg)
if arg.is_a?String then
info = Mongo::URIParser.new(arg)
@host = info.nodes[0][0]
@port = info.nodes[0][1]
@user = info.auths[0]['username']
@password = info.auths[0]['password']
@dat... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.