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

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
Free Tool: IP Lookup
LVL 9
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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
http://www.cchr.org

this website has a very organized layout

what language
or what content management system is used
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
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
#
# 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
I have several rows of twin radio buttons that are generated via a loop in ruby on rails.  For each row, one of the button is already selected, how do i detect if the user accidentally click on a radio button that's already selected?  Keep in mind these buttons all have generated ids so I can just look for a specific id.  Can someone show me how to do this via ruby on rails or javascript?  Thanks.
0
Hello I have two XML files that I need to merge into one. I am able to use Python or Ruby to accomplish this and so far I have had little to no success.

The two XML files are as follows (unfortunately due to very restrictive licensing they can not be shared):

Products.xml
Ingredients.xml

The products XML has over 1000 nodes(if that is the right term) for each product. One of those "nodes" is UPC which is unique. The ingredients XML files has over 500k ingredients that are all individual but match to the product by UPC.

So I am trying to merge the ingredients to the products using UPC as the unique identifier. Any help on this would be greatly appreciated.
0
Hello, I am trying to update a Ruby script that looks in html files downloaded from the IRS site and finds specific text in the file to extract the Year from the document.   The script works fine however there are not 2 types of documents that can be in the folder and the line in question is different in each document.  How can I add an "or" or "if" clause so the script looks for the text formatted either way and pulls out the year based on how the line of text reads.   The line currently in the file is displayed as "TAX PERIOD:    DEC. 31, 2014"  The line in the 2nd document that I need to add is displayed as "Tax Period or Periods:  December, 2014"  I would need the year "2014" extracted from each document.   I have attached screenshots of the script in color and the 2 document types.

 
#Open and read the downloaded file
	transcript_html_name = files_in_dir[i]
	File.open(Dir.pwd + "/Transcripts/#{transcript_html_name}", "r") do |f|
		f.each_line do |line|
			 #Search for the Tax Period date to get the year
			if line.include? "TAX PERIOD:" 
				line.gsub!(/(<[^>]*>)|\n|\t/s) {""}
				line.slice!("TAX PERIOD:")
				line.gsub!(/\w\w\w[.]\s\d\d[,]\s/) {""}
				year = line
			end

Open in new window

script.jpg
document-sample-1.jpg
document-sample-2.jpg
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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 am creating a short Ruby script to kill a stuck process. I checked the syntax (see attached script) and I get the error message below. Please help.

______________

killProcStk.rb:24:in `block in <main>': undefined method `*' for nil:NilClass (NoMethodError)
      from killProcStk.rb:21:in `each'
      from killProcStk.rb:21:in `<main>'
ruby_script.txt
0
Can Sql Server be configured with Ruby?
0
Hi,

Im getting this error while trying to access a https URL.

