Show HN: Ruby One-Liners Cookbook
learnbyexample.github.io
learnbyexample.github.io
---
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.
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.
That said, I'm excited to pick up Crystal someday. What are some good niches you've found for it?
[0]: https://crystal-lang.org/2020/03/03/towards-crystal-1.0.html...
It comes through in so many tiny ways!
command | ruby -e 'ARGF.each { |line| #do stuff with line }' ruby_code = ARGV[0]
loop do
line = $stdin.gets()
l = line
break unless line
line.chomp!
final_ruby_code = 'puts "' + ruby_code + '"'
eval(final_ruby_code, binding())
end
Invoked like this: echo foo | rg "The double do: #{l * 2}"
To print: The double do: foofoo
Extremely useful when data munging around. #!/usr/bin/env ruby
if ARGV.size != 1
puts "USAGE: ruby-each-line CODE"
exit
end
STDIN.each_line do |line|
line = line.strip
l = line
eval(ARGV.first)
end ps ax | ruby -e 'ARGF.each { |line| puts line.split.first if line =~ /top/ }'
becomes: ps ax | ruby -ne 'puts $_.split.first if $_ =~ /top/'
It even squashes the extra newline the ARGF version prints out first. ps ax | ruby -ane 'puts $F[0] if /top/'It's a natural fit for one-liners.
If these are readable, then may be your browser+os combo or something else might be the issue? Could you try on a different browser if possible?