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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b61499073929827d61855e01ea808d161e8f709d | Ruby | kt9302/Geopedia | /app/models/location.rb | UTF-8 | 4,663 | 2.515625 | 3 | [] | no_license | require 'rubygems'
require 'open-uri'
require 'json'
class Location < ActiveRecord::Base
attr_accessor :longitude, :latitude, :city, :county,:state, :country,:tag,:places
def initialize(location='berkeley ca', mul=false)
google_url='http://maps.googleapis.com/maps/api/geocode/json?'
match={:add... | true |
64a2c1e1f41ff87a61dd046159f792634d11bcf5 | Ruby | qqdipps/reverse_sentence | /lib/reverse_sentence.rb | UTF-8 | 849 | 4.1875 | 4 | [] | no_license | # A method to reverse the words in a sentence, in place.
# Time complexity: O(n) where n is the number of elems in string.
# Space complexity: O(1)
def reverse_sentence(my_sentence)
return if !my_sentence
return unreverse_each_word(reverse_string(my_sentence))
end
def unreverse_each_word(my_words)
left = 0
my_... | true |
9afb1b1832aac5b11263d26670cecefe5dfc32a7 | Ruby | kristenhazard/ruby-processing-play | /hazard/circle-triangle-recursion.rb | UTF-8 | 1,676 | 3.53125 | 4 | [] | no_license | class Circle
def initialize(x, y, radius)
@x = x
@y = y
@radius = radius
end
def draw(pointcount)
no_fill
angle = radians(pointcount)
# x = @x + (cos(angle) * @radius)
# y = @y + (sin(angle) * @radius)
arc @x, @y, @radius, @radius, 0, angle
if pointcount % 60 == 0
star... | true |
2a9d700e76b8efc844b2b031ee1f59d77ce65e58 | Ruby | Thomasmclean993/Ruby-stretch | /Mastermind/main/main.rb | UTF-8 | 870 | 3.90625 | 4 | [] | no_license | #1/bin/env ruby
#will need to reference the modules for this file
puts "Welcome New Master!!"
puts "The game is simple, Guess the code and you win. You will have 12 attempts."
puts "THe code will be made up of four assorted colors."
puts "Red, white, blue and black. As you guess the right color in the right slot,"
pu... | true |
fc18f9aa33c5d8456608890821cbb28810807374 | Ruby | Meeco/cryppo | /lib/cryppo/encryption_strategies/rsa4096.rb | UTF-8 | 1,655 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | module Cryppo
module EncryptionStrategies
class Rsa4096 < EncryptionStrategy
UnknownKeyPairType = Class.new(Cryppo::Error)
Cryppo::EncryptionStrategies::EncryptionStrategy.register(self)
def key_length
32 # this value has been chosen as it matches most of the AES cipher key lengths
... | true |
dec78d99fc86dbc38fe86a56c8c6d61c510d53e6 | Ruby | riakoronidi/homework_week2_day2 | /river.rb | UTF-8 | 318 | 3.15625 | 3 | [] | no_license | class River
attr_accessor :name
def initialize(name)
@name = name
@fish = ["Nemo", "Dory" , "Marlin", "Mr Puff", "Cleo"]
@stomach = []
end
def fish_in_river
@fish.count()
end
def fish_count
@bear.stomach << @fish.delete_at(-1)
fish_in_river()
@bear.food_count()
end
end
| true |
5bd7befcf65fdd3f83a494b439312bac2ca5b8a5 | Ruby | elrashid24/W1D5_Classwork | /lib/00_tree_node.rb | UTF-8 | 1,220 | 3.328125 | 3 | [] | no_license | require "byebug"
class PolyTreeNode
attr_reader :value, :parent, :children
def initialize(value)
@value = value
@parent = nil
@children = []
end
def parent=(passed_node)
old_parent = parent
@parent = passed_node
if !passed_node.nil?
old_parent.children.delete(self) unless old_pare... | true |
7b034232861053db3a1687188866ad24a71caf50 | Ruby | Marc0969/ttt-3-display_board-example-ruby-intro-000 | /lib/display_board.rb | UTF-8 | 229 | 3.046875 | 3 | [] | no_license | # display_board method prints a 3x3 tic tac toe board
def display_board
puts "A 3x3 Tic Tac Toe Board"
puts " | | "
puts "-----------"
puts " | | "
puts "-----------"
puts " | | "
end
display_board
| true |
4159db1984e3ebe6a5d65723c1ad1be7904f3e2b | Ruby | pauldambra/adventofcode2016 | /day_21/rotate_by_steps.rb | UTF-8 | 589 | 3.453125 | 3 | [
"CC-BY-4.0"
] | permissive | class RotateBySteps
def self.scramble(s, instruction)
swapper = /rotate (left|right) (\d+) step/.match instruction
if swapper
dir = swapper.captures[0]
x = swapper.captures[1].to_i
x = x * -1 if dir == 'right'
s.chars.rotate(x).join('')
else
s
end
end
def self.unscra... | true |
fdd7a6792d9da40babbd5c4c8f479574957667db | Ruby | Shopify/shopify-app-cli-extensions | /bin/shopify-cli-shell-support | UTF-8 | 2,522 | 2.703125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby --disable-gems
module ShellSupportCLI
ROOT = File.expand_path('../..', __FILE__)
class << self
def call(*argv)
case argv.shift
when 'env'
usage_and_die unless (shellname = argv.shift)
env(shellname)
else
usage_and_die
end
end
private
... | true |
78f4e329dda7088c17287691ee0447e1c893d078 | Ruby | jamesgolick/conductor | /app/models/deployment_runner.rb | UTF-8 | 1,551 | 2.578125 | 3 | [
"MIT"
] | permissive | class DeploymentRunner
attr_reader :instances, :logger, :notifier
def initialize(*instances)
@instances = instances
@logger = DeploymentLogger.new(deployment_type, *instances)
@notifier = InstanceNotifier.new(self, *instances)
end
def perform_deployment
notifier.start
handle_result ssh... | true |
237e9f6e19c6cbea9344b349e8609355ab0f92b9 | Ruby | nofxx/ubi | /spec/ubi/memorias/site_spec.rb | UTF-8 | 2,326 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Memoria::Site do
describe 'simple test' do
subject { Memoria::Site.parse('bla bla somesite.com') }
it { is_expected.to include(Memoria::Site) }
it { is_expected.to be_an Array }
it 'should have text reader method' do
expect(subject[0].text).to eq('http://somesit... | true |
73f80fe836420874621a4227c47d15093aec99c3 | Ruby | aaroncallagher/intro_to_programming | /ch_the-basics/exercise2.rb | UTF-8 | 558 | 4.28125 | 4 | [] | no_license | print "Enter a 4 digit number:"
user_number = gets.chomp.to_i
number_in_thousands_place = user_number / 1000
number_in_hundreds_place = (user_number % 1000) / 100
number_in_tens_place = ((user_number % 1000) % 100) / 10
number_in_ones_place = (((user_number % 1000) % 100) % 10) / 1
puts "The number in the Thousands p... | true |
ab05b8e911eb48332203600267f59fdff0771d02 | Ruby | osiris43/Pool-Of-Greatness | /app/models/html_nba_player_stat.rb | UTF-8 | 1,840 | 2.71875 | 3 | [] | no_license | class HtmlNbaPlayerStat
def initialize(stat_element)
@stat = stat_element
end
def player_name
player_cell = @stat.search('//td')[0]
name = player_cell.search('//a').inner_html
if(name.nil? or name.empty?)
name = player_cell.inner_html
end
name
end
def minutes
time_pl... | true |
df6f57b35fa08507d2f6fb5802db4672b000eec7 | Ruby | blessedsoy/playlister-sinatra-wdf-000 | /app/models/concerns/slugifiable.rb | UTF-8 | 208 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | module Slugifiable
module InstanceMethods
def slug
self.name.downcase.gsub(" ", "-")
end
end
module ClassMethods
def find_by_slug(slug)
self.all.find{|obj| obj.slug == slug }
end
end
end | true |
136e139764e70f14b127e5ad3ca0fbf3c5b83467 | Ruby | morotsman/learning-ruby | /multis_state_tax_calculator/lib/tax_calculator.rb | UTF-8 | 895 | 3.734375 | 4 | [] | no_license | class State
def initialize(amount)
@amount = amount
end
def total
@amount + tax
end
def tax
0
end
end
class Wisconsin < State
@@tax_table = Hash.new(0.05)
@@tax_table["eau clair"] = 0.055
@@tax_table["dunn"] = 0.054
def initialize(amount, county)
super(amount)
... | true |
41166448be765839bed16e7226929c2d97fb9e53 | Ruby | dcoy/learning-ruby | /loops_and_iterators/map_loop.rb | UTF-8 | 326 | 3.96875 | 4 | [] | no_license | arr = ['1', '2', '3', '4', '5', '6', '4568', '1324', '4567']
# Style 1
p arr.map { |x| x.to_i }
# Style 2 - most popular
p arr.map(&:to_i)
puts ("a".."g").to_a.map { |i| i * 2 }
# Create a Hash from an array of integers
# Assigning array element to its integer
puts Hash[[1.1, 2.2, 3.5, 4, 5, 6.5].map { |x| [x,x.to_... | true |
fe8e514cff60aff6538fa046dee4382df55c66a0 | Ruby | asascience-open/CFPointConventions | /timeSeriesProfile/timeSeriesProfile-Ragged-SingleStation-H.5.3.rb | UTF-8 | 2,466 | 2.53125 | 3 | [] | no_license | #! ruby
require 'numru/netcdf'
require_relative '../utils'
include NumRu
readme = \
"
"
nc = CFNetCDF.new(__FILE__, readme)
file = nc.netcdf_file
file.put_att("featureType","timeSeriesProfile")
p = 4
o = 10 #UNLIMITED
name = 50
profile_dim = file.def_dim("profile",p)
obs_dim = file.def_dim("obs",o)
name_dim = fi... | true |
66ffd3c8fa7e78c3cd83f523adbb5071d57d3e79 | Ruby | jayg20/todo-ruby-basics-online-web-prework | /lib/ruby_basics.rb | UTF-8 | 406 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1, num2)
num1/num2= total
puts total
end
def assign_variable(value="Bob")
puts "#{value}"
end
def argue(phrase="I'm right and you're wrong!")
puts "#{phrase}"
end
def greeting(greeting="Hi there," name="Bobby!")
puts "#{greeting}, #{name}"
end
def return_a_value()
return "Nice!"
end
def l... | true |
e1fc35ff23657034cf7126cd8eb165d5d9a804bb | Ruby | juani-garcia/POO_Ruby | /guias/tp9/ej5/bag_tester.rb | UTF-8 | 343 | 2.78125 | 3 | [] | no_license | require '../../tp8/ej3/point'
require_relative 'bag'
my_bag = Bag.new
my_bag.add(Point.new(0, 0))
my_bag.add(Point.new(1, 2))
my_bag.add(Point.new(3, 4))
my_bag.add(Point.new(1, 2))
puts my_bag
puts my_bag.size
puts my_bag.count(Point.new(1, 2))
puts my_bag.delete(Point.new(1, 2))
puts my_bag
puts my_bag.delete(Point.... | true |
0d31fd73d7a9bb0daab94d50f7e680a7f628bbaa | Ruby | preiser/project-euler-multiples-3-5-e-000 | /lib/oo_multiples.rb | UTF-8 | 505 | 3.78125 | 4 | [] | no_license | # Enter your object-oriented solution here!
class Multiples
def initialize(limit)
@limit = limit
end
def collect_multiples
num_array = []
num = 1
while num < @limit
if num % 3 == 0 || num % 5 == 0
num_array.push(num)
end
num += 1
end
return num_array
end
def sum_multiples()
num_array ... | true |
782f8d0372c817aa8390a033aee554164134f96d | Ruby | Neilos/boris_bikes | /lib/headquarters.rb | UTF-8 | 310 | 2.546875 | 3 | [] | no_license | require_relative 'bike'
require_relative 'dockable'
class Headquarters
attr_reader :dockables
def initialize
@dockables = []
end
def all_docked_bikes
@dockables.map {|dockable| dockable.bikes}.flatten
end
def register(headquarters, object)
dockables << new_dockable
end
end | true |
a9f61a8bdd4b81b1dbbe195e2bf6b5b6aacf330c | Ruby | bookest/hiveminder | /test/test_hiveminder_task.rb | UTF-8 | 2,134 | 2.515625 | 3 | [] | no_license | require 'test/unit'
require 'hiveminder'
require 'mocha'
require 'active_resource/http_mock'
class TaskTest < Test::Unit::TestCase
def test_tags_are_expanded
task = Hiveminder::Task.new(:tags => "\"@foo\" \"bar\" \"one two\"")
assert_equal ["@foo", "bar", "one two"], task.tags
end
def test_tags_array_co... | true |
fe839e45de2f0d755746a345ecd7dc12d397648c | Ruby | tanakh/ICFP2012 | /mapmaker.rb | UTF-8 | 1,156 | 3.03125 | 3 | [] | no_license | #!/usr/bin/env ruby
n = ARGV[0].to_i
10.times{|t|
w = n+rand(n)
h = n+rand(n)
ar = (0...h).map{|y| (0...w).map{|x| "."}}
# pats = [" ", "."," ", ".", "\\", "*", "#"].map{|c| [c,rand]}
pats = [" ", ".", "\\", "*", "#"].map{|c| [c,rand]}
50.times{
char = pats.sort_by{|c,hind|hind*rand}[0][0]
rate... | true |
5bd4a10e598f07aac2e896f2643a1c6886d482e4 | Ruby | chris510/aA-Classwork | /W3D5/DIY ADT/queue.rb | UTF-8 | 302 | 3.625 | 4 | [] | no_license | class Queue
attr_reader :array
def initialize
@array = []
end
def enqueue(el) #puts element into the end of the arr
array.push(el)
el
end
def dequeue #removes first element
array.shift
end
def peek
array.first #looks at the next element that is queue
end
end | true |
2d78a4fb5b6f69151e3fb878c38aac7a23300a25 | Ruby | christianchrr/prime-ruby-onl01-seng-ft-041320 | /prime.rb | UTF-8 | 196 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(number)
if number < 2
return false
end
(2...number).each do |num|
if number % num == 0
return false
end
end
return true
end
| true |
6a348f022594c4eca35e891ed00aad8dfa6b38ee | Ruby | rsnorman/julysoundcheck | /app/services/sheet_sync/sheet_row.rb | UTF-8 | 986 | 2.671875 | 3 | [] | no_license | module SheetSync
class SheetRow
ATTRIBUTE_COLUMNS = {
artist: 1,
album: 2,
genre: 3,
source: 4,
review: 5,
reviewer: 6,
date_reviewed: 7,
rating: 8,
aotm: 9,
recommended_by: 10
}.freeze
ATTRIBUTE_COLUMNS.each_pair do |attr, column_index|
d... | true |
672106abe0db11a24a44fe900ea1f48a7ec0a65f | Ruby | tadeusrox/hackerrank | /30_days_of_code/day20.rb | UTF-8 | 439 | 3.6875 | 4 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
total_swaps = 0
(0..n-1).each do |i|
swaps = 0
(0..n-2).each do |j|
if a[j] > a[j + 1]
temp = a[j]
a[j] = a[j + 1]
a[j + 1] = temp
swaps += 1
total_swaps += 1
end
end
if swaps == 0
break
en... | true |
14c28a214f47c90179627faa6991dd8c351af6ed | Ruby | ql/euler | /problem78.rb | UTF-8 | 1,058 | 3.578125 | 4 | [] | no_license | require 'euler_helper.rb'
NAME ="Investigating the number of ways in which coins can be separated into piles."
DESCRIPTION ="Find the least value of n for which p(n) is divisible by one million."
def c n, memo
count(n,n-1, memo) + 1
end
def count n, k, memo = {}
memo[[n,k]] ||= if k == 2
(n/2).floor + 1
els... | true |
85840a7cb4cec998b247e79528cc3063bf08d12a | Ruby | herrtreas/shortcut | /lib/shortcut/index.rb | UTF-8 | 734 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Shortcut
class Index
def self.load
if (File.exist?("/Users/andreas/.shortcut.index"))
puts "Loading index.."
lines = []
File.open("/Users/andreas/.shortcut.index", "r") do |f|
lines = f.readlines
end
else
puts "Updating index.."
lin... | true |
c616f88e6eb7e0d7e40458a9104ac85eafb08981 | Ruby | asbudik/git_practice | /hello.rb | UTF-8 | 113 | 3.75 | 4 | [] | no_license | if 1 < 2
puts "yeah"
elsif 1 = 2
puts "ok"
else
puts "nah"
end
if 3 < 4
puts "yay"
else
puts "way"
end | true |
f6918be48682d4bbdb6775d71a7cdd79894e6470 | Ruby | aceofbassgreg/sentimental-writer | /app/services/twitter/importer.rb | UTF-8 | 1,779 | 2.890625 | 3 | [] | no_license | require 'forwardable'
class Twitter::Importer
extend Forwardable
delegate [:get] => :wrapper
extend Forwardable
attr_reader :wrapper
def initialize
@wrapper = Twitter::Wrapper.new
end
def load_tweets_for(subject)
15.times do
all_tweets_for(subject).each do |tweet|
store_all_d... | true |
0c00264800e2c0335554b0016d0342c1e742748d | Ruby | neonwires/ttt-5-move-rb-q-000 | /lib/move.rb | UTF-8 | 401 | 3.296875 | 3 | [] | no_license | def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
# code your move method here!
def move(board, movechoice, playertoken = "X")
movechoice = mov... | true |
577660f093c019327651957a510ad2f1574a1b9f | Ruby | Prabhakarzx/Web-Scraper-Ruby-Capstone | /lib/team_scraper.rb | UTF-8 | 940 | 2.78125 | 3 | [
"MIT"
] | permissive | require_relative './constants.rb'
require_relative './parser.rb'
require_relative './file_handler'
require_relative './show_status.rb'
class TeamScraper < Parser
include ShowStatus
def initialize(url, league)
@url = url
@league = league
@team_hash = {}
parse_teams
end
private
def parse_tea... | true |
a2293ad2394fdee1108dcef363b0a84d1c098729 | Ruby | AlexeyShpavda/LearningRuby | /6)Redacted.rb | UTF-8 | 534 | 4.125 | 4 | [
"MIT"
] | permissive | =begin
Contents:
Getting the User's Input
The .split Method
Redacted!
Control Flow Know-How
=end
puts "### Getting the User's Input ###"
print "Text to search through: "
text = gets.chomp
print "Word to redact: "
redact = gets.chomp
puts "### The .split Method ###"
words = text.split(" ")
print word... | true |
c56eb4d4807df749fba944893c01226349df838a | Ruby | KierranM/marry-me | /lib/marry/me.rb | UTF-8 | 838 | 3.359375 | 3 | [] | no_license | require 'marry/me/version'
require 'marry/me/simple_stable_marriage'
require 'marry/me/matchable'
require 'marry/me/logger'
module Marry
module Me
# Matches the 'partners' in pool_one to their optimal match in pool_two
# @param pool_one [Array<Matchable>] Pool of partners to match with pool_two
# @param ... | true |
2bceac6d1be230eb19c51b1ec0db0102f14f3d07 | Ruby | drusepth/inline-tests-gem | /lib/inline_test_failure.rb | UTF-8 | 429 | 2.8125 | 3 | [] | no_license | class InlineTestFailure < StandardError
attr_accessor :test_type, :lhs, :rhs, :description
def initialize(test_type=nil, lhs=nil, rhs=nil, description=nil)
super [
" #{description} FAILED:",
" test_type: #{test_type}",
" lhs: #{lhs}",
" rhs: #{rhs}"
].join "\n"
... | true |
5dd9e151a32c1ea958432544dae0211ddd1e48e7 | Ruby | GregoryJFischer/war_or_peace | /spec/deck_spec.rb | UTF-8 | 2,792 | 3.078125 | 3 | [] | no_license | require 'rspec'
require './lib/deck'
describe Deck do
describe "#initialize" do
it "is an instance of deck" do
card1 = Card.new(:diamond, 'Queen', 12)
card2 = Card.new(:spade, '3', 3)
card3 = Card.new(:heart, 'Ace', 14)
cards = [card1, card2, card3]
deck = Deck.new(cards)
exp... | true |
9350d6fde3c398ad85c6123852c885459784a841 | Ruby | OwenKLenz/rb120_object_oriented_programming | /medium_1/deck_of_cards.rb | UTF-8 | 1,027 | 3.796875 | 4 | [] | no_license |
require 'set'
class Card
include Comparable
attr_reader :rank, :suit
CARD_RANKINGS = Set.new([2, 3, 4, 5, 6, 7, 8, 9, 10,
"Jack", "Queen", "King", "Ace"]).freeze
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def <=>(other_card)
CARD_RANKINGS.find_index(s... | true |
ecd27ea2c08f941f9daabb8f4a91ef86f29a5f28 | Ruby | cout/redtimer | /demos/256colors.rb | UTF-8 | 380 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'curses'
screen = Curses.init_screen
begin
Curses.start_color
Curses.use_default_colors
Curses.curs_set(0)
Curses.noecho
window = Curses::Window.new(0, 0, 1, 2)
window.clear
window.setpos(0, 0)
for i in 0...256 do
Curses.init_pair(i, i, 0)
window.color_set(i)
window << i.to_s <<... | true |
9827959aa30827b256aeda26ac4b3db6701f9535 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/roman-numerals/c6ed64c2dbc645e38a854829b826d73e.rb | UTF-8 | 1,122 | 3.859375 | 4 | [] | no_license | # class Fixnum
# def to_roman
# roman_1000 + roman_100 + roman_10 + roman_1
# end
# private
# def roman_1000
# count = self / 1000
# 'M' * count
# end
# def roman_100
# count = (self % 1000) / 100
# convert(count, 'C', 'D', 'M')
# end
# def roman_10
# c = (self % 100) / 10
# convert(c, 'X', 'L', 'C')... | true |
d3e2aa33f6a32af0d005a294920cd785a16de80d | Ruby | Numbericons/aa_online_W7D1 | /executing_time_difference.rb | UTF-8 | 1,716 | 3.828125 | 4 | [] | no_license | require 'byebug'
def my_min_p1(list)
list.each do |num|
return num if list.all? { |num_in| num_in >= num }
end
end
def my_min_p2(list)
minimum = nil
list.each do|num|
minimum = num if minimum.nil? || num < minimum
end
minimum
end
list = [ 0, 3, 5, 4, -5, 10, 1, 90 ]
# p "Below ... | true |
2e3db3bbe915c92217495ba1a524eed44d5dfe86 | Ruby | pecha7x/MyScratchpad | /NessGems/wx_sugar-0.1.22/lib/wx_sugar/string_each.rb | UTF-8 | 95 | 2.640625 | 3 | [
"MIT"
] | permissive | class String
def each
self.split("\n").each do |line|
yield line
end
end
end
| true |
ff916c9bef9975b9a722bd3c6fd0746bef0523b1 | Ruby | NCU-BRATS/Conflux | /app/policies/project_user_context.rb | UTF-8 | 205 | 2.578125 | 3 | [] | no_license | class ProjectUserContext
attr_reader :user, :project
def initialize( user, project )
@user = user
@project = project
end
def is_project_member?
@user.is_member?(@project)
end
end
| true |
a319ab700380e8456b9c22e8904869704128e44f | Ruby | krepflap/games_dice | /spec/reroll_rule_spec.rb | UTF-8 | 1,527 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'helpers'
describe GamesDice::RerollRule do
describe "#new" do
it "should accept self-consistent operator/value pairs as a trigger" do
GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
GamesDice::RerollRule.new( (1..5), :member?, :reroll_replace )
end
it "should rejec... | true |
b3df9acbbb81a8da7deeb4076e7d8f27a763370e | Ruby | peterayeniofficial/oo-relationships-practice-london-web-102819 | /app/models/bakery/dessert.rb | UTF-8 | 210 | 2.9375 | 3 | [] | no_license | class Desert
attr_reader :desert, :bakery
@@all = []
def initialize(ingredients, bakery)
@ingredients = ingredients
@bakery = bakery
@@all << self
end
def self.all
@@all
end
end | true |
91309b688b93afaca5f847d9149c8fd5b2baf706 | Ruby | rathi2016/count-elements-web-0217 | /count_elements.rb | UTF-8 | 100 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def count_elements(array)
hash = Hash.new(0)
array.each do |ele|
hash[ele] +=1
end
hash
end
| true |
9aa93461b53bda46ca8d9ca38a8db3565ed11c59 | Ruby | julienemo/rails_api_devise_jwt_starter | /db/seeds.rb | UTF-8 | 204 | 2.53125 | 3 | [] | no_license | puts 'Creating users...'
n = 1
10.times do
User.create!(
username: "created_from_seed#{n}",
email: "seededuser#{n}@yopmail.com",
password: "111111"
)
n += 1
end
puts "#{User.all.size} users created"
| true |
81ea1e705b8bfcb66e1d6fc6c3e7f6cfd08ad321 | Ruby | pwentz/night_writer | /lib/decryption_formatter.rb | UTF-8 | 676 | 3 | 3 | [] | no_license | require_relative "braille_parser"
require 'pry'
class DecryptionFormatter
attr_reader :raw_braille, :parsed_content, :sorted_braille
def initialize
@sorted_braille = Array.new
end
def parse_braille(raw_braille)
braille_parser = BrailleParser.new
parsed_lines = raw_braille.split("\n")
parsed_le... | true |
f0cd2dc53e7676095b3e9711ead4a9ea42568098 | Ruby | JoshMacSween/odin | /caesar.rb | UTF-8 | 197 | 3.234375 | 3 | [] | no_license | def cipher(str, key)
alphabet = ("a".."z").to_a
alpha_shift = alphabet.rotate(key)
str.downcase.chars.map do |char|
alpha_shift[alphabet.index(char)]
end.join
end
cipher("hello", 2 )
| true |
e453b3723fe8a89f281734d7f0b7739a14adcbba | Ruby | rleer/diamondback-ruby | /tests/parser/large_examples/node.rb | UTF-8 | 1,578 | 3.171875 | 3 | [
"BSD-3-Clause"
] | permissive | require "rexml/parseexception"
module REXML
# Represents a node in the tree. Nodes are never encountered except as
# superclasses of other objects. Nodes have siblings.
module Node
# @return the next sibling (nil if unset)
def next_sibling_node
return nil if @parent.nil?
@parent[ @parent.index(self) + 1... | true |
d7bd8c7d4b17e5fbe77fad8e35bc73b63a959674 | Ruby | toddsdarling/developers | /examples/ruby-single-user/app.rb | UTF-8 | 608 | 2.71875 | 3 | [] | no_license | require 'oauth'
require 'json'
CONSUMER_KEY = 'YOUR_CONSUMER_KEY'
CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET'
# Get these from http://accesstoken.io
ACCESS_TOKEN_KEY = 'YOUR_ACCCESS_TOKEN_KEY'
ACCESS_TOKEN_SECRET = 'YOUR_ACCESSS_TOKEN_SECRET'
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, s... | true |
f4b942d6a146f7b7b70f0c8b2301e52d056106e1 | Ruby | greytape/backend | /101-109 /easy4_9.rb | UTF-8 | 1,391 | 4.53125 | 5 | [] | no_license | # Approach
# - input: integer
# - output: string
# - use integer#/ and integer#% to get first value and remainder
# - will need to work out how long the integer is to know what to divide by
# - can then use 10 ^ intgr_size as divisor
# - probably use a dedicated method for this bit (maybe with recursion?)
# - then we... | true |
2694fb83c6fc752f660de1a718b8f0619e585ed6 | Ruby | Nejuf/Ruby-Blackjack | /src/ComputerPlayer.rb | UTF-8 | 886 | 3.140625 | 3 | [] | no_license | require('./src/Player')
class ComputerPlayer < Player
def initialize(name="computer")
super()
@name = name
end
def choose_play(hand, dealer_top_card=nil)
if @money <= 0
return { :action => :quit }
end
if hand.bet == 0
bet = @money/5
bet = bet <= 0 ? 1 : bet
return { :action... | true |
933c2b9e350a30c79d78b4375b7ba7d2fd539637 | Ruby | pharhadnadi/kyubits | /hackerrank/euler/230/1_alpha_fib.rb | UTF-8 | 1,952 | 3.90625 | 4 | [] | no_license | # This problem is a programming version of Problem 230 from projecteuler.net
#
# For any two strings of digits, and , we define to be the sequence (, , , , , ) in which each term is the concatenation of the previous two.
#
# Further, we define to be the -th digit in the first term of that contains at least dig... | true |
595016a4e6065af9e8e444e1867d744e9e7f473e | Ruby | 12Starlight/App-Academy-Master | /AppAcademyFoundations/W3D5/battleship_project/lib/board.rb | UTF-8 | 1,443 | 3.9375 | 4 | [] | no_license | class Board
# getters, # setters
attr_reader :size
# class method
def self.print_grid(grid)
grid.each do |row|
puts row.join(" ")
end
end
def initialize(n)
@grid = Array.new(n) { Array.new(n, :N) }
@size = n * n
end
# instance methods
def [](position)
row, col = pos... | true |
62db274a1e84a44f732c67872daaad070cc9766b | Ruby | Castone22/word-counter-ruby | /counter.rb | UTF-8 | 769 | 3.421875 | 3 | [] | no_license | require 'json'
## Tool written to do word count on an input file.
## - Some considerations
## Words can be composites, including - or '
## Capitalization should be ignored.
## Output can be placed in a file type of choice
## -- In this regard I chose to go with json since some of that yaml reserved keys were m... | true |
a4431f1f4c30801c9a4937b2a33a82a6a2959ca8 | Ruby | simonkrausgit/the_odin_project | /ruby/building_blocks/spec/bubble_sort_spec.rb | UTF-8 | 984 | 3.328125 | 3 | [] | no_license | require_relative '../bubble_sort'
describe "#bubble_sort" do
it 'should return an Array' do
expect(bubble_sort([2,3])).to be_kind_of(Array)
end
it 'should sort an Array' do
expect(bubble_sort([3,2])).to eq([2,3])
end
it 'should sort an Array' do
expect(bubble_sort([3,2,1])).to eq([1,2,3])
end
... | true |
81776168f0d0b9a8abf5449c0d4bedce7e05f464 | Ruby | lrsousa/RubyStudies | /ruby/ruby restaurante_avancado.rb | UTF-8 | 1,327 | 3.703125 | 4 | [] | no_license | class Franquia
def initialize
@restaurantes = []
end
def adiciona(*restaurantes)
for restaurante in restaurantes
@restaurantes << restaurante
end
end
def mostra
@restaurantes.each do |r|
puts r.nome
end
end
def relatorio
@restaurantes.each do |r|
yield r
end
end
def expandir(restaura... | true |
95420ce2ba00523a4b9247fb688a5453e73ab7ff | Ruby | elia/opal | /test/core/numeric/equal_value_spec.rb | UTF-8 | 213 | 3.125 | 3 | [
"MIT"
] | permissive | describe "Numeric#==" do
it "returns true if self has the same value as other" do
(1 == 1).should == true
(9 == 5).should == false
(9 == 9.0).should == true
(9 == 9.01).should == false
end
end | true |
d0bc215149177e65e240f104e02c4b7873432da7 | Ruby | sanger/print_my_barcode | /app/label_printer/label_printer/data_input.rb | UTF-8 | 448 | 2.546875 | 3 | [] | no_license | # frozen_string_literal: true
module LabelPrinter
##
# Manages the production of the text for the input for the printer.
# Turns the input values into a format which can be recognised by the printer.
module DataInput
##
# Produces a new data input object from input values and a label template
def s... | true |
b3221295a9c6dce8bac9f30953bac2bfb6076d7c | Ruby | eaball35/hotel | /lib/reservation.rb | UTF-8 | 480 | 3.171875 | 3 | [] | no_license | require_relative 'input_validation'
class Reservation
attr_reader :room, :booking_date_range, :price, :discount
def initialize(room:, booking_date_range:, discount: 0)
check_room?(room)
check_booking_date_range?(booking_date_range)
check_num?(discount)
@room = room
@booking_date_range =... | true |
f0cd062c27f96b2d3d87b025b47000faced8a1f8 | Ruby | Eneroth3/townhouse-system | /src/ene_buildings/observers.rb | UTF-8 | 4,228 | 2.65625 | 3 | [
"MIT"
] | permissive | # Eneroth Townhouse System
# Copyright Julia Christina Eneroth, eneroth3@gmail.com
module EneBuildings
# Internal: Wrapper for all observer related code in plugin.
# Concentrating observers here that actually has to do with different classes
# still is cleaner and easier to maintain than spreading out observers and
... | true |
fdf1d72990e9ea6371f185d02c438473cb5e5226 | Ruby | KurisuLim/basic_ruby | /method.rb | UTF-8 | 210 | 4.125 | 4 | [] | no_license | # Methods
def sayhi
puts 'Hello User'
end
sayhi # calls the method
def sayhello(name='none', age=0)
puts "Hello #{name}, you are #{age.to_s}."
end
sayhello('John', 78)
sayhello # uses default values | true |
6876f92e58622b71ca97ae19f994e3df952edb97 | Ruby | alecnhall/sinatra-mvc-lab-online-web-pt-081219 | /models/piglatinizer.rb | UTF-8 | 469 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
def piglatinize(input)
words = input.split(" ")
words.map do |word|
piglatinize_word(word)
end.join(" ")
end
private
def piglatinize_word(input)
first = input.match(/^[^AEIOUYaeiouy]+/)
if first
f... | true |
935c89f9b31560b8d35c0cc4bcdee66e26c24ba4 | Ruby | RadoRado/playground | /ruby/hackbulgaria-problems/week3/1-GameOfLife/cell.rb | UTF-8 | 387 | 3.421875 | 3 | [] | no_license | # rubocop:disable Style/Documentation
module GameOfLife
class Cell
attr_accessor :is_alive, :x, :y
def initialize(x, y, is_alive = false)
@x = x
@y = y
@is_alive = is_alive
end
def die
@is_alive = false
end
def bring_to_life
@is_alive = true
end
def t... | true |
84246a807389246b34061c3190be74406cd0ac5b | Ruby | tchoutdara/week1brainteaser | /teaser_solution1.rb | UTF-8 | 815 | 4.03125 | 4 | [] | no_license | require 'pry'
def input
puts "Please enter a series of numbers"
@user_numbers = gets.split(' ').map { |x| x.to_i }
# @user_numbers = gets.split(' ').map(&:to_i)
puts "1) Highest Value or 2) Lowest Value"
choice = gets.strip
if choice === '1'
highest
elsif choice === '2'
lowest
else
puts 'Pl... | true |
a433ffbfd565099f45824581e85c1856b51bb6e4 | Ruby | weymanf/interview_problems | /add_nums_to_words.rb | UTF-8 | 500 | 3.8125 | 4 | [] | no_license | #takes string and adds numbers after the words
# i.e "this is it"
# "this3 is2 it1"
def add_nums_to_words(str)
counter = 1
if str.reverse[0] != " "
str << "#{counter}"
counter += 1
end
reversed_str = str.reverse
reversed_str.split(//).map.with_index do | character, i |
if character == " " ... | true |
3297905fa895edc33c024a80599aac2ec22654c7 | Ruby | neontuna/project_viking_store | /app/models/credit_card.rb | UTF-8 | 505 | 2.75 | 3 | [] | no_license | class CreditCard < ActiveRecord::Base
belongs_to :user
has_many :orders
validates :card_number, :exp_month, :exp_year, :ccv, presence: true
validate :valid_card_number
def display_card_number
"Ending in #{card_number[-4..-1]}"
end
private
def valid_card_number
if !card_number.nil? && !@c... | true |
2ab6153de430b049fcf6f0e09058bfd27ff3694d | Ruby | Alex-Swann/advent_of_code_2020 | /Answers/1.rb | UTF-8 | 796 | 3.390625 | 3 | [] | no_license | def find_combo(arr, combo)
arr.combination(combo).any? do |*nums|
arr = nums[0]
if arr.reduce(&:+) == 2020
pp arr.reduce(&:*)
break
end
end
end
arr = File.readlines('../Test_Data/1.txt', chomp: true).map(&:to_i)
find_combo(arr, 3)
# O(n^2) Example
#
# require 'set'
#
# def find_combo(arr,... | true |
74cf34eea62aa9466c381b5fe41bb74f5dfaeb00 | Ruby | Candillan/ruby-oo-complex-objects-school-domain-nyc-web-120919 | /lib/school.rb | UTF-8 | 429 | 3.546875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # code here!
class School
def initialize(school_name, roster={})
@roster = roster
@school_name = school_name
end
attr_reader :school_name, :roster
def add_student(name, grade)
if !@roster[grade]
@roster[grade] = []
end
@roster[grade] << name
end
def grade(year)
@roster... | true |
948fdf8b0e1999e3d4eb81615a153325f87996f1 | Ruby | kontez/PM1-PT1 | /Aufgabe3/muster_ausgeben.rb | UTF-8 | 2,229 | 4 | 4 | [] | no_license | def dreieck(n, zeichen)
if ( n <= 0 )
puts "keine Ausgabe für n=#{n} möglich"
else
n.times do |i|
puts ("#{zeichen} "*(i+1))
end
end
end
def dreieck_alternierend(n, zeichen1, zeichen2)
max_l = n.to_s().size()
if ( n <= 0 )
puts "keine Ausgabe für n=#{n} möglich"
else
#heade... | true |
e5ce57f18d55f57c26fcc2c2e1da3caf721d1378 | Ruby | urimikhli/PoS | /terminal.rb | UTF-8 | 732 | 2.734375 | 3 | [] | no_license | require_relative 'order.rb'
class Terminal
attr_reader :order, :price_list
def initialize
@price_list = PriceList.new
@order = Order.new(@price_list)
end
#new list and new order
def set_pricing(pricing_type='regular')
@price_list.set_price_list(pricing_type)
@order = Order.new(@price_list)
... | true |
7d1cc19bd370fe0708d299f1d39be4c1aa01bfd5 | Ruby | maximkoo/ruby-repo | /Tk/Gosu/jump.rb | UTF-8 | 913 | 3.015625 | 3 | [] | no_license | require 'gosu'
class C1<Gosu::Window
def initialize width=400, height=400, fullscreen=false
super
self.caption="OLOLO";
@rock_image = Gosu::Image.new(self, '1.png')
@x=100
@y=100
@vy=10
end;
def button_down(id)
close if id==Gosu::KbEscape;
if id==Gosu::KbUp
puts :up
@y-=10
... | true |
dec11b0faf5b45518f984f053e14101afb955be9 | Ruby | walidwahed/ls | /exercises/101-109_small_problems/additional_practice/easy8/09.rb | UTF-8 | 1,361 | 4.53125 | 5 | [] | no_license | # Double Char (Part 2)
# Write a method that takes a string, and returns a new string in which every consonant character is doubled. Vowels (a,e,i,o,u), digits, punctuation, and whitespace should not be doubled.
# Examples:
# - in: string
# - possible to have empty input
# - out: string
# - every consonant doubl... | true |
3718c1afd2ac2ffa082c36d98f10311af866dadf | Ruby | rorybot/bank-tech-test | /spec/deposits_spec.rb | UTF-8 | 1,056 | 2.59375 | 3 | [] | no_license | describe Account do
let(:test_account) { Account.new }
context 'when interacting with an account' do
it 'can track balance' do
2.times { test_account.change_balance(1000, '10-01-2012') }
expect(test_account.query_balance(test_account.transaction_history)).to eq 2000
end
it 'can store the a... | true |
52a9c7799aa3e9427edc7eccffae1b2e9c2b6bc7 | Ruby | stardust789/programming_collective_intelligence | /similarity.rb | UTF-8 | 4,651 | 2.765625 | 3 | [] | no_license | class Similarity
attr_reader :critics, :films
def initialize
@critics = {
'lisa rose' => {
'lady in the water' => 2.5,
'snakes on a plane' => 3.5,
'just my luck' => 3.0,
'superman returns' => 3.5,
'you me and dupree' => 2.5,
'the night listener' => 3.... | true |
daad593e0116890b3abaea5f41a19bbe88116f0a | Ruby | hientuminh/SOLID_In_Ruby | /SRP/AuthenticatesUser/Not_SRP/authenticates_user.rb | UTF-8 | 312 | 2.578125 | 3 | [] | no_license | class AuthenticatesUser
def authenticate(email, password)
if matches?(email, password)
do_some_authentication
else
raise NotAllowedError
end
end
private
def matches?(email, password)
user = find_from_db(:user, email)
user.encrypted_password == encrypt(password)
end
end
| true |
b9ae2c23ecd325b743269a52504fe5149695e4ad | Ruby | ebenavides/TI3404-TPIV | /Main.rb | UTF-8 | 673 | 2.890625 | 3 | [] | no_license |
load 'TwitterAPI.rb'
load 'InstagramAPI.rb'
require 'twitter'
require 'instagram'
print "\nDigite el #hashtag\n"
hashtag = gets.chomp
print "\nDigite la cantidad \n"
quantity = gets.chomp
_twitter = TwitterAPI.new()
_instagram = InstagramAPI.new()
print "\nTwitter=================================="
_twitter.Search... | true |
1ea35827d2cb5a562e8eee1bb7fa9cc496f288ac | Ruby | morag92/understanding_programming | /avengers.rb | UTF-8 | 240 | 2.59375 | 3 | [] | no_license | avengers = {
Iron_Man: {
name:"tony_stark",
moves:{
punch: 10,
kick: 100
}
},
Hulk: {
name:"Bruce_Banner",
moves:{
smash: 1000,
roll: 500
}
}
}
puts avengers [:Hulk][:moves][:smash]
| true |
65354c07319c309e2bd4c7d43376e7f14151f3d1 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/difference-of-squares/58118de88ed143609e5abf8235625790.rb | UTF-8 | 317 | 3.625 | 4 | [] | no_license | class Squares
attr_reader :n
def initialize(number)
@n = number
end
def square_of_sums
sum_of_numbers**2
end
def sum_of_squares
sum_of_numbers * (2 * n + 1) / 3
end
def difference
square_of_sums - sum_of_squares
end
private
def sum_of_numbers
n * (n + 1) / 2
end
end
| true |
37edaf6dd504a086446aaae756ef23cc9799bb86 | Ruby | darvs/advent-of-code | /2020/2001.rb/features/step_definitions/cucumber_steps.rb | UTF-8 | 242 | 2.890625 | 3 | [] | no_license | # frozen_string_literal: true
Given('the number in file {string}') do |string|
@expense = Expense.from_file(string)
end
Then('the multiplication of {int} numbers would be {int}') do |int, int2|
expect(@expense.run(int)).to eq(int2)
end
| true |
9170aab6029182e9cfe3c0769e19ff6b17c60c73 | Ruby | fakehatecrimes/fakehatecrimes | /app/helpers/application_helper.rb | UTF-8 | 6,274 | 2.640625 | 3 | [] | no_license | require "#{ Rails.root }/lib/calendar_date_select/lib/calendar_date_select.rb"
CalendarDateSelect.format = :american
HIT_THIS_BUTTON = "Fill in the form and hit this button"
SAVE_BUTTON = " Save "
SAVING_BE_PATIENT = "Saving - please be patient..."
SAVE_MEDIUM_BUTTON = "Save " + Article::DESCRIPTION.downcase
CLICK_HE... | true |
a7c163966e9f1ebf1373107d16ccdba1fbf95db0 | Ruby | conyekwelu/rb101 | /euler/3.rb | UTF-8 | 699 | 4.21875 | 4 | [] | no_license | # Largest prime factor
#
# Problem 3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
#
# algo:
# iterate from 1 up to input integer
# add to a factor array if factor of input
# select [prime factors], select max of prime factors
def is_prime?(num)
c... | true |
fc8872e9707d06e02d03c61841553894e4816c58 | Ruby | joubin/gitlabhq | /lib/pager_duty/webhook_payload_parser.rb | UTF-8 | 1,809 | 2.5625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"CC-BY-SA-4.0"
] | permissive | # frozen_string_literal: true
module PagerDuty
class WebhookPayloadParser
SCHEMA_PATH = Rails.root.join('lib', 'pager_duty', 'validator', 'schemas', 'message.json')
def initialize(payload)
@payload = payload
end
def self.call(payload)
new(payload).call
end
def call
Array(... | true |
260720616f1e7742759c8d5618db4e86a5ad9fe7 | Ruby | bbensky/launch_school | /launch_school_lessons/101-109_small_problems/advanced_1/3_transpose_3x3.rb | UTF-8 | 1,309 | 4.25 | 4 | [] | no_license | # def transpose(matrix)
# transposed_matrix = []
# max_index = matrix.size - 1
# 0.upto(max_index) do |column|
# new_row = []
# matrix.each_index do |row|
# new_row << matrix[row][column]
# end
# transposed_matrix << new_row
# end
# transposed_matrix
# end
# alt w/ map
# def transpos... | true |
14e16b72169692605ca18bc99386141daee9739c | Ruby | uk-gov-mirror/UKGovernmentBEIS.beis-report-official-development-assistance | /app/services/transaction_overview.rb | UTF-8 | 1,153 | 2.71875 | 3 | [
"MIT"
] | permissive | class TransactionOverview
def initialize(activity, report)
@activity = activity
@report = report
end
def all_quarters
group_fields = "transactions.financial_year, transactions.financial_quarter"
relation = transaction_relation
.group(group_fields)
.select("#{group_fields}, SUM(value)... | true |
fea8ca415e382f54a9eda3c73ff439f5d1628cbc | Ruby | harisfi/CompetitiveProgramming | /HackerRank/30-Days-of-Code/Day20.rb | UTF-8 | 384 | 3.703125 | 4 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
swaps = 0
for i in 0..(n-1)
for j in 0..(n-2)
if a[j] > a[j+1]
a[j], a[j+1] = a[j+1], a[j]
swaps += 1
end
end
if swaps < 1
break
end
end
puts "Array is sorted in #{swaps} swaps... | true |
95487ab5abcc2adb903e0aa972b6e9a78e4c6d66 | Ruby | tobiasvl/pgnlint | /lib/pgnlint/parser.rb | UTF-8 | 2,522 | 2.578125 | 3 | [] | no_license | require 'parslet'
module PGNLint
class Parser < Parslet::Parser
rule(:space) { match("[[:space:]]").repeat(1) }
rule(:space?) { space.maybe }
root(:pgn_database)
rule(:pgn_database) do
pgn_game.as(:game).repeat.as(:database)
end
rule(:pgn_game) do
tag_section.as(:tags) >>... | true |
1f43ef63e866881d4ff757aa746b1c6038b80318 | Ruby | page-io/ruby-twig | /lib/twig/sandbox/security_policy.rb | UTF-8 | 2,761 | 2.765625 | 3 | [] | no_license | module Twig
module Sandbox
class SecurityPolicy
def initialize(allowed_tags = [], allowed_filters = [], allowed_methods = [], allowed_properties = [], allowed_functions = [])
@allowed_tags = allowed_tags
@allowedilters = allowed_filters
set_allowed_methods(allowed_methods)
@... | true |
3b7d1012953064a044d1b67f4355c465cf4cb18f | Ruby | stefluu/aA-Classwork | /W2D2/Chess Game/Piece.rb | UTF-8 | 386 | 3.1875 | 3 | [] | no_license | require_relative "Board.rb"
class Piece
attr_reader :val
def initialize(val)
@valid_moves = []
@val = val
end
def valid_move?(end_pos)
true
#some list of valid ones, and check if the pos is there. return bool
end
def inspect
self.val.colorize()
end
def moves;end
end
... | true |
109519a05238879f7d1fdf60a61bccaff0689303 | Ruby | cescarez/string-manipulation-practice | /lib/reverse_sentence.rb | UTF-8 | 2,533 | 4.25 | 4 | [] | no_license | # A method to reverse the words in a sentence, in place.
# METHOD 1: USING .REPLACE, but is that an "in-place" reversal? Really it's a reversal in a new string and replacing the contents of the passed in object with the values of the new string....
# Time complexity: O(nm), where n is number of words in the sentence a... | true |
61ca62339fb24d042d5b5f5bfc723471222e93c4 | Ruby | ssheehan1210/phase-0-tracks | /ruby/gps6/my_solution.rb | UTF-8 | 2,835 | 3.59375 | 4 | [] | no_license | # Virus Predictor
# I worked on this challenge [with: Yamini S., Sam Sheehan].
# We spent [#] hours on this challenge.
# EXPLANATION OF require_relative
# lists a relative path, includes it in the document if its accessible
# separate from 'require', in which you refer to an absolute path
# if not found, then... | true |
e0ff358aaaf5d0a2b35420d76bfa2195e30f3822 | Ruby | binitkumar/campusdream | /app/models/test_participation.rb | UTF-8 | 581 | 2.515625 | 3 | [] | no_license | class TestParticipation < ActiveRecord::Base
attr_accessible :question_paper_id, :score, :time_consumed, :user_id
belongs_to :question_paper
belongs_to :user
def self.current_participation(question_paper_id,user_id)
where(
question_paper_id: question_paper_id,
user_id: user_id
).first
en... | true |
3d44156a6a97f58a25d3cf795aed0fa93decf3aa | Ruby | Shopify/redis-tools | /tools/bin/redis-slowlog | UTF-8 | 1,996 | 2.859375 | 3 | [] | no_license | #!/usr/bin/ruby
$LOAD_PATH << File.dirname(File.realpath(__FILE__)) + "/../lib"
require 'redis_tool'
require 'statsd'
class SlowLogger < RedisTool
class Entry < Struct.new(:id, :timestamp, :duration, :command_name, :arguments, :command, :command_raw)
def initialize(id, timestamp, duration, command)
supe... | true |
a1a2d7c38401d09381ebc41464ab48d835950bb5 | Ruby | Fleurtam/fizz_buzz | /lib/fizz_buzz.rb | UTF-8 | 385 | 3.984375 | 4 | [] | no_license |
def fizz_buzz(number)
if number.is_a? String
'You should enter a number'
elsif number < 0
'You should enter a number'
elsif has_zero_remainder?(number, 15)
'fizz_buzz'
elsif has_zero_remainder?(number, 3)
'fizz'
elsif has_zero_remainder?(number, 5)
'buzz'
else
number
end
end
def ... | true |
cd21fe8e2f2c9637ac52c2f13f5dc2bc81b049f8 | Ruby | jacekm123/Zadania_Podstawowe | /zadanie2.rb | UTF-8 | 290 | 3.359375 | 3 | [] | no_license | #Zadanie2.
#Zadeklaruj zmienną przechowującą swoje imię, wypisz na ekran ostatnią literę swojego imienia.
imie = "Jacek"
jacek_tablica = imie.split("")
puts jacek_tablica
puts "Za pomoca elementu tablicy:"
puts jacek_tablica[4]
puts "Za pomoca metody last:"
puts jacek_tablica.last
| true |
7ca2cd20c181319178c233a3ff59fbc527a77536 | Ruby | xenfinity/Intro-to-Programming-Exercises | /4 - Loops & Iterators/3-Recursion.rb | UTF-8 | 167 | 3.421875 | 3 | [] | no_license | def count_down(num)
puts num
count_down(num-1) unless num == 0
end
def count_up(num)
count_up(num-1) unless num == 0
puts num
end
count_down(47)
count_up(47) | true |
f549801e9462df655febdf22cf3ec83099ed9f9f | Ruby | rednblack99/messenger-Wed | /spec/unit/message_unit_spec.rb | UTF-8 | 582 | 2.8125 | 3 | [] | no_license | require './lib/message.rb'
describe Message do
input = "this string is more than 20 characters"
let(:time_double) { DateTime.now.strftime("%d/%m/%Y %H:%M:%S:%L.%P") }
subject(:message) { described_class.create(:content => input) }
it 'stores given message as content' do
expect(message.content).to eq("this... | true |
6d38e00c6ce0a59f829472cc61cff3ed613fdfe9 | Ruby | fluffypancakes159/08zbuffer | /main.rb | UTF-8 | 5,187 | 2.75 | 3 | [] | no_license | require_relative 'line'
require_relative 'matrix'
require_relative 'transform'
require_relative 'curve'
require_relative 'solid'
require_relative 'polygon'
def main() # remember to change XRES and YRES
out = Array.new(YRES) {Array.new(XRES, [0, 0, 0])}
zbuffer = Array.new(YRES) {Array.new(XRES, nil)}
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.