Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

Ruby

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello, I see below script starting like

require 'MonitoringScript'
class CheckSnmp < MonitoringScript

Open in new window


I am wondering what is MonitoringScript ? is it gem? and what below does?

class CheckSnmp < MonitoringScript

Open in new window


Really appreciate any help and guidance.
0
Concerto Cloud for Software Providers & ISVs
LVL 4
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

A traveller searches for trips from Bern to Berlin on Dec 25, 2013, from 8am (one-way).
A list of the 20 first results returned by a tool is given in the attached ex3-data.json file.

Tips: most fields are self-explanatory, while some may need explanation:
1. boo_return is true for a return trip, false otherwise
2. workTime_sec is the duration that the traveler can work during that part of the trip in seconds.
3. duration_out_sec is the duration of the corresponding outbound part of the trip, in seconds. For return trip, if applicable, there will be a similar field duration_in_sec for the duration of the inbound trip part.

Goals
1. Propose a solution to rank the list of results provided in the attached file.
2. Output the list of ranked results to a file named ex3-output.json.
   Each result must have two additional properties “rank” and “score”, respectively storing the final rank and the score of the trip (If applicable).

========================================
ex3-data.txt
0
The development environment is as follows.

OS:CentOS7 x86_64
ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
rails: 5.0.6
cancancan: 2.0.0
devise: 4.3.0
rails_admin: 1.2.0

In the above environment, accessing the password change screen redirects to root path.
The log at that time is as follows.

