Title photo
frugal technology, simple living and guerrilla large-appliance repair
Thu, 16 Jun 2016

OMG, the @railstutorial by @mhartl

OMG, the @railstutorial by @mhartl https://www.railstutorial.org/book

The /now page movement

The /now page movement -- it's what you're doing now http://sivers.org/nowff and http://nownownow.com

The Bastards Book of Ruby

While it calls itself out as old and out of date, I really like The Bastards Book of Ruby.

I recognize that Ruby is no longer the new hotness, but it's still so useful and, dare I say, user-friendly. For those reasons, I'd love to see updated versions of just about every book out there.

I'm using the old (as the hills) "Learning Ruby" by Michael Fitzgerald (2007, O'Reilly), The Pickaxe book ("Programming Ruby") from Ruby version 1.9.2 (2010/11, Pragmatic Programmers, though do I realize there is a 2013 edition).

The beginners books seem to be the oldest. At my level, everything seems to be working, so I will maybe complain a little less.

I do have a Rails book, "Rails Crash Course," by Anthony Lewis, that's much newer, but I'm not there quite yet. And there's always Michael Hartl's "The Ruby on Rails Tutorial", of which the more I see, the more I like.

Using Ruby to delete blocks of text across multiple lines

I tend to learn things in programming when I have a problem to solve. This is just such a case.

I was working with a huge XML file, and I needed to trim elements out of it that begin with <generic tag> and end with </generic tag>, and include a random amount of text and other tags, across multiple lines, in between.

At first I tried using the Nokogiri gem, but it just wasn't happening. I was working on my Election Results script, and ... the election -- they hold it on a certain date, you know.

I would have to brute-force it. Like I always do.

My whole idea this cycle was to dump my giant sed hack from elections past and use mostly (if not all) Ruby to parse the XML I get from the state of California and provide the JSON output my fellow dev needed for the front end. (I also have a ton of fixed-width ASCII from Los Angeles County to deal with, as well as scraped HTML from San Bernardino County, but those are other tales for other times.)

With the state data, I had the XML-to-JSON conversion covered with Ruby's Crack gem. But I just couldn't pare down the XML to make the JSON a manageable size.

Read the rest of this post

Wed, 15 Jun 2016

A great Ruby loops tutorial from Prograils

A company called Prograils offers a great tutorial, Loops in Ruby - all possible approaches.

It looks like a good reference for when you're writing a Ruby program and need to figure out which kind of loop will work best in a particular situation.

Tue, 14 Jun 2016

I used Firefox a bunch

I've been using Firefox version 47 for the past couple of days. And it's been working well. This isn't for my day job, where I beat the hell out of the browser, but for "research" (aka looking things up) while learning programming.

Nothing cost $ .

I should probably give it a try for my real work and see how it holds up.

Update: Firefox did better than I thought but not good enough.

Slow rendering in Google Maps was annoying.

It couldn't handle Tweetdeck at all. Nobody would (or should) argue that Tweetdeck is anything but a mess. It is built with unwieldy amounts of JavaScript and delivers messes (or masses) of data. Trying to run Tweetdeck in Firefox was a parade of "unresponsive script" pop-ups that had me bailing out for Chrome within the hour.

I want Firefox to be competitive. I'd rather have fewer eggs in Google's basket. But my web production workflow is just too many windows of pain.

Quick Ruby: Open and write a file

Need to open an existing file, create a new one and write to that file in Ruby?

This Stack Overflow answer makes it super simple.

I already used this in one of my little Ruby programs.

In the same thread (but earlier), here's another one.

Coding Horror: It's a UNIX system, I know this

Coding Horror: It's a UNIX system, I know this https://discourse.codinghorror.com/t/its-a-unix-system-i-know-this/4378

Sun, 12 Jun 2016

Learning Ruby: Loops and arrays

This entry shows what I'm doing when I practice programming. I find it helpful to write little programs that use the concepts I'm trying to learn.

Why Ruby? you might ask. No particular reason. I've spend a semester learning C++, and I was pleasantly surprised to find out that the things I learned are applicable in many other programming languages. Ruby is one of them.

Writing scripting-type programs is one of the things I do. I have "practiced" recently with Bash (and all the little Unixy utilities that go along with it) and Perl (for the add-on that does the statistics for this blog).

Ruby just happens to interest me. I'm also interested in Elixir, but for the kind of things I'm interested in doing right now, Ruby with its many, many Gems and "make programmers happy" philosophy looks like a good fit.

I could say the same thing about Perl (or Python, or Java), but for now I'm playing around with Ruby.

I find that writing little programs like these is a great way to learn. And writing the "same" program in different languages is also very helpful. I could re-write this one in, say, Perl or JavaScript (using either Node in the console or rendering it on an HTML.

Here is the program I wrote to practice using Ruby loops and arrays. I also worked with strings (and converting arrays to strings and back again) and outputting results to the terminal.

What is an array? Here's what it is (in my mind anyway): A collection of pieces of data that can be manipulated as a whole. You can mix numbers and strings. In Ruby, arrays can even contain other arrays. I read that somewhere.

Here is the program:

#!/usr/bin/env ruby

=begin

The purpose of this program is to experiment
with Ruby loops, arrays, strings, integers and output.

The program creates an array, uses loops
to *push* numbers into that array, shows what
the array looks like at every stage using *puts*
and *inspect*, then uses *shift* to remove
numbers from the array, also showing
what it looks like at every stage.

There are two more loops in this script.
One prints out numbers ascending, the other
descending. 

=end

# Create an array

number_array = Array.new

# loop uses *push* to add a number,
# *puts and *inspect* to print it

(1..10).each do |i|
    number_array.push(i)
    puts number_array.inspect

end

# loop uses *shift* to remove
# an array element
# 1...10 with three dots runs
# the loop until 9, not 10

(1...10).each do |i|
    number_array.shift
    puts number_array.inspect
end

# *puts* on its own adds a blank line

puts

# *print* prints the output without adding
# a newline character (aka \n) like *puts*

for i in 1..10
    print i
    print " "
end

puts

10.downto(1).each do |i|
    print i
    print " "
end
Fri, 10 Jun 2016

Ruby for Admins

There's a great book available on the web, "Ruby for Admins."

Grammatically it's a little rough -- I would love to contribute via GitHub if that was available -- but the information seems solid.