[2016-01-14 14:42:58] ERROR OpenSSL::SSL::SSLError: SSL_accept SYSCALL returned=5 errno=0 state=SSLv2/v3 read client hello A /usr/lib/ruby/1.8/openssl/ssl-internal.rb:174:in `accept'

Im not knowledgeable in this area but looking around and in the rb file I found this: DEFAULT_PARAMS = { :ssl_version => "SSLv23", :verify_mode => OpenSSL::SSL::VERIFY_PEER, :ciphers => "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW", :options => OpenSSL::SSL::OP_ALL, }

I treid already to change the ssl_version to TLSv1 and tried to access the URL again but I got the same error...

Any suggestion on how to solve this?

Tks
0
Just getting started with using chef recently.  I have created custom JSON in AWS Opswork and trying to access it as an attribute in Chef recipe, but its failing to grab the JSON values. JSON file looks like.
{
 "normal": { 
 "filbeat": {
 "log_path" : "/var/log/*.log",
 "hosts" : "Some Random Host ID", 
 "port"  : 5000
 }
 }
}

Open in new window


and I am trying to catch it in recipe as,

log = node['filebeat']['log_path']
hosts = node['filebeat']['hosts']
port = node['filebeat']['port']

Open in new window


But it failed, I have also tried without 'normal'. I got the some []null class error.
0
I have a multi-select dropdown, eg:
<select id="mySelect" multiple="multiple" onchange="myFunction(event)">
  <option value="Audi">Audi
  <option value="BMW">BMW
  <option value="Mercedes">Mercedes
  <option value="Volvo">Volvo
</select>
What will the myFunction look like? I've found examples with single-select but not multi-select.
The user would have to use Ctrl + Click or Shift + Click to select multiple options. Let's say for now, i just want to print out the values selected to the console.
0
Hello and thanks in advance for your help.

I am trying to install redmine on an ubuntu server. I am on the step where I am trying to call:

bundler update

And it errors out on installing rmagick. When I try:

sudo gem install rmagick

I get Error installing rmagick. Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb

I am not even sure why its using 1.9.1 ruby because when I do ruby -v I get ruby2.2.2p95 etc...

After looking around on line, I found that I need to install imagemagick, so I tried:

apt-get install libmagickwand-dev

and this gives me an error as well:
error: template infile /usr/share/redmine/templates/database.yml.template does not exist
dpkg: error processing package redmine (--configure):
 subprocesses installed post-installation script returned error exit status 1
Errors were encountered while processing: redmine.

I am not sure what I can do at this point, and I am new to Ubuntu and the terminal so I apologize ahead of time.

Any help would be much appreciated.
Thank you.
0
I am new to Ruby. I have a Rakefile. How do i run a Rakefile?
0
Need to validate that the date entered is a certain day of the week.

View:
   
      <div class="form inline">
       <%= f.label :meeting_date, "Meeting Date" %>
      <%= f.date_select :meeting_date, :class => 'form_control date_select datetest'  %>
      </div>
     

I am looking for a way to validate that this "meeting_date" is valid and a particular day of the week.
0
I currently have a list of ip addresses that I would like to have a ruby script for loop though and find an ip address that is not pingable and cannot ssh to. I'm new to ruby so I am not sure what gems I would use to accomplish this but I am guessing I will need net::ssh at some point. ... however since some of the IP in the list might be Windows boxes it might be better to have something more telnet or nc like attempt to connect to known services on known ports. Can anyone help me get started with this?
0
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

In Ruby how can I take a command put stdout in a variable or array?


# bosh deployment | awk  -F"\`|'" '{print $2}'   ---This is the bash command
/opt/app/cloudfoundry/cf/manifests/cf_openstack_bdpaas_enterprise.yml   --here the output I want to put in a variable or array.

try below but not woking.
$ymlfile = %x(bosh deployment | awk  -F"\`|'" '{print $2}')
puts $ymlfile

This not not work as well.
$ymlfile = `bosh deployment | awk  -F"\`|'" '{print $2}'`
puts $ymlfile
0
Hi
I have a large text file and need to remove any duplicate rows - eg
example text (original)
select *
from table1
table 1
table 1
select * from ref where
table1
etc etc
...what I want returned is ....
select *
from table1
table 1
select * from ref where
table1

Regards
0
How to use sed to replace a pattern out of a file?

Below is the line in rsyslog.conf that I am trying to replace.
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

Want to replace it with this line:
*.*;mail.none;authpriv.none;cron.none,local1.none,local2.none,local3.none,local4.none,local5.none,local6.none /var/log/messages

try to use sed but can not get it to work correctly. Need some help on the best way to replace this line.
0
I just installed chef using omnibus:

curl -L https://www.chef.io/chef/install.sh | sudo bash

I got below error:
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

You are installing an omnibus package without a version pin.  If you are installing
on production servers via an automated process this is DANGEROUS and you will
be upgraded without warning on new releases, even to new major release.
Letting the version float is only appropriate in desktop, test, development or
CI/CD environments.

Open in new window


Now I would like to understand how it will be upgraded to new version when it gets released?
0
Hi

I want to be able to use a regular expression which goes through a large txt file where all my Packages (around 100) are kept.
The objective is for the ruby script/regex to return the Package name and the tables and joins used.

CREATE OR REPLACE PACKAGE TEST
SELECT *
FROM
TABLE1
INNER JOIN TABLE2 ON TABLE1.ID = TABLE2.ID
LEFT JOIN  TABLE3 ON TABLE1.REF = TABLE3.REF
WHERE TABLE1.ID > 14


CREATE OR REPLACE PACKAGE TEST2
SELECT *
FROM
TABLE1a
INNER JOIN TABLE2a ON TABLE1a.ID = TABLE2a.ID
LEFT JOIN  TABLE3a ON TABLE1a.REF = TABLE3a.REF
LEFT JOIN  TABLE4  ON TABLE4.NAME = TABLE2a.NAME
WHERE TABLE4.NAME IN ('FRED','BRIAN')

etc etc


ouptut file would read as .......

CREATE OR REPLACE PACKAGE TEST
TABLE1
INNER JOIN TABLE2 ON TABLE1.ID = TABLE2.ID
LEFT JOIN  TABLE3 ON TABLE1.REF = TABLE3.REF

CREATE OR REPLACE PACKAGE TEST2
INNER JOIN TABLE2a ON TABLE1a.ID = TABLE2a.ID
LEFT JOIN  TABLE3a ON TABLE1a.REF = TABLE3a.REF
LEFT JOIN  TABLE4  ON TABLE4.NAME = TABLE2a.NAME

any help much appreciated.

Regards
0
How to capture my stdout when run Ruby script and place in log file.
Would like to run a Ruby script and place stdout,stdin,stderr into a log file.
Would want the specific where the logs would be placed and put a tdate time stand on log file name.

#!/usr/bin/env ruby

 require 'rubygems'
 require 'net/ssh'

USER = 'root'
hosts = ['server1', 
         'server2', 
         'server3',
         'server4',
         'server5', 
         'server6',]

cmd = ['hostname',                                                                         
            'df -h', 
            'servicce rsyslog status',                                        
            "echo \'*** ****\'",                                                    
            "echo \'*** ****\'",]

hosts[0..2].each do |host|
      Net::SSH.start( host, USER ) do |ssh|
 for cmds in cmd[0..9].each
 result = ssh.exec! cmds
 puts result
   end
 end
end    

hosts[3..5].each do |host|
      Net::SSH.start( host, USER ) do |ssh|
 for cmds in cmd[0..2].each
 result = ssh.exec! cmds
 puts result
   end
 for cmds in cmd[4..6].each
 result = ssh.exec! cmds
 puts result
 result = ssh.exec!("echo \'*** ****\'")
 puts result
  end
 end
end    

Open in new window

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
>