repo_name stringlengths 6 97 | path stringlengths 3 341 | text stringlengths 8 1.02M |
|---|---|---|
AcnologiatheEnd/MineEstate | backend/db/migrate/20201026170750_fix_column_name.rb | class FixColumnName < ActiveRecord::Migration[6.0]
def change
rename_column :users, :usesrname, :username
end
end
|
AcnologiatheEnd/MineEstate | backend/app/controllers/application_controller.rb | <reponame>AcnologiatheEnd/MineEstate
class ApplicationController < ActionController::API
require 'securerandom'
include SessionsHelper
@@token = "0"
@@user = 0
end
|
AcnologiatheEnd/MineEstate | backend/db/migrate/20201111021708_add_session_to_users.rb | class AddSessionToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :session, :integer
end
end
|
AcnologiatheEnd/MineEstate | backend/config/routes.rb | Rails.application.routes.draw do
resources :houses, only: [:create, :destroy]
resources :users
resources :sessions, only: [:home, :create, :new, :destroy]
get '/logout' => 'sessions#destroy'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
|
AcnologiatheEnd/MineEstate | backend/app/controllers/houses_controller.rb | <reponame>AcnologiatheEnd/MineEstate
class HousesController < ApplicationController
def create
house = House.new(house_params)
if current_user
current_user.houses << house
end
if house.valid?
allHouses = House.all
render json: HouseSerializer.new(allHouses).t... |
AcnologiatheEnd/MineEstate | backend/app/controllers/users_controller.rb | <filename>backend/app/controllers/users_controller.rb
class UsersController < ApplicationController
def create
@user = User.new(house_params)
@user.password = <PASSWORD>[:password]
status = "bad"
if @user.valid?
@user.save
log_in @user
... |
AcnologiatheEnd/MineEstate | backend/app/helpers/sessions_helper.rb | module SessionsHelper
def log_in(user)
@@token = SecureRandom.hex
user.token = @@token
user.session = 1
user.save
set_current_user(user)
end
def set_current_user(user)
@@user = user
end
def current_user
@@user
end
def logged_in?
... |
LaunchAcademy/gollum_client | spec/spec_helper.rb | require 'rspec'
require 'vcr'
require_relative '../lib/gollum_client'
GollumClient.path_prefix = '/codecabulary/'
GollumClient.base_url = 'http://localhost:9292'
VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.hook_into :webmock # or :fakeweb
c.configure_rspec_metadata!
c.default_cassette_o... |
LaunchAcademy/gollum_client | spec/gollum_client/page_spec.rb | require 'spec_helper'
describe GollumClient::Page, :vcr do
context "fetching content" do
let(:page) { GollumClient::Page.fetch('/test') }
it 'contains testing 1 2 3' do
expect(page.body).to include('testing')
end
it 'does not contain navigation' do
expect(page.body).to_not include('Last... |
LaunchAcademy/gollum_client | lib/gollum_client/page.rb | require 'faraday'
require 'faraday_middleware'
require 'nokogiri'
module GollumClient
class Page
attr_reader :body, :title, :meta
def initialize(title, body, meta = {})
@title = title
@body = body
@meta = meta
end
class << self
def fetch(path = '')
resp = nil
... |
LaunchAcademy/gollum_client | lib/gollum_client.rb | require 'configatron'
require 'gollum_client/version'
require 'gollum_client/page'
require 'gollum_client/app'
module GollumClient
class << self
def base_url=(url)
configatron.gollum_client.base_url = url
end
def base_url
configatron.gollum_client.base_url
end
def path_prefix=(pref... |
LaunchAcademy/gollum_client | lib/gollum_client/version.rb | <filename>lib/gollum_client/version.rb
module GollumClient
VERSION = "0.0.1"
end
|
honeycombio/faraday-honeycomb | lib/faraday/honeycomb/version.rb | <reponame>honeycombio/faraday-honeycomb<gh_stars>1-10
module Faraday
module Honeycomb
GEM_NAME = 'faraday-honeycomb'
VERSION = '0.3.3'
MIN_FARADAY_VERSION = '0.8'
end
end
|
honeycombio/faraday-honeycomb | lib/faraday/honeycomb.rb | require 'faraday'
require 'faraday/honeycomb/middleware'
Faraday::Middleware.register_middleware honeycomb: ->{ Faraday::Honeycomb::Middleware }
|
honeycombio/faraday-honeycomb | faraday-honeycomb.gemspec | lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH << lib unless $LOAD_PATH.include?(lib)
require 'faraday/honeycomb/version'
Gem::Specification.new do |gem|
gem.name = Faraday::Honeycomb::GEM_NAME
gem.version = Faraday::Honeycomb::VERSION
gem.summary = 'Instrument your Faraday HTTP requests with Honeycomb'
... |
honeycombio/faraday-honeycomb | spec/middleware/middleware_spec.rb | <reponame>honeycombio/faraday-honeycomb<filename>spec/middleware/middleware_spec.rb
require 'faraday-honeycomb'
# Do not require honeycomb-beeline directly as that will auto-install our faraday middleware
require 'honeycomb/client'
require 'honeycomb/span'
require 'timeout'
RSpec.describe Faraday::Honeycomb::Middlewa... |
honeycombio/faraday-honeycomb | lib/faraday/honeycomb/middleware.rb | require 'faraday'
require 'libhoney'
require 'securerandom'
require 'faraday/honeycomb/version'
module Faraday
module Honeycomb
USER_AGENT_SUFFIX = "#{GEM_NAME}/#{VERSION}"
class Middleware
def initialize(app, client: nil, logger: nil)
@logger = logger
@logger ||= ::Honeycomb.logger i... |
honeycombio/faraday-honeycomb | spec/auto_install_spec.rb | require 'faraday'
require 'faraday-honeycomb'
require 'faraday-honeycomb/auto_install'
RSpec.describe Faraday::Honeycomb::AutoInstall, auto_install: true do
before(:all) do
Faraday::Honeycomb::AutoInstall.auto_install!(honeycomb_client: Libhoney::TestClient.new)
end
it "standard usage with no block works" d... |
honeycombio/faraday-honeycomb | lib/faraday-honeycomb.rb | <reponame>honeycombio/faraday-honeycomb
require 'faraday/honeycomb/version'
begin
gem 'faraday', ">= #{Faraday::Honeycomb::MIN_FARADAY_VERSION}"
require 'faraday/honeycomb'
rescue Gem::LoadError
warn 'Faraday not detected, not enabling faraday-honeycomb'
end
|
honeycombio/faraday-honeycomb | lib/faraday-honeycomb/auto_install.rb | require 'faraday/honeycomb/version'
module Faraday
module Honeycomb
module AutoInstall
class << self
def available?(logger: nil)
constraint = ">= #{::Faraday::Honeycomb::MIN_FARADAY_VERSION}"
gem 'faraday', constraint
logger.debug "#{self.name}: detected Faraday #{cons... |
UAlbertaALTLab/homebrew-hfst | Formula/hfst.rb | class Hfst < Formula
desc "Helsinki Finite-State Technology (library and application suite)"
homepage "https://hfst.github.io/"
url "https://github.com/hfst/hfst/releases/download/v3.15.2/hfst-3.15.2.tar.gz"
sha256 "7e28c6aa2796549b93f5e8aee7ca187716df17b9e687718d4ebf9817d214059d"
depends_on "readline" => :r... |
infrablocks/terraform-aws-assumable-roles-policy | spec/policy_spec.rb | <filename>spec/policy_spec.rb
require 'spec_helper'
describe 'assumable roles policy' do
let(:policy_name) { vars.policy_name }
let(:policy_description) { vars.policy_description }
let(:policy_arn) { output_for(:harness, 'policy_arn') }
let(:target_role_arn) { output_for(:harness, 'target_role_arn') }
let(... |
kostya/modest | bench/test-libxml.rb | <filename>bench/test-libxml.rb
require "bundler/setup"
require "nokogiri"
page = File.read("./google.html")
s = 0
links = []
1000.times do
doc = Nokogiri::HTML(page)
links = doc.css("div.g h3.r a").map { |link| link["href"] }
s += links.size
end
p links.last
p s
|
adz/quickets | lib/quickets.rb | <filename>lib/quickets.rb
require "roda"
require "pathname"
require "quickets/version"
require "quickets/config"
require "quickets/logger"
require "quickets/ticket_printer"
require "quickets/available_printers"
# Config
$quickets_dir = Pathname.new(
if ENV['QUICKETS_DIR'].nil? || ENV['QUICKETS_DIR'] == ""
Quic... |
adz/quickets | lib/quickets/logger.rb | require 'logger'
module Quickets
def self.logger
@logger ||= Logger.new($stdout).tap do |log|
log.progname = 'quickets'
end
end
end
|
adz/quickets | config.ru | #!/usr/bin/env ruby
# Add lib path
require 'pathname'
Pathname.new(__FILE__).dirname.join('lib').tap {|lib_dir|
$:.unshift(lib_dir) unless $:.include?(lib_dir)
}
require "bundler/setup"
require "rack/cors"
require "quickets"
use Rack::Cors do
allow do
origins '*'
resource '/*', :headers => :any, :methods... |
adz/quickets | lib/quickets/config.rb | <reponame>adz/quickets<gh_stars>0
require 'yaml'
module Quickets
def self.configure(file_name)
@config = Config.new(YAML.load_file(file_name))
end
def self.config
@config
end
class Config
def initialize(printers_by_api_key)
@printers_by_api_key = printers_by_api_key
end
def check... |
adz/quickets | lib/quickets/available_printers.rb | <reponame>adz/quickets<filename>lib/quickets/available_printers.rb
# Interface to java lib
require "java"
require "jars/ticket_printer-1.2.0-jar-with-dependencies.jar"
java_import com.quicktravel.ticket_printer.PrintServiceLocator
module Quickets
class AvailablePrinters
def self.all(api_key)
# Return only... |
adz/quickets | lib/quickets/ticket_printer.rb | <reponame>adz/quickets
# Interface to java lib
require "java"
require "jars/ticket_printer-1.2.0-jar-with-dependencies.jar"
java_import com.quicktravel.ticket_printer.TicketPrintCommand
require 'quickets/available_printers'
module Quickets
class TicketPrinter
attr_reader :printer_name
def initialize(params... |
MountainCode/jruby-velocity | spec/file_velocity_launcher_spec.rb | require 'velocity'
describe Velocity::FileVelocityLauncher do
let(:launcher) { Velocity::FileVelocityLauncher.new 'spec/resources' }
subject { launcher }
it 'should merge a template from a velocity file' do
context = {
'host' => 'Cardinal Fang',
'weapons' => ['Fear', 'Surprise', 'Ruthless Effi... |
MountainCode/jruby-velocity | lib/velocity/mysql_data_source.rb | <filename>lib/velocity/mysql_data_source.rb
java_import 'javax.sql.DataSource'
java_import 'java.sql.DriverManager'
java_import 'com.mysql.jdbc.Driver' # We need to load the Driver class even though we don't explicitly use it.
class MySqlDataSource
include DataSource
def initialize url, user, password
@url ... |
MountainCode/jruby-velocity | lib/velocity.rb | <gh_stars>0
require 'java'
require 'velocity/velocity_launcher'
require 'velocity/mysql_data_source'
require 'velocity/file_velocity_launcher'
require 'velocity/mysql_velocity_launcher'
require 'velocity/hash_converter'
require 'velocity/version'
|
MountainCode/jruby-velocity | spec/mysql_velocity_launcher_spec.rb | <reponame>MountainCode/jruby-velocity<gh_stars>0
require 'yaml'
require 'velocity'
describe Velocity::MySqlVelocityLauncher do
let(:launcher) { Velocity::MySqlVelocityLauncher.new YAML.load_file('spec/resources/sql_connection.yaml') }
subject { launcher }
it 'should merge a template from a database table' do
... |
MountainCode/jruby-velocity | spec/hash_converter_spec.rb | require 'velocity'
class Person
attr_accessor :name, :address
end
class Address
attr_accessor :city, :state, :zip
end
describe Velocity::HashConverter do
describe 'when object is converted to hash' do
converter = Velocity::HashConverter.new
person = Person.new
person.name = 'Chris'
person.addre... |
MountainCode/jruby-velocity | lib/velocity/file_velocity_launcher.rb | module Velocity
class FileVelocityLauncher
include VelocityLauncher
def initialize template_dir
init({
'resource.loader' => 'file',
'file.resource.loader.path' => template_dir
})
end
end
end
|
MountainCode/jruby-velocity | lib/velocity/mysql_velocity_launcher.rb | <gh_stars>0
java_import 'org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader'
module Velocity
class MySqlVelocityLauncher
include VelocityLauncher
def initialize connection
loader = DataSourceResourceLoader.new
loader.setDataSource(MySqlDataSource.new "jdbc:mysql://#{connection[... |
MountainCode/jruby-velocity | lib/velocity/hash_converter.rb | module Velocity
class HashConverter
def to_hash obj
hash = {}
if(obj.is_a? Hash)
string_key_hash = {}
obj.each do |key, value|
string_key_hash[key.to_s] = to_hash value
end
string_key_hash
elsif obj.is_a? Array
obj.each_with_index { |item, i| obj... |
MountainCode/jruby-velocity | lib/velocity/velocity_launcher.rb | <filename>lib/velocity/velocity_launcher.rb<gh_stars>0
module Velocity
module VelocityLauncher
java_import 'org.apache.velocity.app.Velocity'
java_import 'org.apache.velocity.app.VelocityEngine'
java_import 'org.apache.velocity.VelocityContext'
java_import 'java.io.StringWriter'
java_import 'org.... |
andrewjkerr/ufid_parser | spec/spec_helper.rb | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'ufid_parser'
|
andrewjkerr/ufid_parser | spec/ufid_parser_spec.rb | <gh_stars>0
require 'spec_helper'
describe UfidParser do
it 'has a version number' do
expect(UfidParser::VERSION).not_to be nil
end
describe 'with a valid UFID number' do
before { @expected = '12345678' }
describe 'and the two UFID numbers match up' do
@arr = [';200123... |
andrewjkerr/ufid_parser | lib/ufid_parser.rb | <gh_stars>0
require "ufid_parser/version"
module UfidParser
class UFID
attr_accessor :ufid_number
def initialize(str)
@ufid_number = parse_ufid_number(str)
end
private
def parse_ufid_number(str)
splitter = [] << str[1]
splitter << str[-... |
ritabc/numbers-to-words | spec/number_to_words_spec.rb | <filename>spec/number_to_words_spec.rb
require 'rspec'
require 'number_to_words'
require 'pry'
describe ("NumberToWords#translate") do
it "will take the number 2 and return the word two" do
number = NumberToWords.new(2)
expect(number.translate()).to(eq('two'))
end
it "will take the number 11 and return e... |
ritabc/numbers-to-words | lib/number_to_words.rb | <reponame>ritabc/numbers-to-words<filename>lib/number_to_words.rb
class NumberToWords
def initialize(number)
@number = number
end
def translate()
ones_and_teens = {0 => "", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 1... |
rayvaldez/fi-player-tracker | app/models/player.rb | class Player < ActiveRecord::Base
belongs_to :user
validates :name, :team, :cost, :quantity, :presence => true
end
|
rayvaldez/fi-player-tracker | app/models/user.rb | <reponame>rayvaldez/fi-player-tracker<filename>app/models/user.rb
class User < ActiveRecord::Base
has_many :player
has_secure_password
validates :username, :email, :uniqueness => true
validates :username, :email, :presence => true
end
|
rayvaldez/fi-player-tracker | app/controllers/application_controller.rb | require './config/environment'
require 'rack-flash'
class ApplicationController < Sinatra::Base
configure do
set :public_folder, 'public'
set :views, 'app/views'
enable :sessions
set :session_secret, "football_index"
use Rack::Flash
end
helpers do
def current_user
@user = User.fin... |
rayvaldez/fi-player-tracker | app/controllers/players_controller.rb | <reponame>rayvaldez/fi-player-tracker<filename>app/controllers/players_controller.rb<gh_stars>0
class PlayersController < ApplicationController
get '/players' do
if logged_in?
@player_array = []
Player.all.each do |player|
if player.user_id == current_user.id
@player_array << player... |
ookam/rangrok | rangrok.gemspec | $:.push File.expand_path("lib", __dir__)
# Maintain your gem's version:
require "rangrok/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|
spec.name = "rangrok"
spec.version = Rangrok::VERSION
spec.authors = ["<NAME>"]
spec.email = ["<EMAIL>"]
s... |
ookam/rangrok | lib/rangrok/railtie.rb | module Rangrok
class Railtie < ::Rails::Railtie
initializer 'rangrok_add_ngrok_to_allowed_hosts' do
Rails.application.config.hosts << ".ngrok.io" if Rails.env.development?
end
initializer 'rangrok_add_localtunnel_to_allowed_hosts' do
Rails.application.config.hosts << ".localtunnel.me" if Rail... |
ookam/rangrok | test/rangrok_test.rb | require 'test_helper'
class Rangrok::Test < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, Rangrok
end
test 'allow request from "*.ngrok.io"' do
assert_includes Rails.application.config.hosts, ".ngrok.io"
end
test 'allow request from "*.localtunnel.me"' do
assert_includes Rails.... |
ookam/rangrok | lib/rangrok.rb | <filename>lib/rangrok.rb
require "rangrok/railtie"
module Rangrok
# Your code goes here...
end
|
ctrlok/opsworks-example-cookbooks | secrets_test/recipes/store.rb | #
# Cookbook Name:: secrets_test
# Recipe:: store
#
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.am... |
NessInMorse/Learn_Morse_WordsTEXT | Morse_game.rb | require "path/to/alle_woorden.rb"
include Words
require 'curses'
input=""
rawinput=""
rawtime=[]
c=0
time= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
count= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
line_c=0
inter_c=0
time0=0
time1=0
lettertimes=""
File.open("path/to/Letter_graph.txt","... |
cpuguy83/faye-client | lib/faye-client/channel_handlers/default_channel_handler.rb | module FayeClient
class DefaultChannelHandler
include Sidekiq::Worker
sidekiq_options :queue => :messaging
def perform(message)
message
end
end
end |
cpuguy83/faye-client | lib/faye-client.rb | require 'rubygems'
require 'eventmachine'
require 'Faye' unless defined? Faye
require 'sidekiq'
require 'active_support'
require 'require_all'
require_rel 'faye-client' |
cpuguy83/faye-client | lib/faye-client/faye_client.rb | module FayeClient
# extend FayeClient in your class/module to use
# the "start" method spins off the EM instance with the Faye client to it's own thread
# You can access the the client itself or the thread using the class accessor methods "messaging_client" and "messaging_client_thread", respectively
# You must spe... |
leenasn/active_admin_auto_select | lib/active_admin_auto_select/version.rb | <gh_stars>0
module AdminAutoSelect
VERSION = "0.1.12"
end
|
leenasn/active_admin_auto_select | active_admin_auto_select.gemspec | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require 'active_admin_auto_select/version'
Gem::Specification.new do |spec|
spec.name = "active_admin_auto_select"
spec.version = AdminAutoSelect::VERSION
spec.authors = ["spyrbri"]
spec.email = ["<EMAIL>"]
sp... |
leenasn/active_admin_auto_select | lib/active_admin_auto_select.rb | require "active_admin_auto_select/version"
require "active_admin_auto_select/rails"
module AutoSelectable
def auto_select(*fields)
options = fields.extract_options!
# The @resource instance variable seems unavailable in versions
# later than 1.0.0.pre1 of the ActiveAdmin.
resource = @resource || sel... |
sparkrico/ruby_apk | spec/layout_spec.rb | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Android::Layout do
context 'with real apk sample file' do
let(:apk_path){ File.expand_path(File.dirname(__FILE__) + '/data/sample.apk') }
let(:apk){ Android::Apk.new(apk_path) }
let(:layouts) { apk.layouts }
subject { layouts ... |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_encoding.rb | def transcode(string)
string.encode('ISO-8859-1').force_encoding('UTF-8')
end |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_iteration.rb | def count_multibyte_char(string)
number_of_multibyte_chars = 0
string.each_char {|x| number_of_multibyte_chars+=1 if x.bytesize > 1}
number_of_multibyte_chars
end |
sarvekash/HackerRank_Solutions | Ruby/Control Structures/ruby_control_structures-infinite_loop.rb | loop do
coder.practice
if coder.oh_one?
break
end
end |
sarvekash/HackerRank_Solutions | Ruby/Arrays Hashes/ruby_array_initialization.rb | array = []
array_1 = [nil]
array_2 = [10, 10] |
sarvekash/HackerRank_Solutions | Ruby/Arrays Hashes/ruby_hash_add_del_sel.rb | hackerrank.store(543121, 100)
hackerrank.keep_if {|key, value| key.is_a? Integer}
hackerrank.delete_if{|key, value| key % 2 == 0} |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_procs.rb | def square_of_sum (my_array, proc_square, proc_sum)
sum = proc_sum.call(my_array)
proc_square.call(sum)
end
proc_square_number = proc {|number| number**2}
proc_sum_array = proc {|array| array.inject(0){|sum,x| sum + x }}
my_array = gets.split().map(&:to_i)
puts square_of_sum(my_array, proc_square_number, proc... |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_introduction.rb | <gh_stars>1-10
def single_quote
# single quote string here
'Hello World and others!'
end
def double_quote
# Double quote string here
"Hello World and others!"
end
def here_doc
# Here doc string here
document = <<-HERE
Hello World and others!
HERE
end
|
sarvekash/HackerRank_Solutions | Ruby/Control Structures/ruby_control_structures-each.rb | def scoring(array)
array.each do |user|
user.update_score
end
end |
sarvekash/HackerRank_Solutions | Ruby/Enumerables/ruby_enumerables_collect.rb | <reponame>sarvekash/HackerRank_Solutions
def rot13(secret_messages)
secret_messages.collect { |message| message.tr("abcdefghijklmnopqrstuvwxyz", "nopqrstuvwxyzabcdefghijklm") }
end
|
sarvekash/HackerRank_Solutions | Ruby/Enumerables/ruby_enumerables_group_by.rb | <reponame>sarvekash/HackerRank_Solutions
def group_by_marks(marks, pass_marks)
marks.group_by {|key, value|
if value < pass_marks
"Failed"
else "Passed"
end}
end |
sarvekash/HackerRank_Solutions | Ruby/Enumerables/ruby_enumerables_reduce.rb | def sum_terms(n)
(1..n).reduce(0) {|sum, num| sum + num**2 + 1 }
end |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_blocks.rb | <reponame>sarvekash/HackerRank_Solutions
def factorial
yield
end
n = gets.to_i
factorial do
puts (1..n).inject(:*)
end |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_keyword_arguments.rb | <gh_stars>1-10
def convert_temp(temperature, input_scale, **output_scale)
if input_scale[:input_scale] == input_scale[:output_scale]
temperature
elsif input_scale[:input_scale] == 'celsius' and input_scale[:output_scale] == 'fahrenheit'
# T(°F) = T(°C) × 1.8 + 32
temperature * 1.8 + 32
elsif input_sca... |
sarvekash/HackerRank_Solutions | Ruby/Arrays Hashes/ruby_hash_initialization.rb | <filename>Ruby/Arrays Hashes/ruby_hash_initialization.rb
empty_hash = Hash.new
default_hash = Hash.new
default_hash.default = 1
hackerrank = Hash.new
hackerrank["simmy"] = 100
hackerrank["vivmbbs"] = 200 |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_indexing.rb | <gh_stars>1-10
def serial_average(string)
matches = string.scan(/...-(\d+\.\d+)-*(\d+\.\d+)*/)
x = matches[0][0].to_f
unless matches[0][1].nil?
y = matches[0][1].to_f
else
y = x
end
z = ((x + y) / 2).round(2)
string[0, 4] + "#{z}"
end |
sarvekash/HackerRank_Solutions | Ruby/Control Structures/ruby_control_structures-unless.rb | <filename>Ruby/Control Structures/ruby_control_structures-unless.rb
def scoring(array)
# update_score of every user in the array unless the user is admin
# unless is the logical equivalent of if not
array.each do |user|
user.update_score unless user.is_admin?
end
end |
sarvekash/HackerRank_Solutions | Ruby/Control Structures/ruby_control_structures-until.rb | <filename>Ruby/Control Structures/ruby_control_structures-until.rb<gh_stars>1-10
# until is the logical equivalent of while not.
coder.practice until coder.oh_one? |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_lazy_evaluation.rb | n = gets.to_i
def is_prime?(n)
2.upto(Math.sqrt(n).round()).each do |x|
return false if n % x == 0
end
true
end
def is_palindrome?(n)
n.to_s == n.to_s.reverse
end
palindromic_primes_array = -> (array_size) do
2.upto(Float::INFINITY).lazy.map { |x| x if (is_palindrome?(x) && is_prime?(x)) }.select {|ite... |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_variable_arguments.rb | def full_name(first, *rest)
fullname = ''
fullname += first
rest.each do |name|
fullname += ' ' + name
end
fullname
end |
sarvekash/HackerRank_Solutions | Ruby/Control Structures/ruby_control_structures-case_bonus.rb | def identify_class(obj)
case obj
when Hacker then puts "It's a Hacker!"
when Submission then puts "It's a Submission!"
when TestCase then puts "It's a TestCase!"
when Contest then puts "It's a Contest!"
else puts "It's an unknown model"
end
end |
sarvekash/HackerRank_Solutions | Ruby/Enumerables/ruby_enumerables_introduction.rb | <gh_stars>1-10
def iterate_colors(colors)
array = Array.new
colors.each do |color|
array.push(color)
end
end
|
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_introduction.rb | <reponame>sarvekash/HackerRank_Solutions
require 'prime'
def prime?(number)
return number.prime?
end |
sarvekash/HackerRank_Solutions | Ruby/Arrays Hashes/ruby_hash_each.rb | def iter_hash(hash)
hash.each do |key, value|
puts key
puts value
end
end |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_methods_ii.rb | def strike(string)
string.prepend("<strike>").concat("</strike>")
end
def mask_article(string, array)
array.each do |s|
if string.include?(s)
string.gsub!("#{s}", strike(s))
end
end
string
end |
sarvekash/HackerRank_Solutions | Ruby/Enumerables/ruby_enumerables_each_with_index.rb | def skip_animals(animals, skip)
array = Array.new
animals.each_with_index { |animal, index|
if (index >= skip)
array.push("#{index}:#{animal}")
end
}
return array
end |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_partial_applications.rb | combination = -> (number) do
-> (another_number) do
(1..number).inject(:*) / ((1..another_number).inject(:*) * (1..number-another_number).inject(:*))
end
end
n = gets.to_i
r = gets.to_i
nCr = combination.(n)
puts nCr.(r) |
sarvekash/HackerRank_Solutions | Ruby/Strings/ruby_strings_methods_i.rb | <filename>Ruby/Strings/ruby_strings_methods_i.rb
def process_text(string_array)
result = ''
string_array.each do |s|
result += s.strip + ' '
end
result.chop
end |
sarvekash/HackerRank_Solutions | Ruby/Methods/ruby_methods_arguments.rb | <reponame>sarvekash/HackerRank_Solutions
def take(array, len=1)
array[len, array.length]
end |
jacobmarshall-etc/apollo | data/plugins/skill/magic/teleport.rb | # Thanks to phl0w <http://www.rune-server.org/members/phl0w> for providing
# the correct destination coordinates of the ancient teleports.
require 'java'
java_import 'org.apollo.game.model.Animation'
java_import 'org.apollo.game.model.Graphic'
java_import 'org.apollo.game.model.Position'
java_import 'org.apollo.game.... |
jacobmarshall-etc/apollo | data/plugins/player-action/action.rb | <reponame>jacobmarshall-etc/apollo<gh_stars>0
require 'java'
java_import 'org.apollo.game.message.impl.SetPlayerActionMessage'
java_import 'org.apollo.game.model.entity.Player'
# A right-click action for a Player.
class PlayerAction
attr_reader :slot, :primary, :name
def initialize(slot, primary, name)
index... |
tylerxiety/tylerxiety.github.io | jekyll-theme-cayman-blog.gemspec | <reponame>tylerxiety/tylerxiety.github.io
# encoding: utf-8
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = "jekyll-theme-cayman-blog"
s.version = "0.0.9"
s.license = "CC0-1.0"
s.authors = ["Tyler"]
s.email = ["<EMAIL>"]
s.homepage = "https://git... |
saadbinakhlaq/kahwa | lib/kahwa/utils.rb | <filename>lib/kahwa/utils.rb
class String
def to_snake_case
self.gsub('::', '/') # Home::PagesController => Home/PagesController
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # HOMEController => home_controller
.gsub(/([a-z\d])([A-Z])/, '\1_\2') # FO86OBar => fo86_o_bar
.tr('-', '_')
.downcase
end
... |
saadbinakhlaq/kahwa | lib/kahwa/dependencies.rb | <gh_stars>1-10
class Object
def self.const_missing(const)
require const.to_s.to_snake_case
Object.const_get(const)
end
end |
saadbinakhlaq/kahwa | lib/kahwa.rb | require 'kahwa/version'
require 'kahwa/controller'
require 'kahwa/utils'
require 'kahwa/dependencies'
require 'kahwa/routing'
module Kahwa
class Application
def call(env)
if env['PATH_INFO'] == '/favicon.ico'
return [404, {}, []]
end
get_rack_app(env).call(env)
end
end
end
|
Scompler/ruby-msg | lib/mapi/version.rb | <filename>lib/mapi/version.rb
module Mapi
VERSION = '1.5.3'
end
|
Scompler/ruby-msg | lib/mapi/rtf.rb | <filename>lib/mapi/rtf.rb<gh_stars>0
require 'stringio'
require 'strscan'
class StringIO # :nodoc:
begin
instance_method :getbyte
rescue NameError
alias getbyte getc
end
end
module Mapi
#
# = Introduction
#
# The +RTF+ module contains a few helper functions for dealing with rtf
# in mapi messages: +rtfdec... |
drefuss/rubequ | config/initializers/paperclip.rb | Paperclip.interpolates :song_name do |attachment, style|
"#{attachment.instance.name}".downcase
end
Paperclip.interpolates :file_path do |attachment, style|
"#{attachment.instance.band}".gsub(" ", "_").downcase.gsub(/[^0-9a-z]/, '')
end
Paperclip.interpolates :custom_filename do |attachment, style|
"#{attachmen... |
drefuss/rubequ | config/initializers/session_store.rb | <filename>config/initializers/session_store.rb<gh_stars>0
# Be sure to restart your server when you modify this file.
Rubequ::Application.config.session_store :cookie_store, key: '_rasplay_session'
|
drefuss/rubequ | db/migrate/20130711021551_create_songs.rb | class CreateSongs < ActiveRecord::Migration
def change
create_table :songs do |t|
t.string :name
t.string :band
t.string :album
t.string :album_cover
t.datetime :release_date
t.timestamps
end
end
end
|
drefuss/rubequ | lib/rubequ_mpd.rb | require 'ruby-mpd'
module RubequMpd
attr_accessor :mpd_server, :mpd_port
class Mpd
attr_accessor :mpd
def initialize
@mpd = MPD.new RubequMpd.mpd_server, RubequMpd.mpd_port
connect
consume
end
def consume
@mpd.consume = true
end
def connect
begin
@m... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.