Show HN: Ruby One-Liners Cookbook

asicsp | 191 points

Ruby is based on programming languages like Perl, Smalltalk, Eiffel, Ada, and Lisp. Many cli options are same as Perl and behave similarly too. While Ruby would be slower compared to sed/awk/perl, I find it a pleasure to use Ruby's built-in array/enumerable methods, blocks, etc.

---

The post links to the web version of the ebook. You can download pdf/epub versions using the links below (free until this Sunday)

* Ruby one-liners cookbook: https://gumroad.com/l/ruby-oneliners or https://leanpub.com/ruby-oneliners

* Bundle of one-liners and Regexp: https://gumroad.com/l/ruby-textprocessing or https://leanpub.com/b/ruby-textprocessing

Also, my 6 book bundle (regular expressions and grep/ripgrep/sed/awk) is priced $5 until Sunday:

* https://gumroad.com/l/regex/off10

* https://leanpub.com/b/regex/c/off10

---

Writing a book: is it worth it? (https://news.ycombinator.com/item?id=24628549)

For my unique circumstances, emphatic yes. I left my job more than 6 years back for various reasons. I tried a few things that didn't work out.

Before I left the job, I had been conducting yearly workshops at my college for electronics students to get started with command line, vim, perl/python, etc. For reference material, I used provide a few slides. As something to keep me mentally occupied, I started with word document, then moved to GitHub/Gitbook. My awk tutorial (https://news.ycombinator.com/item?id=15549318) hit front page and combined with sharing on other social sites, I started getting decent traffic to my GitHub repos. My primary aim with these resource materials was to share with workshop students. Since I had failed to earn outside of workshops and my savings were dwindling, I tried putting donation button on GitHub (sponspor wasn't introduced at that time). Didn't work out.

Finally, about two years back, kinda like a last try before I was forced to look for a job again, I self-published Ruby Regexp book. Didn't earn much, but couple of months later, I used this material to publish Python regex book. This was received much better, got me about $250 in initial sales.

I live alone in outskirts of a city in India, and my modest lifestyle needs about $150 per month to cover my living expenses. Last year, ebook sales and workshops nearly covered my expenses. This year, pandemic put a stop to my workshops. But, ebook sales has more than covered for it so far.

I have a sustainable income again. About 20k free copies given away and all my books are now free to read online. It is worth it.

asicsp | 4 years ago

I recently picked Ruby up again after about a year of JS and Python. I instantly fell in live again due to how simple it is to do anything with Ruby.

Rails is a breath of fresh air after trying to maintain hand-rolled solutions. The productivity gains are incredible. With Ruby 3 coming soon it seems like the performance of the language has drastically improved. I’m excited to see ruby continue to flourish.

jmarchello | 4 years ago

Very similar to this idea, simply using ‘irb’ for one-off data munging and simple automations is very handy. That’s one of my go to tools when I am not sure exactly what I want to do with the data, and being able to poke at the intermediate steps as I transform it is handy. If I then come up with a pipeline that is useful, it only takes a minute to copy paste what I figured out in IRB to a file and save it as an executable script for future use.

burlesona | 4 years ago

It’s fascinating to me that the mindshare that was once taken up by Perl seems to slowly but surely be replaced by Ruby. This is a positive, IMO. Compared to Perl, Ruby is easier to write and — more importantly — read.

revscat | 4 years ago

I get a lot of mileage out of

    command | ruby -e 'ARGF.each { |line| #do stuff with line }'
jfhufl | 4 years ago

Ruby, like Perl, is really built to be a part of a *nix system and has some bash elements (like special variables).

It's a natural fit for one-liners.

jrumbut | 4 years ago

Ruby brings me joy of programming. Like this morning, doing a report for year, month and getting the last day of the month is absolute genius: Date.new(year, month, -1) # wow

oogway8020 | 4 years ago

Just FYI, the code element color is impossible to see when the page loads its dark theme. Otherwise, looks great.

save_ferris | 4 years ago

Some of these one-liners are clocking in at around 120 characters.

bdcravens | 4 years ago