spaces

Dart: How to remove leading spaces in a multiline string (using splitMapJoin)

As far as I know, there’s no built-in way to remove spaces from a multiline string in Dart, but you can write your own function to do this. For example, I just dug into the splitMapJoin method of the Dart String class, and wrote a stripMargin function like this:

String stripMargin(String s) {
    return s.splitMapJoin(
        RegExp(r'^', multiLine: true),
        onMatch: (_) => '\n',
        onNonMatch: (n) => n.trim(),
    );
}

The Android “adb shell list files permission denied” error

As a brief note, today I tried to list the files in my Android application, which was running on a physical Android device — a Nexus 9 — with this adb shell command:

adb shell com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser

When I did that, I got an Android/ADB “permission denied” error.

The short story is that a solution to this problem is to run the same command, but with the run-as argument, like this:

PHP - reduce multiple consecutive spaces to a single space

A PHP function that reduces multiple consecutive spaces in a string to one single space, so something like "   " is reduced to " ".

function reduceMultipleSpacesToSingleSpace($text) {
  return preg_replace('/\s+/', " ", $text );
}

Scala methods: dots, spaces, and parentheses

If you've started using Scala, you've seen that there are some cool things in the Scala syntax compared to Java. For instance, in Java you'd execute a method on an object like this:

object.method();

But in Scala you definitely don't need the semi-colon:

object.method()

and then you can omit the parentheses:

Handling spaces in Linux shell script input (and for loops)

Linux shell script FAQ: How can I deal with spaces (blank spaces) in my input data when I'm writing a shell script for loop or while loop?

I was just working on a Linux shell script, and ran into the ages-old problem of handling data that has spaces (space characters) in it. I run into this any time I try to read a data file with blank spaces in it, or when I run into files and directories with spaces in their names. Whenever I try to work this data like this in a shell script for loop, the spaces always ruin what I'm trying to accomplish.

Mac backups: How to handle spaces in filenames with find, tar, and xargs alvin August 27, 2011 - 5:04pm

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

TextMate - converting tabs to spaces (or not)

I finally dug into a problem with TextMate that has been driving me crazy. I always have the TextMate "soft tabs" feature enabled, and want two spaces wherever there was a tab. However, it turns out TextMate doesn't really do what I expect here. Instead of automatically converting tabs to spaces, you have to take an extra step to make this work.

Assume you've just opened an existing document. To convert the tabs in the document to spaces (soft tabs):

How to swap Mac Spaces

Mac Spaces FAQ: How can I move a Mac Space from one Space to another (swap Mac Spaces)?

Last night I learned quite by accident that you can easily move Mac Spaces, or more accurately swap Mac Spaces. To move a Mac Space from one Space to another, just follow these steps:

Mac Spaces: Open a minimized window in the current Mac space

Mac Spaces minimized windows FAQ: How do I open a minimized Mac window in the current Mac Space?

I love the Mac Spaces feature, but it has nearly driven me insane that when I click a minimized Mac application window (a window minimized to the Mac Dock), it changes the current Mac Space to whatever Space that window was opened in before, and then opens the window. 98% of the time I want that minimized Mac window to open in the current Mac Space, not whatever the old application Space was.

How to convert vi/vim tabs to spaces

vim tabs/spaces FAQ: How do I convert vi/vim tabs to spaces?

You can convert tabs to spaces in vim using the usual vim search and replace command. Specifically, this vim "tabs to spaces" command is all you need:

:1,$s/\t/  /g

In short, this command can be read like this: