How Do You Write a Tic-Tac-Toe Program in Ruby?

Problem scenario
You want to write a Tic-Tac-Toe program in Ruby. What should you do?

Solution

# Tic-tac-toe game in Ruby. Written by continualintegration.com.
# We know Ruby is object-oriented. Ideally we will re-write this to encapsulate all logic in objects.
puts “This is a two player game of tictactoe. One person can pretend to be the other player.”
puts “Both players should share a keyboard and monitor.”
puts “The legend for squares in the grid is as follows: ”
puts ” ”
puts “***************************************************************”
puts “ltc is left-top-corner,  » Read more..

How Do You Check If a Variable in Ruby Is a Boolean?

Problem scenario
You want to determine if a variable is being assigned a non-string “true” or “false” data type.  That is, you want to distinguish from a string value of true/false and the Boolean, built-in, supported data type of true/false.  Some programming languages support Boolean or bit values.  Ruby has a number of data types.  There is a feature that Ruby supports to test for most of its datatypes.  By appending to a variable this “.is_a?”,

 » Read more..

How Do You Test If a Variable Is a String or a Numeric Data Type in Ruby?

Problem scenario
You want to test if a given variable is a Numeric or String.  These are built-in data types that Ruby has.

What should you do?

Solution
Append “.is_a? Numeric” or “.is_a? String” to variable.  For an example, here is code that explicitly prints out if the data type is a Numeric or String.

var1 = 123
an = var1.is_a? Numeric
as = var1.is_a?

 » Read more..

Two Error Messages when Installing Gems On Linux

Problem scenario:  You are trying to use gem install, but you get an error like this:
“usr/bin/ruby extconf.rb
mkmf.rb can’t find header files for ruby at /usr/lib/ruby/ruby.h”

Solution:  Install ruby-devel.  For RedHat deriviatives, you can find the rpm here.

=====================================================================================

Problem scenario:  You are running gem install *.gem, and you get ‘ERROR: While executing gem …

 » Read more..

Using a rubyntlm script (http.rb), you get “connection refused.”

Problem scenario:  You modify this script to have a hostname, username, and password of a Windows server with IIS installed.  You add a “puts line” stanza on line 32 for debugging.  You try to run the script with ruby http.rb, but you get “connection refused.”  

Possible solutions:  If you changed the port stanza in the http.rb file from 80, make sure there is no firewall blocking the port in the path to the Windows server. 

 » Read more..

Rubyntlm: Communication from a Linux Server to a Windows Server

Problem scenario:  You modify this script to have a hostname, username, and password of a Windows server on your network.  You add a “puts line” stanza on line 32.

You run the script but you get a message like this: “HTTP/1.1 404 Not Found error. “

Solution:  Make sure that the Windows server has IIS installed, make sure the server name you entered was correct,

 » Read more..

This Command “gem install contint.gem” Hangs Forever

Problem scenario:  You are running gem install *.gem and it hangs.  This stalling appears to be a freeze.  You wait several minutes and nothing happens.  You are waiting for a message or a new prompt.

Solution:  Control-C to get out of it.  Try it again with the “-V” flag like this:

gem install contInt.gem -V

# This time be patient.  Sometimes these commands can take more than 10 minutes to return a message. 

 » Read more..

How To Integrate Perl, Ruby, and Python Programs

Problem scenario
You want a Perl program to call a Python program to call a Ruby program to call another Python program.  You are using Linux as the OS.

Solution
Here is a one-line Perl program (course.pl) that calls a Python program:

system( “python /home/ec2-user/cont.py”);

Here is a two-line Python program named cont.py.  It invokes a Ruby program.

import subprocess
subprocess.call([‘ruby /home/ec2-user/integration.rb’],

 » Read more..

Using Python and Ruby To Read Files

Problem:  You have a Python program that reads in a file named coolFile (in /tmp), and outputs the content to the screen.  The program prints an extra blank line after each line of content of the file named coolFile.  You want the output to not have an extra blank line.  Here is the code:

#/usr/bin/python

x = open(“/tmp/coolFile”, “r”)
for line in x:
        print (line)

How do you have the output now print an extra blank line after each line?

 » Read more..

How Do You Copy Files into a Docker Container from the Server’s Command Line?

Docker is itself a dependency resolution tool.  It is a container that allows a DevOps engineer to prepare one-time an OS environment with nuanced dependencies and configurations for other packages to be installed.

Leveraging the efficiency of a configuration management tool (such as Ansible, CFEngine, Chef, Puppet, and SaltStack) can empower DevOps engineering.  It can also necessitate using duplicative deployments in different environments (development, quality assurance, staging, and production).  Having a backup plan for disaster recovery is also important. 

 » Read more..