Started GET "/users/password/edit" for 127.0.0.1 at 2017-09-28 22:28:35 +0900
Processing by Devise::PasswordsController#edit as HTML
  User Load (40.8ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Redirected to http://localhost:3333/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 45ms (ActiveRecord: 40.8ms)


Started GET "/" for 127.0.0.1 at 2017-09-28 22:28:35 +0900
Processing by ProductController#index as HTML
  User Load (40.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
  Rendering product/index.html.erb within layouts/application
  Rendered product/index.html.erb within layouts/application (31.5ms)
Completed 200 OK in 127ms (Views: 83.2ms | ActiveRecord: 40.3ms)

What should I check for solutions?
0
I want to call a C++ project from Ruby, but my knowledge of the C build process is shaky at best, so unsure of how to set compiler flags (and why) as well as how to reference and link the project files. Currently RubyInline seems like the quickest option, but open to other suggestions.
0
How difficult is it for someone to make an AI interface that can be used on my computer, that can access anything from google maps when asking where something is located (like siri) all the way to being able to scan a hard drive for the contents held within it? I work for this small company and all we do is use google maps and take old hard drives and scan them for their contents, upon request by customer, and retrieve data deleted, lost, or just unreachable due to computer malfunction. I want to see if there is an easier way to do this, by using an AI to do all the hard work, and all we have to do is tell it to scan the drive and collect the lost data and store it into either a zip file or something as such. Please let me know thoughts. Am also flexible, doesn't have to be in ruby, but a lot of things we do, we use ruby based programs that's why I'm curious if its possible.
0
Thank you for watching.
I'm trying to create a custom filter on ActiveAdmin.
I tried to find a solution with referencing online articles.
But, I couldn't. Plese, help me.

There are two models called PointPayment and Contract.

PointPayment
# Table name: point_payments
#
#  id           :integer          not null, primary key
#  user_id      :integer
#  contract_id  :integer
#  amount       :float(24)
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#  state        :integer          default(0)
#  payment_type :integer          default(0)

class Contract < ActiveRecord::Base
  has_many :point_payments, dependent: :destroy
end

Contract
# Table name: contracts
#
#  id                         :integer          not null, primary key
#  client_id                  :integer
#  advisor_id                 :integer

class PointPayment < ActiveRecord::Base
  belongs_to :contract
end

Open in new window


I'd like to filter Contract with "payment_type."
But, Contract model hasn't payment_type.
So, I have to filter records of PointPayment model with payment_type at first and pick "contract_id" up from them.
And then, I filter Contract model records with the contract_ids.

The payment_type has four types 0 to 3.
But, I'll only use three types ( 1 to 3 ) for filtering.

Now, I wrote below codes. But, It doesn't work.
I'm stuck. I don't even know how I should search.

models/contract.rb
class Contract < ActiveRecord::Base
  scope :payment_type_one, -> { PointPayment.find_by(payment_type: 1) }
  scope :payment_type_two, -> { PointPayment.find_by(payment_type: 2) }
  scope :payment_type_three, -> { PointPayment.find_by(payment_type: 3) }

  scope :payment_types, lambda { |payment_types|
    case payment_types
    when 2
      pt = payment_type_one
      Contract.id(pt.contract_id)
    when 3
      pt = payment_type_two
      Contract.id(pt.contract_id)
    when 4
      pt = payment_type_three
      Contract.id(pt.contract_id)
    end
  }

  def self.ransackable_scopes(_auth_object = nil)
    %i(payment_types)
  end

end

Open in new window


adminn/contract.rb
ActiveAdmin.register Contract do
  filter :payment_types, as: :select, collection: proc { [%w(Type1 2), %w(Type2 3), %w(Type3 4)] }
end

Open in new window

0
Hi All,

I have decent powershell skills, I now want to learn either Ruby or Python , which language will you recommend  and which will be the easiest for someone from a powershell background?

Also do any know if if chef configuration management support python?

thank you in advance
0
I have inherited a cookbook from another developer and when I run "berks install" I get the following error output.

{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:80:in `block in resolve': undefined method `name' for nil:NilClass (NoMethodError)
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `each'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `inject'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `resolve'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve.rb:64:in `it!'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/resolver.rb:78:in `resolve'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/installer.rb:176:in `install_from_universe'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/installer.rb:40:in `run'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/berksfile.rb:422:in `install'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/cli.rb:143:in `install'
        from /{dir …
0
this script pick up a file and steps through it, and then picks up another file and matches the item number to merge the file and i getting this error, and I do not know why ?

here is the code where the file is blowing up with the following errors repeatedly.

<Error>
substr outside of string at ./parseOsc.pl line 272, <PLUS> line 745800.
substr outside of string at ./parseOsc.pl line 273, <PLUS> line 745800.
Use of uninitialized value $bo_plus in substitution (s///) at ./parseOsc.pl line 283, <PLUS> line 745800.
Use of uninitialized value $res_plus in substitution (s///) at ./parseOsc.pl line 284, <PLUS> line 745800.
Use of uninitialized value $res_plus in string eq at ./parseOsc.pl line 286, <PLUS> line 745800.
Use of uninitialized value $bo_plus in string eq at ./parseOsc.pl line 287, <PLUS> line 745800.
</Error>

<code>
while(<PLUS>) {
     $the_plus = $_;
     chomp($the_plus);
 
     $item_plus = substr($the_plus, 0,10);
     $bo_plus   = substr($the_plus,36, 5);
     $res_plus  = substr($the_plus,41, 5);

   next if $item_plus =~ m/\s*MSC/i;
 
     $item_plus =~ s/\s+//;
     next if $item_plus eq "";
 
   #print " $item  >$item_plus< \t $bo_plus  \t $res_plus \n";
 
   $bo_plus  =~ s/\s+//; ### Error happens here !!!
   $res_plus =~ s/\s+//; ### Error happens here !!!


         $res_plus = ($res_plus eq "" ) ? '0' : $res_plus;
        $bo_plus = ($bo_plus eq "" ) ? '0' : $bo_plus;
 
        next if ( $item ne $item_plus);
0
I am working on a POC to read data from a DB using Logstash and create a JSON nested document and put it into elasticsearch. I am unable to create the JSON and was wondering using RUBY for the same however I am new to RUBY and need some help doing the same
The JSON I want created is
 { ParentId:1, ParentName:pName,
Child[
{
ChildId:1,
ChildName:cname1,
}

{
ChildId:2,
ChildName:cname2,
}


]
}


Any help in this regard will be appreciated. I need this urgently
0
How to Use the Help Bell
LVL 10
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

hello need help with installing basic installation of gem Capistrano and test the gem locally if possable?
0
I am trying to get a RoR application running on Ubuntu 15.10, the app runs on:
* Apache
* MySQL
* Ruby on Rails

Should I install Apache first, then CD to the Apache directory before installing rails? The reason I ask is there is one GEM that needs to be installed manually:
sudo gem install jquery-rails -v 3.1.4

Open in new window


I have just did a clean Ubuntu 15.10 and started installing Ruby, however I am thinking, should I have installed Apache first? Is there an order to installing RoR for Apache, where I need to be in the apache directories for GEM commands?

I am a Linux newbee, thanks in advance!
0
I am trying to install redmine (a ruby based bug tracker) on a goDaddy VPS running ubuntu 15.10. I got the app to install on my dev box using Ubuntu 16.04, however GoDaddy does not offer that as an option for VPS.

For the most part things are working and from what I gather, to get over the 500 error I am getting now, I need to run:
sudo RAILS_ENV=production bundle exec rake db:migrate

Open in new window


And here is where things become harder than the documentation. Now when I run the command I am given the output of:
W: `require 'RMagick'` is deprecated, please change to `require 'rmagick'`

Open in new window


This is where I am over my head for Linux. I am sure this is an easy fix, but I have no idea where to look. I swear I installed Ruby 2.3.3 before I rebooted, however when I run
ruby -v

Open in new window

I get
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

Open in new window

. When I run
sudo rails -v

Open in new window

, I get
Rails 4.1.10

Open in new window

.

Again, I just want to get this command to run:
sudo RAILS_ENV=production bundle exec rake db:migrate

Open in new window

, please help.
0
I just spun up an Ubuntu 15.1 server on GoDaddy VPS.

I am trying to get a ruby web app working, when I enter command:
 ruby -v

Open in new window

I get  back: ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

however, in my home directory I see a folder named ruby-2.4.0. Why is my Ubuntu server not using Ruby 2.4?
0
http://www.cchr.org

this website has a very organized layout

what language
or what content management system is used
0
Hello,

I have two versions of SASS installed.

SASS (3.4.22, 3.4.21)

Should I uninstall one of them, or leave as is?

If i should uninstall, what command shall I issue at the command line? I am running windows10.

Thanks
0
Hello,

I have installed the following gem:

https://rubygems.org/gems/autoprefixer-rails

The documentation states the following:

Ruby on Rails
Add the autoprefixer-rails gem to your Gemfile:
gem "autoprefixer-rails"

Clear your cache:
rake tmp:clear

I found a file named 'Gemfile', at the following location:
C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\autoprefixer-rails-6.5.4

I opened the file, which had the following line
eval_gemfile "#{ File.dirname(__FILE__) }/sprockets4.gemfile"

Open in new window

i added the line,
gem "autoprefixer-rails"

Open in new window

just underneath and saved

Is this what was needed?


About the cache instructions:

I issued the command rake tmp:clear, from the following two locations
C:\Devkit
C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\autoprefixer-rails-6.5.4

I received the error response

rake aborted!
No Rakefile found

Open in new window



Also, there are separate instructions for Ruby on rails, and separate instructions for Ruby. What is the difference?

Thanks for your help!
0
I am migrating an existing Ruby on Rails application.   I have setup a development environment in Ubuntu with Ruby 1.8.7 and Rails 2.3.12 and SQLite 2.8.17.

I would like to download the production source and install on the development computer.   What do I need to download and move?
0
I’ve been trying to find alternatives to using sleep for some time and it seems that every single suggested method to avoid using sleep never works and I’m at the end of my rope.

      it 'finds the correct product when searching by job type', js: true do
        fill_in('filterrific_for_work_type', with: 'Central')
        # once again, sleep feels like the only thing that works
        #sleep 1 # TODO: find a better way..
        expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
        expect(page).to have_link('IP Central Report',
                                  href: work_queue_item_path(@release.id))
      end

Open in new window


I also have this wait for ajax helper:

module CapybaraHelpers
  def wait_for_ajax
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end
end

Open in new window


And in spec_helper.rb:

RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
End

Open in new window


This test breaks unless I add the sleep 1.  and I’ve tried so many iterations using things like ‘within’ ‘find’, ‘have_content’ ect.  This is really driving me crazy.
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I’ve been trying to find alternatives to using sleep for some time and it seems that every single suggested method to avoid using sleep never works and I’m at the end of my rope.

     it 'finds the correct product when searching by job type', js: true do
        fill_in('filterrific_for_work_type', with: 'Central')
        # once again, sleep feels like the only thing that works
        #sleep 1 # TODO: find a better way..
        expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
        expect(page).to have_link('IP Central Report',
                                  href: work_queue_item_path(@release.id))
      end

Open in new window


I also have this wait for ajax helper:

module CapybaraHelpers
  def wait_for_ajax
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end
end

Open in new window


And in spec_helper.rb:

RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
End

Open in new window


This test breaks unless I add the sleep 1.  and I’ve tried so many iterations using things like ‘within’ ‘find’, ‘have_content’ ect.  This is really driving me crazy.
0
There are two models:

    # == Schema Information
    #
    # Table name: news
    #
    #  id         :integer          not null, primary key
    #  title      :string           not null
    #  content    :text             not null
    #  scope      :string           not null
    #  created_at :datetime         not null
    #  updated_at :datetime         not null
    #  person_id  :integer          not null
    
    # == Schema Information
    #
    # Table name: likes
    #
    #  id        :integer          not null, primary key
    #  like      :boolean
    #  person_id :integer          not null
    #  news_id   :integer          not null

Open in new window


Relation

    news has many likes
    like belongs to news

Open in new window

I want to get most liked news from query. Query should subtract count of likes equal true from likes equal false. The highest number is most liked news.
What I tried:
@most_liked_news = News.joins(:likes).where('likes.like = ?', true).group('news.id').order('COUNT(likes.like) DESC').first

Open in new window

Above returns news that has most positive likes. But it's not all good, because e.g. post with 10 positive and 1 negative will be better than post with 20 positivie and 15 negative(10 - 1 > 20 -15)
0
There are three models:

    # Table name: activities_people
    #
    #  activity_id :integer          not null
    #  person_id   :integer          not null
    #  date        :date             not null
    #  id          :integer          not null, primary key
    #
    # Table name: activities
    #
    #  id          :integer          not null, primary key
    #  name        :string(20)       not null
    #  description :text
    #  active      :boolean          not null
    #  day_of_week :string(20)       not null
    #  start_on    :time             not null
    #  end_on      :time             not null

Open in new window


Third model is people.
Associations:

 
  class Activity < ActiveRecord::Base
      has_many :activities_people
      has_many :people, through: :activities_people
    end
    
    class ActivitiesPerson < ActiveRecord::Base
      belongs_to :person
      belongs_to :activity
    end
    
    class Person < ActiveRecord::Base
    has_many :activities, through: :activities_people
    end

Open in new window

Issue:
I don't know how to create validation method in ativities_person.rb to protect joining on activities, that my other training interests overlaps timely.

Example:

person_id:1 join to activity, that will 08.08.2016(date) and last 09:00(start_on) - 10:00(end_on).
 Same person want save to another activity, that will also be 08.08.2016 and last 09:30(start_on) - 10:30(end_on). Now
validation should throw error that he's save to other activity in same time(time ranges overlap). Validation first should check that dates match, next should check time overlaps of activities.

What I tried:

 

Open in new window

0
Hi there, recently our business has started to request the need for remote data and or a portal page for our clients.
I have developed in ASP.net (ASP.NET Core) and I have done some research on web api and how it works.
My question is this, what is the general structure for business applications? Is there usually a back-end server program that interacts internally with the company database to process/send request such as web-api that then forwards them to an internal or externally hosted application such as a rails/asp.net site. Or are these generally lumped together into one single application hosted internally? We currently are using WCF services for an in-house mobile application so my thoughts were creating an api that we could use for any existing and future projects to use. Mainly the goal I want to achieve is a reusable system.

Thanks for any help.
0
I have two models, `Genre` and `Book`. They both have a `has_and_belongs_to_many` association.
What i'm doing is scraping a site and collecting the information of each book. I'm running into an issue updating genres to an existing book and genre in my DB.

Below is an example of how my array of genres are going to come out.

    genres = ["Action", "Drama", "Romance"]

I was thinking of doing this to check if i already have the genre in the database and if it does exist it will update it.

    genre = Genre.where(title: genres).first_or_create
    anime.update(genres: genre)

I end up getting this error.

    `undefined method `each' for #<Genre:0x007f9059868bc0>

Is there a simple way for me to do this? This would really help me.
0
#
# Check OS platform to ensure this only executes on Windows
#

include_recipe "chef_handler"

powershell_script do
  code <<-EOH
  ###############
  # Title:
  #
  #
  # Description:
  # Returns 1 if any share or share path allow read/write by the 'Everyone' group (fail)
  # Returns 0 if this condition is not found (pass)
  #
  #
  # 0.1
  ###############

  Try
  {
    #get all shares
    $shares = Get-S | Select-Object Name,Path
    if($shares)
    {
      Foreach ($share in $shares)
      {
        #check share for everyone permissions
        $shareAccounts = Get- -Name $share.Name
        Foreach ($account in $shareAccounts)
        {
          If ($account.AccountName -eq 'Everyone')
          {
            return 1
          }
        }

        #check underlying NTFS path for everyone permissions
        $volum= Get-$share.Path
        if ($volumePerm.Access.Where({$PS -eq 'Everyone'}))
        {
          return 1
        }
      }
    }
    else
    return 0
    #loop through each share checking for 'Everyone'
    # How to pass the return values and send to Chef or something else.
  }
  Catch
  {
    #build error message
  }
  Finally
{
#Return  some final message
}
EOH
   fail "instance has failed the check" if code == 1
End

Please respond with an example, as I think I'm looking at this the wrong way. I see it as a more complex effort - like having to write out a temp file. The client doesn't see …
0

Ruby

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Top Experts In
Ruby
<
Monthly
>