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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
fb703daee0b1e6cd770294f45b44efdc741cecc8 | Ruby | metermaid/algorithms | /math/fibonacci.rb | UTF-8 | 488 | 3.9375 | 4 | [] | no_license | # Fibonacci
def fibonacci(n)
fibonacci_helper(0,1,n)
end
def fibonacci_helper(a,b,n)
if n == 0
a
else
fibonacci_helper(b,a+b,n-1)
end
end
def fibonacci(n) # recursive non-optimal solution… 2^n
if (n == 0 || n == 1)
return n
else
return fibonacci(n - 1) + fibonacci(n - 2)
end
end
def fibo... | true |
3a28fd7caaa9975b547e47f6bf57eb1792f640c9 | Ruby | RokkuRi/Gym-Lab | /ruby/learn_ruby_hard_way/20ex.rb | UTF-8 | 421 | 3.6875 | 4 | [] | no_license | input_file = ARGV[0]
def read_a_file(file)
file.read
end
def rewind_a_file(file)
file.seek(0)
end
def print_a_line(line_number, file)
puts "what line - #{line_number}, #{file.gets.chomp}."
end
current_file = File.open(input_file)
puts "Let's print the whole file:"
puts read_a_file(current_file)
puts "Let's rewi... | true |
fc16ea76f83aa2aa0890e9f648f16751c1fec034 | Ruby | panangad/projecteuler-ruby | /problems/problem_024.rb | UTF-8 | 530 | 4.03125 | 4 | [] | no_license | =begin
Problem 24
A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:
012 021 102 120... | true |
792833f3658fa333fcc8511f262db10d9fe75766 | Ruby | devinsiphone/RB101 | /lesson_2/mortgage_car_loan_calculator.rb | UTF-8 | 3,389 | 4.03125 | 4 | [] | no_license | # Take everything you've learned so far and build a mortgage calculator
# (or car payment calculator -- it's the same thing).
#
# You'll need three pieces of information:
#
# * the loan amount
# * the Annual Percentage Rate (APR)
# * the loan duration
#
# From the above, you'll need to calculate the following two thing... | true |
d1b713affd88c1c28613d3207c75b2047e24f5ec | Ruby | 47colborne/simple-currency-converter | /lib/simple_currency_converter.rb | UTF-8 | 605 | 2.875 | 3 | [
"MIT"
] | permissive |
module SimpleCurrencyConverter
class Client
def get_exchange_rate(from_currency, to_currency)
currency_name = from_currency.to_s + to_currency.to_s + '=X'
yahoo_query_url =
URI::HTTP.build(host:"download.finance.yahoo.com",path:"/d/quotes.csv", query:"s=#{currency_name}&f=l1d1t1&e=.csv")
... | true |
0a93927eabab891fa40a4bf15fc49dbf6234fc38 | Ruby | nange-ustb/kl | /app/models/keyword.rb | UTF-8 | 4,883 | 2.640625 | 3 | [] | no_license | # -*- encoding : utf-8 -*-
# == Schema Information
#
# Table name: keywords
#
# id :integer not null, primary key
# title :string(255)
# ancestry :string(255)
# is_child :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
#
cl... | true |
f5ee0e139233a197b2ab974fe8565d086a7aa2fe | Ruby | logankoester/grake | /test/test_grake.rb | UTF-8 | 1,221 | 2.71875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'helper'
class TestGrake < Test::Unit::TestCase
context "The example TaskTree" do
setup do
@task1 = ['food','pastry','cupcake']
@task2 = 'food:pastry:muffin'
@tasks = TaskTree.new('Tasks')
@tasks.add_task(@task1, "First example")
@tasks.add_task(@task2, "Second example")
... | true |
47254998ef5f43531a413a0f9e8d1ebf58444c43 | Ruby | hwgordon247/intro-to-web | /lib/app.rb | UTF-8 | 363 | 2.625 | 3 | [] | no_license | require 'sinatra'
require 'shotgun'
get '/' do
'Come fly with me, come fly, let\'s fly away..'
end
get '/secret' do
'yoyoyo'
end
get '/another' do
'can you read me?'
end
get '/random-cat' do
@name = %w(Felix Keith Burt).sample
erb(:index)
end
get '/cat-form' do
erb(:cat_form)
end
post '/named-cat' do
... | true |
bb4923171fbbeed92513f0caceaf89f87d065389 | Ruby | complete12/coderbyte | /AlphabetSoup.rb | UTF-8 | 443 | 3.296875 | 3 | [] | no_license | def AlphabetSoup(str)
# code goes here
chars = str.chars.to_a
chars.each_index do |i|
(chars.length - i - 1).times do |job|
if chars[job] > chars[job + 1]
chars[job], chars[job + 1] = chars[job + 1], chars[job]
end
end
end
return chars.join('')
end
# keep this ... | true |
4cdeb8acc76b1bb86192b615bfc60dc5fed09a70 | Ruby | ksutikm/2020-spring-ruby | /test/lib/station_in_stock.rb | UTF-8 | 157 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
class StationInStock
attr_reader :code, :title
def initialize(code, title)
@code = code
@title = title
end
end
| true |
380126361f2243e0838d485869a9583e61bdc4b2 | Ruby | refinery/refinerycms | /core/lib/refinery/engine.rb | UTF-8 | 1,712 | 2.625 | 3 | [
"MIT"
] | permissive | module Refinery
module Engine
# Specify a block of code to be run after the refinery inclusion step. See
# Refinery::Core::Engine#refinery_inclusion for details regarding the Refinery
# inclusion process.
#
# Example:
# module Refinery
# module Images
# class Engine < Rails... | true |
08d09a8191f577fb1b692ff13bcc3e9350fbcf48 | Ruby | Caveman07/Chess-game | /lib/field.rb | UTF-8 | 355 | 3.140625 | 3 | [] | no_license | class Field
attr_reader :coords, :color
attr_accessor :figure
def initialize(coords)
@coords = coords
@color = set_color(coords)
@figure = nil
end
def set_color(coords)
if coords.y % 2 == 0
coords.index % 2 == 0 ? "\u2593" : " "
else
coords.index % 2 == 0 ? " " : "\u2593"
... | true |
0d969b6f1639be78ccd09c2c44db84f917c9b64a | Ruby | andrewdwooten/enigma | /lib/decrypt.rb | UTF-8 | 344 | 2.671875 | 3 | [] | no_license | require_relative 'encrypt.rb'
require 'pry'
encrypted_file = File.open(ARGV[0], "r")
to_decrypt = encrypted_file.read
encrypted_file.close
decrypted_message = f.decrypt(to_decrypt)
decrypted_file = File.open(ARGV[1], "w")
decrypted_file.write(decrypted_message)
decrypted_file.close
puts "Created #{ARGV[1]} with or... | true |
5e4caf9009203b09e10703c92f246e7ffb615a81 | Ruby | juniorjp/parking | /app/models/parking.rb | UTF-8 | 509 | 2.53125 | 3 | [] | no_license | class Parking < ApplicationRecord
#In the future the client may want new kinds of status, example: overnight
enum status: {
in_progress: 0,
finished: 1
}, _prefix: :status
validates :plate, presence: true
validates_format_of :plate, with: /\A\w{3}\-\d{4}\z/
def self.create_default(plate)
park... | true |
d64f5a4d486973248c72ae4af95baf59c13a9708 | Ruby | fearoffish/rehabilitate | /lib/rehabilitate/plugins/s3.rb | UTF-8 | 3,905 | 2.625 | 3 | [] | no_license | require 'rehabilitate/plugin'
require 'rehabilitate/plugins/splitter'
require 'fog'
require 'yaml'
class S3 < Rehabilitate::Plugin
def list(options)
location = parse_upload_string(options.location)
s3 = setup_fog(location)
log "Listing bucket contents for #{location[:bucket]}"
dir = s3.directories.g... | true |
a90f84340fb42bfbb17403afa656c1e9e5427840 | Ruby | StevenXL/learntoprogram | /chapter_13_creating_new_classes_changing_existing_ones/orange_tree.rb | UTF-8 | 1,382 | 4.46875 | 4 | [] | no_license | # =============================================================================
# Orange Tree
# =============================================================================
class OrangeTree
def initialize(name=nil)
@height = 0
@age = 0
@name = name
@oranges = 0
end
def he... | true |
d96c19969d81a400e9976ee706985002913ba4c1 | Ruby | kirubahari76/rubylearning | /ex1.rb | UTF-8 | 275 | 3.53125 | 4 | [] | no_license | #puts "Hello World"
puts "Hello Again"
puts "I LIke Typing thiS"
puts "This is fun"
puts "Yay! Printing."
puts 'I "said" do not touch this.'
puts "I'd much rather you 'not'."
puts "puts actually does printing what's inside the double quotes("") or single quotes('')"
| true |
692c830591228e389edf336ef6c6c5d4e061b809 | Ruby | Instagram/fog | /lib/fog/rackspace/examples/compute_v2/delete_image.rb | UTF-8 | 1,818 | 3.140625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# This example demonstrates deleting a server image with the Rackpace Open Cloud
require 'rubygems' #required for Ruby 1.8.x
require 'fog'
def get_user_input(prompt)
print "#{prompt}: "
gets.chomp
end
def select_image(snapshot_images)
abort "\nThere are not any images to delete in the Chic... | true |
926f65caa2e1fa335336e315e951e62cc4860118 | Ruby | jeffreybasurto/CoralMud | /lib/CMI/client.rb | UTF-8 | 682 | 2.5625 | 3 | [] | no_license | require 'eventmachine'
load 'lib/CMI/packet.rb'
$cmiclient = nil
module Rclient
def post_init
$cmiclient = self
send_data Packet.login("CoralMud")
end
def receive_data data
# TODO need to make some way to capture and ensure a full packet is being sent.
# Probably a delimiter but maybe just usin... | true |
22ad8a91cd605a56f340dbcfc8cf741125ab5f6c | Ruby | jasonsutter87/Algorithm-Practice | /arrays_and_strings/array_and_string_spec/is_unique_spec.rb | UTF-8 | 594 | 2.78125 | 3 | [
"MIT"
] | permissive | require_relative('../is_unique')
describe 'detects if characters are unique in a word' do
let(:word1) {"jason"}
let(:word2) {"banana"}
let(:word3) {"cool"}
let(:word4) {"cat"}
it 'Should return true, since nothing repeats' do
expect(is_unique(word1)).to eq(true)
end
it 'Should return true, since nothing rep... | true |
66d9614270bd1ff0299a8c55b20e3c0a34259593 | Ruby | julienemo/thp-6-rubytests | /lib/03_basics.rb | UTF-8 | 1,147 | 3.84375 | 4 | [] | no_license | def who_is_bigger(a,b,c)
my_array = [a, b, c]
if my_array.include? nil
return "nil detected"
elsif my_array.uniq != my_array
return "duplicate detected"
elsif my_array.max == a
return "a is bigger"
elsif my_array.max == b
return "b is bigger"
else
return "c is bigger"
end
end
def r... | true |
e718bb48f945383e13613a2ccd5289152eab76a3 | Ruby | tonyvalencia/Mood_Project | /app.rb | UTF-8 | 656 | 2.53125 | 3 | [] | no_license | require 'bundler'
Bundler.require
require_relative 'lib/tumblr.rb'
class MyApp < Sinatra::Base
get '/' do
erb :index
end
post '/' do
url = params[:site]
@blog = Blog.new(url)
@url_array = @blog.post_body
if url == "gif-guy.tumblr.com"
@mood = "Funny"
elsif url == "graceinitiatessar... | true |
ce239dc83df840eb1248f84f4bed8cd62e5e258d | Ruby | GSergeevich/ruby | /exercises/5.rb | UTF-8 | 892 | 3.5625 | 4 | [] | no_license | # frozen_string_literal: true
class Point
def set_x(x)
@x = x
end
def set_y(y)
@y = y
end
attr_reader :x
attr_reader :y
end
point1 = Point.new
point2 = Point.new
point1.set_x(3)
point1.set_y(6)
point2.set_x(-1)
point2.set_y(5)
puts Math.sqrt((point1.x - point2.x)**2 + (point1.y - point2.y)**... | true |
dacb26def8a026fbae78b038ba9f6318d56999af | Ruby | TWSummer/W1D5 | /knight_path_finder.rb | UTF-8 | 771 | 3.46875 | 3 | [] | no_license | class KnightPathFinder
def initialize(starting_point)
@starting_point = starting_point
@move_tree = {}
end
def build_move_tree
queue = [@starting_point]
until queue.empty?
cur_pos = queue.shift
new_moves = KnightPathFinder.valid_moves(cur_pos)
end
end
def self.valid_moves(po... | true |
5f98cb1122cd8508c7db77a38e3a23babef18e9a | Ruby | jnk9/wapii-net-app | /app/adapters/jsonplaceholder/post.rb | UTF-8 | 2,023 | 2.71875 | 3 | [] | no_license | module Jsonplaceholder
class Post < Base
def initialize; end
def all(start = nil, limit = nil)
response = self.class.get("/posts?_start=#{start}t=&_limit=#{limit}")
posts = JSON.parse(response.body)
add_hash_count_comments(posts)
add_hash_name(posts)
add_hash_comments(posts)
... | true |
e0ae2ec00c5ff675ff0cb529e658070409508adc | Ruby | dentearl/mus_strain_cactus | /pipeline/src/getMostChangedStats.rb | UTF-8 | 1,777 | 2.90625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'set'
require 'nokogiri'
(warn "Usage: #{$0} statsXML1 statsXML2"; exit(1)) if ARGV.size != 2
MIN_TRANSCRIPT_FRAC=0.02 # Minimum % of transcripts that a tag must
# apply to for it to be reported
def get_transcripts_per_tag(xml)
h = {}
xml.traverse { |node| h[no... | true |
4630fa459e8005ea735d4544c799d2009118412f | Ruby | matheusbergue/shotflix | /_plugins/aa.rb | UTF-8 | 2,619 | 3.1875 | 3 | [] | no_license | require 'rest-client'
require 'json'
def teste()
api = 'd8dd86fe3d3bb9be9edf5dabc8aac0f1'
erro = 'awdawsuawhdiud654aw6s84a8wd8455'
url = "https://api.themoviedb.org/3/movie/392044?api_key=#{api}&language=pt-BR"
resp = RestClient.get url
enviar = {
title: JSON.parse(resp.body)['title... | true |
41e97af0fc070d671522aca5afbef238dfa72ea0 | Ruby | treylavergne/sql-library-lab-onl01-seng-pt-021020 | /lib/querying.rb | UTF-8 | 1,021 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
"SELECT title, year FROM books WHERE books.series_id = 1 ORDER BY books.year;"
end
def select_name_and_motto_of_char_with_longest_motto
"SELECT name, motto FROM characters ORDER BY LENGTH(motto) DESC LIMIT 1 ;"
end
def select_value_and_count_of_mos... | true |
67e9c41e6c734863fc0bdc51600649047057bf1f | Ruby | tulios/better_helpers | /lib/better_helpers/hash_hierarchy_to_class.rb | UTF-8 | 817 | 3 | 3 | [
"MIT"
] | permissive | module BetterHelpers
class HashHierarchyToClass
def initialize hash, parent_class
@hash = hash
@parent_class = parent_class
end
def apply
value = apply_to_class @hash, @parent_class.new
@hash.keys.first.nil? ? value : @parent_class.new
end
private
def apply_to_class ... | true |
30f0b5d17451cef128c9dcad60baf89dc63560f5 | Ruby | nicolashodee/thp-week2-day2 | /exo_18.rb | UTF-8 | 194 | 3.078125 | 3 | [] | no_license | counter = 0
my_array= Array.new
while (counter <= 50)
my_array << "jean.dupont0#{counter}@email.fr"
puts "Counter is at #{counter} and the corresponding array is #{my_array[counter]}"
counter = counter + 1
end
| true |
42ac7cb86fc2cc2d54a296f4a5739ac83f3ab1e4 | Ruby | lstrzebinczyk/Zemanta | /lib/zemanta/cache/disk.rb | UTF-8 | 381 | 2.6875 | 3 | [
"MIT"
] | permissive | module Zemanta
module Cache
class Disk
attr_accessor :db
def initialize(directory='tmp/db')
@db = Pathname.new(directory)
@db.mkpath
end
def [](key)
file = @db.join(key)
file.read if file.exist?
end
def []=(key,value)
@db.join(key).ope... | true |
ca858a58c82b383eaeeb93c15eb04c56b52d7e63 | Ruby | AdrianSmith/geom | /spec/geom/point_spec.rb | UTF-8 | 7,067 | 3.34375 | 3 | [
"MIT"
] | permissive | require_relative '../spec_helper.rb'
require 'geom/point'
module Geom
describe Point do
before do
@valid_attributes = [1.1, -2, 10]
end
describe "Construction" do
it "should create a valid instance from an array of coordinates" do
point = Point.new(@valid_attributes)
expect(p... | true |
e9d115408012254d904896e8f26b3d5b94f7c926 | Ruby | WeTransfer/image_vise | /lib/image_vise/operators/fit_crop.rb | UTF-8 | 1,241 | 2.984375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Fits the image based on the smaller-side fit. This means that the image is going to be fit
# into the requested rectangle so that all of the pixels of the rectangle are filled. The
# gravity parameter defines the crop gravity (on corners, sides, or in the middle).
#
# The corresponding Pipeline method is `fit_crop`.
... | true |
9781c02920afd3045d97876c182cab0bfb7a78e6 | Ruby | lightyrs/imdbee | /app/models/data_miner.rb | UTF-8 | 704 | 2.703125 | 3 | [] | no_license | class DataMiner
def self.roles
{
actor: 1,
actress: 2,
producer: 3,
writer: 4,
cinematographer: 5,
composer: 6,
costume_designer: 7,
director: 8,
editor: 9,
miscellaneous_crew: 10,
production_designer: 11,
guest: 12
}
end
def self.n... | true |
3ac487021e4b896a2b32bf317902922f06e8d757 | Ruby | gabrielecirulli/supernova | /lib/supernova/remote/common/event_handler.rb | UTF-8 | 5,370 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'set'
require 'supernova/remote/common/event_handler/event'
module Supernova
module Remote
module Common
# Handles events sent to the receiver to be processed.
module EventHandler
# Class methods.
module ClassMethods
# A list of all of the events defined in the cl... | true |
503c04ac1ac9bd288b7253d680244f949c6d40ba | Ruby | fatkodima/bundler-visualize | /lib/bundler/visualize/command.rb | UTF-8 | 2,389 | 2.546875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "bundler/visualize/graph"
require "bundler"
require "optparse"
module Bundler
module Visualize
class Command
def initialize
Bundler.ui = UI::Shell.new
end
def exec(_command, args)
options = parse_options(args)
options = defaults.m... | true |
7f49cf4aeec2cac3a7adf155d9e07dff76cc7dc2 | Ruby | Impicklerick12/git-ca-repo | /term2/rails-projects/gumball_machine/model.rb | UTF-8 | 579 | 3.484375 | 3 | [] | no_license | # MODEL
# Check the stock
# Dispense a gumball
# refill of the gumball machine
class GumballModel
attr_accessor :gumballs
def initialize(gumballs)
@gumballs = gumballs
end
#check the stock
def check_stock
return @gumballs
end
#dispense a gumball
def dispense_gumball
... | true |
5ea95232ab2ee607908a9d4179340fceeaebc65b | Ruby | epitron/scripts | /timestamp | UTF-8 | 803 | 3.125 | 3 | [] | no_license | #!/usr/bin/env ruby
def usage
puts DATA.read
end
def nice_stamp(usec=false)
# %L = usec, %N = nsec
fmt = usec ? "%Y-%m-%d %H:%M:%S:%L" : "%Y-%m-%d %H:%M:%S"
Time.now.strftime(fmt)
end
args = ARGV
if STDIN.tty?
if args.delete("--help") or args.delete("-h")
usage
exit
elsif args.delete("-n") or ar... | true |
f61e1e1c3c731b982784e9500473355bc6a8529e | Ruby | cowens87/whether_sweater | /app/poros/roadtrip.rb | UTF-8 | 546 | 3 | 3 | [] | no_license | class Roadtrip
attr_reader :start_city,
:end_city,
:travel_time,
:weather_at_eta
def initialize(data, origin, destination, weather)
@start_city = origin
@end_city = destination
if data[:info][:statuscode] == 402
@travel_time = 'impossible route'
@we... | true |
c0ebc4ee85b4307be37e306773d653b5c12cec37 | Ruby | leachj/led-screen | /screen.rb | UTF-8 | 1,915 | 3.15625 | 3 | [] | no_license | require "serialport"
require "color"
class Screen
def initialize(brightness,width, height)
#params for serial port
port_str = "/dev/ledScreen" #may be different for you
baud_rate = 115200
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
@sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits,... | true |
f0d94c5722db9f74519032fc6470dcbd07a57d70 | Ruby | panicbus/WDI_week1_guestbook | /sinatra/main.rb | UTF-8 | 478 | 2.875 | 3 | [] | no_license |
require 'sinatra'
require 'sinatra/reloader'
@title = "Calculator"
get '/subtract/:first_num/:second_num' do
@result = params[:first_num].to_i - params[:second_num].to_i
@result.to_s
erb :myview
end
# get '/greet/:name' do
# @title = "Greeter"
# @name = params[:name].capitalize
# @wish = "Hello, "
# ... | true |
226bf9be573dc928b417133b3f29a4c27e06bc76 | Ruby | thoran/startor | /lib/String/each.rb | UTF-8 | 418 | 3.265625 | 3 | [] | no_license | # String#each
# 20120330
# 0.0.0
# Description: Ruby 1.9 no longer mixes in Enumerable, so here's String's missing #each method. See String#each_line and String#each_char for the specific implementations.
require 'String/each_char'
require 'String/each_line'
class String
def each(unit = :line, &block)
c... | true |
36bcb0a8b20b1aabf2c70b24c57254ded4056c8b | Ruby | lepesevichnikita/polessu-timetable | /app/repositories/lessons_repository.rb | UTF-8 | 1,453 | 2.65625 | 3 | [] | no_license | # Provide functionality for lessons management
class LessonsRepository < MongoidDocumentRepository::Base
# @type [Hash] Required entities and types
REQUIRED_ENTITIES_AND_KEYS = {
teacher: 'teacher_id',
group: 'group_id'
}.freeze
# @param [Hash] params Params for lessons getting
def self.by_params(par... | true |
4c6a775c22e5ef5095a5d6b142e1ba0742f0750e | Ruby | osmondvail81/geekmap | /vendor/plugins/needs_approval/lib/needs_approval.rb | UTF-8 | 1,331 | 2.78125 | 3 | [
"MIT"
] | permissive | module NeedsApproval
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods
def needs_approval(options={}, &block)
cattr_accessor :ladder
cattr_accessor :approval_block
self.approval_block = block
self.ladder = options[:ladder]||false
include Inst... | true |
c5cdfce6bc15416d664c3bf2e8d6f4346178aab2 | Ruby | tafujino/vcreport | /lib/vcreport/report/sample/vcf_collection.rb | UTF-8 | 1,847 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'fileutils'
require 'vcreport/chr_region'
require 'vcreport/report/sample/vcf'
module VCReport
module Report
class Sample
class VcfCollection
# @return [String]
attr_reader :program_name
# @return [Array<Vcf>]
attr_reader :vcfs
... | true |
a2ce62718ab3de6a09bc7e9a2fa232961eec5ebe | Ruby | jocelynk/Urban-Impact-Events-Manager | /lib/tasks/populate.rake | UTF-8 | 10,732 | 2.765625 | 3 | [] | no_license | namespace :db do
desc "Erase and fill database"
# creating a rake task within db namespace called 'populate'
# executing 'rake db:populate' will cause this script to run
task :populate => :environment do
# Invoke rake db:migrate just in case...
Rake::Task['db:migrate'].invoke
# Need two gems to... | true |
fbd3b03005b06ec34199b87bcb283ebb6ffe7a24 | Ruby | iamshayankarami/super_private_web_browser | /get_request.rb | UTF-8 | 244 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | require "socket"
host = ARGV[0]
port = ARGV[1]
path = ARGV[2]
request = "GET #{path} HTTP/1.0\r\n\r\n"
socket = TCPSocket.open(host, port)
socket.print(request)
response = socket.read
headers, body = response.split("\r\n\r\n", 2)
print body
| true |
23744539df5e73191d43e39dd4273674ae9dca4b | Ruby | MitulMistry/rails-storyplan | /spec/controllers/stories_controller_spec.rb | UTF-8 | 10,453 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
RSpec.describe StoriesController, type: :controller do
# kaminari page
shared_examples_for "public access to stories" do
describe "GET #index" do
it "populates an array of stories per page (by creation date)" do
story1 = create(:story)
story2 = create(:story)
... | true |
e530969be09b58aad1f13a22cc05ff9b50fdd260 | Ruby | nikushi/code_golf_rb | /app.rb | UTF-8 | 1,001 | 2.5625 | 3 | [] | no_license | require 'sinatra'
require "sinatra/reloader" if development?
require 'json'
require 'pp'
require_relative 'router'
also_reload './router.rb'
get '/' do
map = [
[5,5,4,2,1,1,1,2,2,3],
[5,4,3,2,1,1,2,2,3,4],
[5,4,2,1,1,2,2,4,5,5],
[4,4,2,1,2,2,3,3,4,5],
[4,3,1,1,4,3,3,3,4,5],
[3,1,1,5,4,3,2,3,... | true |
bd481dd153930b6a580346d299eb9c5ca39e2872 | Ruby | daiwaka/jiji2 | /src/jiji/utils/strings.rb | UTF-8 | 276 | 2.59375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Jiji::Utils
class Strings
def self.mask(string, length = 1)
return '' unless string
return 'x' * string.length if string.length - length <= 0
string[0, length] + 'x' * (string.length - length)
end
end
end
| true |
6bcc15b5dd2001ea7d9822a39a8c0ce8d399ac1e | Ruby | Machi427/ruby_scripting | /sample_scripts/lecture02/kprintf.rb | UTF-8 | 542 | 2.84375 | 3 | [] | no_license | # kanji-aware printf for both Ruby1.8 or 1.9+
class String
require 'kconv'
if defined?("".force_encoding)
def toeucbin()
self.toeuc.force_encoding("binary")
end
else
def toeucbin()
self.toeuc
end
end
end
class IO
def printf(*args)
out = sprintf(*(args.collect{|x| x.is_a?(Strin... | true |
45ee1b394de894a8145e847396e7e9a3ddc43802 | Ruby | daveb1392/sinatra-mvc-file-structure-london-web-062419 | /app/models/dog.rb | UTF-8 | 326 | 4 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog
attr_accessor :name, :breed, :age
DOGS = [] # empty array to keep track of all dogs.
def initialize(name, breed, age) #initialize with 3 arguments.
@name = name
@breed = breed
@age = age
DOGS << self #showell into empty DOGS array.
end
def self.all #keeps track of all dogs.
DOGS
en... | true |
e118bb7cc189bd9531698dc3376abe4a71226d93 | Ruby | j10nelson/ruby-fundamentals-part2 | /exercise6.rb | UTF-8 | 1,127 | 3.8125 | 4 | [] | no_license | grocery_list = ["carrots", "toilet paper", "apples", "salmon"]
def output_list(v)
v.each do |i|
p "* " + i
end
end
p output_list(grocery_list)
# You realize you've forgotten some rice, so add it to your list and output it again.
p "the grocery_list after the rice is added:"
grocery_list << "rice"
output_lis... | true |
09ab2ffeb847e18ff8a486cf74c9de0d87db4aad | Ruby | eveyv/star-fleet.rb | /server.rb | UTF-8 | 1,909 | 2.734375 | 3 | [] | no_license | require 'sinatra'
require_relative 'config/application'
set :bind, '0.0.0.0' # bind to all interfaces
enable :sessions
# Any classes you add to the models folder will automatically be made available in this server file
get '/' do
redirect '/starships'
end
get '/starships/new' do
erb :'starships/new'
end
pos... | true |
e40d1a53871632b6333801990371e35b0f2f88e5 | Ruby | MargaretLangley/letting | /lib/tasks/import/import_invoice_texts.rake | UTF-8 | 606 | 2.5625 | 3 | [] | no_license | require 'csv'
####
# Import InvoiceText
#
# These are the texts used in the invoices
#
####
namespace :db do
namespace :import do
filename = 'import_data/new/invoice_texts.csv'
desc 'Import invoice text from CSV file'
task :invoice_texts do
if File.exist?(filename)
CSV.foreach(filename, head... | true |
2d9e7343a175e465d4e19153c3e4d406b39778b4 | Ruby | ThomasC222/rails-yelp-mvp | /db/seeds.rb | UTF-8 | 1,168 | 2.578125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
9850d310667481e7fcbba169baeb8a7d938194de | Ruby | tjaRoxasXIII/Pingsurance | /app/models/lead.rb | UTF-8 | 440 | 2.828125 | 3 | [] | no_license | class Lead < ApplicationRecord
validates :first_name, :last_name, presence: true
def full_name
return self.first_name + " " + self.last_name
end
# Method should only be called on un-formatted numbers during Lead creation
def format_phone_number
area_code = self.phone_number.slice!(... | true |
141638b844104d38cb9fabf1e3c8afd7aa27f414 | Ruby | catalistt/Desafios-arreglos-archivos | /proyecciones.rb | UTF-8 | 1,155 | 3 | 3 | [] | no_license | file = File.open('./ventas_base.db').read
file = file.split(',')
file = file.map!{|num| num.to_f}
#OPCIÓN 1 - SEGÚN LO VISTO EN CLASES
def forecast(sales, p_variation, first_month, last_month)
i_start = first_month - 1
i_end = last_month - 1
sum_extra= sales[i_start..i_end].sum
aumento = sum_extra *... | true |
411a10795e06bb1da478c1a9f2b4160f9b50d08e | Ruby | spejamchr/sia | /lib/sia/safe.rb | UTF-8 | 8,838 | 2.921875 | 3 | [
"MIT"
] | permissive | module Sia
# Keep all the files safe
#
# Encrypt files and store them in a digital safe. Have one safe for
# everything, or use individual safes for each file to be encrypted.
#
# When creating a safe provide at least a name and a password, and the
# defaults will take care of the rest.
#
# safe =... | true |
9e550fd575268bb09c926bccc9f88dac87e59375 | Ruby | Fennic08/Ruby | /Arrays_I/Access_Single_Element_by_Index_Position.rb | UTF-8 | 152 | 3.25 | 3 | [] | no_license |
fruits = ["Apple", "Orange", "Grape", "Banana"]
# p fruits[0]
# p fruits[1]
# p fruits[3]
#
# p fruits[10]
# p fruits[100]
# p fruits[5]
p fruits[-3]
| true |
28430e7467ecb615aeace291d8631de9700ac2a7 | Ruby | adamcreekroad/interpreter | /ast/var.rb | UTF-8 | 134 | 2.75 | 3 | [] | no_license | class Var < AST
attr_accessor :token, :value
def initialize(token)
self.token = token
self.value = token.value
end
end
| true |
c36bcac3f767ca6998f8763eac3e410e6b5a3b24 | Ruby | amelian94/LPP_M_5_P8 | /lib/exam/examen.rb | UTF-8 | 199 | 2.765625 | 3 | [
"MIT"
] | permissive | class Examen
attr_accessor :exam, :npreguntas
def initialize(n)
@exam= Doble_list.new
@npreguntas=n
end
def add_pregunta(pre)
@exam.push_fin(pre)
end
end | true |
60d3a2d113fff5107c3ecd87313c0cfc77bc6461 | Ruby | janno-p/project-euler | /problems/problem_089/solution.rb | UTF-8 | 1,115 | 3.671875 | 4 | [] | no_license | #!/usr/bin/env ruby
values = {
1 => :i,
4 => :iv,
5 => :v,
9 => :ix,
10 => :x,
40 => :xl,
50 => :l,
90 => :xc,
100 => :c,
400 => :cd,
500 => :d,
900 => :cm,
1000 => :m
}
def decode(literal, values)
number = 0
str = literal.downcase
values.reverse_each do |value, roman|
roman_number... | true |
c296cb8a9d70e71af5a63c6e860b6474f6b3ddac | Ruby | LagoLunatic/DSVEdit | /dsvlib/area.rb | UTF-8 | 2,270 | 2.90625 | 3 | [
"MIT"
] | permissive |
class Area
class AreaReadError < StandardError ; end
attr_reader :area_index,
:fs,
:game,
:area_ram_pointer,
:sectors
def initialize(area_index, game)
@area_index = area_index
@fs = game.fs
@game = game
read_from_rom()
end
def rea... | true |
8c3cc404671895a66674c3757d2b204f193fad3c | Ruby | deepak23verma/ruby_fundamentals | /prime_factors.rb | UTF-8 | 802 | 3.875 | 4 | [] | no_license | # # def prime_factors(num)
# #Get a number
# def prime_factors(num)
# #Find all its factorals and add to a new array
# factors = []
# digit = 0
# num.times do
# digit += 1
# if num % digit == 0
# factors << (num / digit)
# end
# end
# #check if each factorial is a prime number
# factors.each do |first... | true |
2c2e85dd88f9ed1203f2bb70228f214c48aae0cd | Ruby | voodoorai2000/Intro-Rails-Febrero-2011-Ejercicios | /dia_2_ejercicios/1bank/bank.rb | UTF-8 | 923 | 3.578125 | 4 | [] | no_license | #crear una clase "Bank"
class Bank
#crear un "attr_accessor" para las variables "revenue" y "costs"
attr_accessor :revenue, :costs
#crear un metodo initialize
#que inicialice las variables de instancia "revenue" y "costs" a cero
def initialize
@revenue = 0
@costs = 0
end
#crear un metodo "credit"
#que... | true |
3e30c4086790695b9ac43c1deab56998ce035cf5 | Ruby | antoniairizarry/Hashmap-Questions | /lib/permutations.rb | UTF-8 | 460 | 3.5 | 4 | [
"MIT"
] | permissive | def permutations?(string1, string2)
return true if string1 == string2
return false if string1.length != string2.length
hash = {}
string1.split('').each do |letter|
if hash[letter]
hash[letter] += 1
else
hash[letter] = 1
end
end
string2.split('').each do |letter|
return f... | true |
e334fbb09031fd1d00d507726a36df8390545098 | Ruby | JoeG21/houston-se-071320 | /05-oo-review/tools/console.rb | UTF-8 | 1,098 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
# Insert code here to run before hitting the binding.pry
# This is a convenient place to define variables and/or set up new object instances,
# so they will be available to test and play around with in your console
microsoft = S... | true |
f45aa895350de515b317f41fe01da36ac36b1bb6 | Ruby | rubydoc/fog | /lib/fog/rackspace/requests/queues/create_message.rb | UTF-8 | 2,383 | 2.59375 | 3 | [
"MIT"
] | permissive | module Fog
module Rackspace
class Queues
class Real
# This operation posts the specified message or messages.
# @note You can submit up to 10 messages in a single request.
#
# @param [String] client_id UUID for the client instance.
# @param [String] queue_name Speci... | true |
15ad869838ea764e3a6c2b8a2b6cbdc5312f2e8e | Ruby | takagotch/rb | /ruby/thread.rb | UTF-8 | 390 | 3.109375 | 3 | [] | no_license | require 'thread'
#BankAccount
class BankAccount
def initialize(name, checking, savings)
@name,@checking,@savings = name,checking,savings
@lock = Mutex.new
end
#transaction
def transfer_from_savings(x)
@lock.synchronize{
@savings -= x
@checking += x
}
end
def report
@lock.synchroni... | true |
f11c2eeca005ce07a4ce7a2463e1f0c79604c9f3 | Ruby | ZuhairS/URL-Shortener | /URLShortener/bin/cli.rb | UTF-8 | 920 | 3.28125 | 3 | [] | no_license | require 'launchy'
puts "Input your email:"
email = gets.chomp
raise 'You are not a valid user!' unless User.exists?(['email = ?', email])
user = User.find_by(email: email)
puts "\n"
puts "What do you want to do?"
puts "0. Create shortened URL"
puts "1. Visit shortened URL"
choice = gets.chomp
raise 'Invalid choice... | true |
7dc9ad5bfb6ee3a916883b36eb0ed300fa719710 | Ruby | rubyworks/assay | /work/defunct/assertable_module/assertions/nil.rb | UTF-8 | 680 | 2.984375 | 3 | [
"BSD-2-Clause",
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'assertion'
require 'ae/assertable'
class IsNilFailure < Assertion
def self.assertion_name
:nil
end
def fail_message(exp)
"Expected #{exp} to be nil"
end
def fail_message!(exp)
"Expected #{exp} to NOT be nil"
end
def self.check(obj)
obj.nil?
end
end
module Assertable
# Pas... | true |
653988d6bb59af308114cc0859f11933e930626e | Ruby | marras/contour | /ogarnij_clicki.rb | UTF-8 | 708 | 2.53125 | 3 | [] | no_license | #!/usr/bin/env ruby
require './constraints'
params = %w(phi charge diam Salt alpha)
fh = File.open("last_choice", "rt")
constr_string = fh.gets.split
constr_string.delete_at 2 # ingore the z axis
columns, constraints = Constraint.parse_args(constr_string, params)
p constraints
puts
fdata = File.open("clicks.dat", ... | true |
4230707d10f4c2b7f5f9710a324616103e9d6347 | Ruby | archivesspace/archivesspace | /backend/app/model/mixins/directional_relationships.rb | UTF-8 | 4,658 | 2.953125 | 3 | [
"ECL-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | require_relative 'relationships'
# This extends regular relationships to add support for storing a relationship
# between two records where the direction of the relationship matters. For
# example, a relationship between two agents might be called "is_parent_of" when
# viewed from one side, and "is_child_of" when vie... | true |
7659fd1af4291e9b8ccd19c9cb04dcc19386e7ca | Ruby | atae/w3d2 | /aa_questions/model_base.rb | UTF-8 | 1,812 | 2.625 | 3 | [] | no_license | require 'byebug'
class Base
DATABASES = {:User => 'users',
:Question => 'questions',
:QuestionLike => 'question_likes',
:Reply => 'replies',
:QuestionFollow => 'question_follows'}
def self.all
object_type = self.to_s.to_sym
data = QuestionDBConnectio... | true |
009f805a16ba6b6f46e5c89807f8d5384c676fea | Ruby | AJ8GH/ruby-udemy | /Classes/getter_and_setter_methods.rb | UTF-8 | 3,229 | 4.09375 | 4 | [] | no_license | class Gadget
def initialize
@username = "User #{rand(1..100)}"
@password = 'topsecret'
@production_number = "#{[*'a'..'z'].sample}-#{rand(1..99)}"
end
def to_s
"Gadget #{@production_number} has the username #{@username}.
It is made from the #{self.class} class and it has the ID #{self.object_... | true |
8dfe96a4a7d25b0521ef4bd4282fba58faba4c77 | Ruby | nurlywhirly/Scrabble | /specs/Scoring_spec.rb | UTF-8 | 2,095 | 3.3125 | 3 | [] | no_license | require_relative 'spec_helper'
require_relative '../Scoring.rb'
describe Scrabble::Scoring do
it "should have a scoring chart" do
Scrabble::Scoring::SCORE_CHART.wont_be_nil
end
describe "#initialize" do
it "should create a new instance of Scoring" do
Scrabble::Scoring.new.must_be_instance_of(Scr... | true |
9b66f8231f79aceace27b8dfdc0263de695605aa | Ruby | daschne8/advanced-hashes-hashketball-online-web-prework | /hashketball.rb | UTF-8 | 2,923 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def game_hash
hash = {
home: {
team_name:"Brooklyn Nets",
colors:["Black", "White"],
players: {
"Alan Anderson" => {number:0,shoe:16,points:22,rebounds:12,assists:12,steals:3,blocks:1,slam_dunks:1},
"Reggie Evans" => {number:30,shoe:14,points:12,rebounds:12,assists:12,steals:12,b... | true |
6dfa9f68bd0cd8a77d163858f36c35423497d5ba | Ruby | newtypeV2/oo-relationships-practice-dc-web-051319 | /app/IMDBModels/Character.rb | UTF-8 | 424 | 3.328125 | 3 | [] | no_license | class Character
@@all = []
attr_reader :name,:actor
def initialize(name,actor)
@name = name
@actor = actor
@@all << self
end
def self.all
@@all
end
def get_movies
Character_Movie.all.select {|cast| cast.character == self}
end
def movies_count
self.get_movies.count
en... | true |
d52dfe8c6e224e6be3f2a04a05465df233aab97b | Ruby | darrenburgess/launch-school-object-oriented-programming | /lesson_01/parent_child.rb | UTF-8 | 192 | 3.265625 | 3 | [] | no_license | class Parent
def say_hi
p "hi from parent"
end
end
class Child < Parent
def say_hi
p "hi from child"
end
end
son = Child.new
son.send :say_hi
puts son.instance_of? Parent
| true |
f617f04ad6b82412bed0bff5ce2b98d95b9c2e06 | Ruby | esther-ng/algorithms | /stack/stack.rb | UTF-8 | 605 | 3.609375 | 4 | [] | no_license | require_relative '../linkedlist/linked_list_example'
# Attributes:
# LIFO - Last In First Out
# Everything works in relation to the top of the Stack
# Each item on the stack is an element of a Linked List.
# An item has a value, but also has a pointer to another
class Stack
def initialize
@current = nil
end
... | true |
b728a2159648a5b24001e02059912e112376680d | Ruby | Anna3005ka/crashlytics-services | /lib/service/http.rb | UTF-8 | 4,494 | 3.015625 | 3 | [
"MIT"
] | permissive | module Service
module HTTP
# Public: Makes an HTTP GET call.
#
# url - Optional String URL to request.
# params - Optional Hash of GET parameters to set.
# headers - Optional Hash of HTTP headers to set.
#
# Examples
#
# http_get("http://github.com")
# # => <Faraday::R... | true |
5feb72864b03895f2ef29d98d5d27c6ed32c7c55 | Ruby | exosty/educational_competitions | /mastermind/mastermind/scratch-files/old_print.rb | UTF-8 | 850 | 3.4375 | 3 | [] | no_license | module Printer
ROW_TOP_BOTTOM_BORDER = '----'
ROW_LEFT_RIGHT_BORDER = '|'
def self.print_row rows
top = (rows.length).times { '' << ROW_TOP_BOTTOM_BORDER }
puts top
rows.each_with_index do |val, index|
Kernel.print ' ', val, ' ', ROW_LEFT_RIGHT_BORDER
end
puts
end
end
module Mastermin... | true |
90bf58107b25df7c80dd7930f11afa1b92ab119e | Ruby | ruanwz/tinto | /Spec/Tinto/LocalizerSpec.rb | UTF-8 | 4,502 | 2.546875 | 3 | [] | no_license | # encoding: utf-8
$:.unshift File.expand_path('../../../Lib', __FILE__)
require 'ostruct'
require 'minitest/autorun'
require_relative '../../Lib/Tinto/Localizer'
describe Tinto::Localizer do
before do
@fake_app_class = Class.new {
attr_accessor :session, :params, :request
def initialize(options={})
... | true |
1e8bb0fe595567b9bcac502c3e6c69ece86e1965 | Ruby | cannahum/MarginCall | /app/jobs/trigger_job.rb | UTF-8 | 2,669 | 3.015625 | 3 | [] | no_license | class TriggerJob
# This class will go through the trigger table, see if there is a trigger to be invoked,
# then alert its user
def self.perform
@triggers = Trigger.all
@triggers.each do |trigger|
if trigger[:active]==true
t_value = trigger[:trigger_price]
security = ... | true |
02590ebe1b12dea8b1de2918327a294c87b74890 | Ruby | ignat-z/aoc-2020 | /2020_11/solution.rb | UTF-8 | 2,846 | 3.234375 | 3 | [] | no_license | FLOOR = -1
EMPTY = 0
OCCUPIED = 1
SEATS_AROUND = [
[0, -1],
[1, -1],
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1]
]
INPUT = File.read('input.txt').split("\n").map(&:chars)
FIELD = INPUT.map { |row|
row.map { |column|
case column
when '.' then FLOOR
when 'L' then EMPTY
whe... | true |
5fbb81d6a2805c6e9dab4c110775bbcd3c64b443 | Ruby | Ronll/ruby_moon | /spec/models/user_spec.rb | UTF-8 | 3,408 | 2.625 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
describe User do
describe 'password hashing' do
it 'should encrypt the password' do
expect(::BCrypt::Password).to receive(:create).with('password').and_return('encrypted password')
user = User.create(password: 'password')
expect(user.encrypted_password).to eq 'encrypted ... | true |
f1bf8307aec91142c5bc68244eb0d8beeb8f0d35 | Ruby | ameravant/siteninja_plugins | /faker/lib/faker/company.rb | UTF-8 | 2,016 | 2.6875 | 3 | [
"MIT"
] | permissive | module Faker
class Company
class << self
def name
Formats.rand.call
end
def suffix
%w(Inc. \&\ Sons LLC Group Studio).rand
end
# Generate a buzzword-laden catch phrase.
# Wordlist from http://www.1728.com/buzzword.htm
def catch_phrase
[... | true |
105afc907b75f16e7f644ff0d9df7da93725809c | Ruby | khamilowicz/QuestinnetParser | /lib/questinnet/parsers/super_parser.rb | UTF-8 | 1,933 | 2.96875 | 3 | [
"MIT"
] | permissive | require "nori"
require_relative './converters/xml_to_hash_converter'
require_relative './converters/rss_to_hash_converter'
require_relative './converters/json_to_hash_converter'
module Questinnet
module Converter
module SuperParser
def parse data, options={}
@data = data
@translator_id = ... | true |
e1b792e039265afb2367d08174e56b46bccf5096 | Ruby | yogiduzit/codecore_homework | /notes/Ruby: Intro To Testing/circle.rb | UTF-8 | 204 | 3.390625 | 3 | [] | no_license | class Circle
def initialize(radius)
@radius = radius
end
def diameter
@radius * 2
end
def area
Math::PI * (@radius ** 2)
end
def perimeter
Math::PI * @radius * 2
end
end | true |
1b5ebf8af062c06a8be5d50d9515e12b802d2b62 | Ruby | plablock/carbon_calculated_api | /lib/carbon_calculated_api/models/global_computation.rb | UTF-8 | 1,433 | 2.71875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class GlobalComputation
include MongoMapper::Document
include CarbonCalculatedApi::Model
# keys
# key :name, String, :unique => true, :required => true
# key :parameters, Set, :required => true
# key :equation, String
# instance eval on the equation string you can
# @example
# constant(:earth_ra... | true |
1dfdfef88d3b76c125678d18156dea3696c27c98 | Ruby | trodicaro/ruby_work | /GDI_ruby_workshop/while_loop.rb | UTF-8 | 264 | 3.34375 | 3 | [] | no_license | puts "We are running a script until q key is entered. Type any other letter"
key = gets.chomp!
second_key = key
until key == 'q' && second_key == 'q'
puts "Do you want to continue (type c) or quit (type q twice)"
key = gets.chomp!
second_key = gets.chomp!
end
| true |
01863bb9f215e3db6beccc10319e10ff1df416ee | Ruby | camott/sudoku | /sudoku/solverFunctions/solver.rb | UTF-8 | 331 | 3.390625 | 3 | [] | no_license | class Solver
def initialize board
@board = board
end
def solve cells
raise NotImplementedError, "Implement this method in an inheriting class"
end
private
def solve_all_ways
anything_changed = false
@board.iterate_through_all do |cells|
anything_changed ||= yield(cells)
end
anything_change... | true |
6c50175b7cae992ffafa1893c094ac6d7e2f0c6c | Ruby | KishorBudhathoki10/Introduction_to_ruby | /Loops_and_Iterators/while_stop.rb | UTF-8 | 205 | 3.28125 | 3 | [] | no_license | while true
puts "Please enter your name."
name = gets.chomp
puts "Hi #{name}!!"
puts "Do you want me to ask u again? If not write 'STOP'."
reply = gets.chomp
if reply == "STOP"
break
end
end
| true |
c254c2a6bc2d351669ec29a503dc225ce5a16aa0 | Ruby | ablueplatypus/todo-ruby-basics-nyc-web-111918 | /lib/ruby_basics.rb | UTF-8 | 348 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1, num2)
num1/num2
end
def assign_variable(name)
name ="Bob"
end
def argue(phrase)
phrase = "I'm right and you are wrong!"
end
def greeting(name, string)
string = "Hello"
name = "Matt"
end
def return_a_value
return "Nice"
end
def last_evaluated_value
"expert"
end
def pizza_party(toppi... | true |
e7a42aaa620e897f553288920f1aea906edd311e | Ruby | igutwins/sinatra-logging-in-and-out-v-000 | /app/helpers/helpers.rb | UTF-8 | 367 | 2.78125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'sinatra/base'
class Helpers
def self.current_user(session) #class method, meaning operates on the class itself, not an instance. Thereofre you don't do Helpers.new.current_user, but rather Helpers.current_user
@user = User.find_by(:id => session[:user_id])
end
def self.is_logged_in?(ses... | true |
90189b2ba7853914b48cf78c5a881c1361c44d8b | Ruby | brunohq/exercism | /ruby/sum-of-multiples/sum_of_multiples.rb | UTF-8 | 272 | 3.328125 | 3 | [] | no_license | class SumOfMultiples
attr_reader :factors
def initialize(*factors)
@factors = factors
end
def to(limit)
factors
.reject(&:zero?)
.map { |factor| (factor...limit).reject{ |n| n % factor != 0 } }
.flatten
.uniq
.sum
end
end
| true |
b962fe276aadb7fa8d7e691eb3d624d96ed51f5e | Ruby | shangardezi/calendar-bookings | /app/models/booking.rb | UTF-8 | 664 | 2.640625 | 3 | [] | no_license | class Booking < ActiveRecord::Base
validate :start_date_is_before_end_date, :availability
validates_presence_of :start, :end, :room
belongs_to :room
private
def start_date_is_before_end_date
return unless start || self.end
if start > self.end
errors.add(:start, 'cannot be after the end date... | true |
7a8344e5cb73935ac6f884384744f411fb41b0b4 | Ruby | bnjmnhndrsn/rubtris | /lib/pattern.rb | UTF-8 | 226 | 2.96875 | 3 | [] | no_license | class Pattern
attr_accessor :name, :size, :color, :pattern
def initialize(name, pattern, size, color)
@name, @pattern, @size, @color = name, pattern, size, color
end
def pattern
@pattern.map(&:dup)
end
end | true |
28b404effad0f8b44b6b7b5b966af20e1b1c0ede | Ruby | jussiry/Opinaattori | /app/models/picture.rb | UTF-8 | 1,871 | 2.640625 | 3 | [] | no_license | require 'mini_magick' # for picture_modification
class Picture < ActiveRecord::Base
validates_format_of :picture_type, :with => /^image/, :allow_blank => true
def self.uploaded_user_picture(user, picture_field)
#self.name = base_part_of(picture_field.original_filename)
user.small_picture.destr... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.