line

How to process every line in a file with a Unix/Linux shell script

Unix/Linux shell script FAQ: How do I write a Unix or Linux shell script where I "do something" for every line in a text file?

Solution: An easy way to process every line in a text file is to use a Unix/Linux while loop in combination with the Linux cat command, like this:

A custom TextMate 2 bundle to underline the current line

I just created a TextMate 2 bundle to underline the current line, and this image shows how I created that bundle. The dashed-line will be the same length as the line the cursor is currently on (the current line). I do this a lot when I use TextMate to write notes and even Markdown text, so I wanted a little script/bundle like this.

FWIW, the result of this bundle/command is that I can have the cursor be on a line like “Hello, world,” as shown below, press [Command][u], and end up with this:

Hello, world
------------

Scala/Java 2D: How to draw lines and arcs

This code may not make much sense without seeing the end result, but ... the following source code shows how to draw lines and arcs in Scala and Java:

Ruby command line arguments

Ruby FAQ: How do I read command line arguments in a Ruby script (Ruby command line args)?

To read command line args in a Ruby script, use the special Ruby array ARGV to get the information you need. Here are a few examples.

1) Getting the number of command line args

To get the number of command line arguments passed in to your Ruby script, check ARGV.length, like this:

The Vim goto line number command

Vim FAQ: What is the Vim go to line number command? (Or, how do I go to a specific line number in vim?)

In short, you use the capital letter 'G' in Vim command mode to move to a specific line number. Here are several Vim goto line number example commands:

Vim insert commands

Vim FAQ: What is the Vim insert command?

Short answer: Type the letter 'i' while in Vim command mode. You'll then be able to type text into your document, right where the cursor is currently positioned.

Vim insert commands

Longer answer: There are several other variations of the Vim insert command you can use:

How to draw a straight line in Gimp

It's embarrassing to say how long I've been using GIMP without knowing how to draw a straight line, but ... skipping that story ... here's a quick tutorial on how to draw a straight line with GIMP.

GIMP straight line: Step 1

Step 1 in the process is to have an image you want to draw a straight line on. I'll assume you have a practical image you're working with, but for my purposes, I'll be drawing a straight line in black, on a white canvas. Here's my white canvas:

How to process every line in a text file with Ruby

There are quite a few ways to open a text file with Ruby and then process its contents, but this example probably shows the most concise way to do it:

# ruby sample code.
# process every line in a text file with ruby (version 1).
file='GettysburgAddress.txt'
File.readlines(file).each do |line|
  puts line
end

As you can see, this example code is very concise, and inside the processing loop you can do whatever you need to do with the line variable.