background preloader

Ruby for SysAdmins

Facebook Twitter

Cfruby. 0x10 - Security, sysadmin and stuff: A little python vs ruby. Just a little comparison of python vs ruby which nicely sums up why I prefer ruby to python.

0x10 - Security, sysadmin and stuff: A little python vs ruby

Coming from a perl background, parsing strings and manipulating data structures is the bread and butter of sysadmin scripting. Here we're going to split a string, add to the array, then join into a string again. First, in python: a = "a b c".split()>>> a['a', 'b', 'c']>>> len(a)3>>> a.append("d")>>> ",".join(a)'a,b,c,d' Ok, fair enough I guess.

A = "a b c".split=> ["a", "b", "c"] a.size=> 3 a.push "d" => ["a", "b", "c", "d"] a.join "," => "a,b,c,d" Notice the difference? For python, we split the string to get an array. For ruby, we split the string to get an array. To me ruby is far more consistent. Criticisms, suggestions and improvements welcome :) Untitled. Wirble. How Ruby is beating Python in the battle for the Soul of System Administration. I spend most of my days writing either Python or Ruby.

How Ruby is beating Python in the battle for the Soul of System Administration

I enjoy programming in these languages but am painfully aware of their faults. The single process concurrency limitation in both sucks ass. I love that Python is straightforward and predictable but have to admit that I prefer Ruby because I can always bend Ruby to my needs while I sometimes have to change my thinking to fit Python. There are several things about both Ruby and Python that annoy me and make them a poor fit for some of the problems I deal with. Problem #1 is that I need serious concurrency. It is high time for me to expand my skills and learn a new programming language, a process which I don't take lightly.

So how would one select which language to learn? Which am i most likely to use at my day job? Notice that Java does not appear on that list. Id774/sysadmin. Documentation for sysadmin (0.2.0) Documentation for sysadmin (0.2.0) Sysadmin. Ruby for systems administrators. Introduction Ruby is a highly feature-rich, free, simple, extensible, portable, and object-oriented scripting language.

Ruby for systems administrators

It has gained immense popularity of late on the worldwide Web. This popularity can at least partly be attributed to the very powerful Web application development framework, Rails, which is written in Ruby. Rails, or Ruby on Rails ( ROR ), as it is called, provides a very powerful platform to very quickly and efficiently develop a Web application. It is highly scalable and there are many sites on the Web that have been built using Ruby on Rails. Ruby development for system administrators. The function ‘collect’ invokes the function 2*n for each element n in the array numbers.

Ruby development for system administrators

As a result, ‘doubles’ has the content [2, 4, 6, 8, 10]. Most of the built-in Ruby classes such as Array have some methods that use a code block as a parameter, especially for looping, iterating, sorting and mapping. Once you get used to code blocks, they make programming in Ruby quite intuitive. For example, it comes in handy when querying a database: In the first line, we set the #! Other features will be familiar from other programming languages or even shell scripts: for example, running external commands with a backtick or regular expressions.

The value of the variable ‘resolve’ is set to the output of the shell command ‘host address’. Text processing Ruby has great capabilities to process text, which is an important task in many UNIX workflows. This script uses the csv library, where we use the Reader.parse method to read the rows of the CSV file. Did you enjoy this article? Follow our.