remove

Ubuntu ‘apt-get’ list of commands (cheat sheet)

I have a couple of Ubuntu Linux systems, including Raspberry Pi systems, test servers, and production servers. It seems like every time I have to use an apt-get or other apt command, I always have to search for the command I need. To put an end to that, I’m creating this “apt-get reference page.” It’s very terse, as I’ve just written it for myself, but I hope it’s also helpful for others.

How to drop the first matching element in a Scala sequence

Summary: This blog post shows one way to drop/filter the first matching element from a Scala sequence (Seq, List, Vector, Array, etc.). I don’t claim that the algorithm is efficient, but it does work.

Background

While creating some Scala test code earlier today I had an immutable list of toppings for a pizza, and I got into a situation where I wanted to remove the first instance of a topping.

PHP: How to remove non-printable characters from strings

PHP FAQ: How do I remove all non-printable characters from a string in PHP?

I don’t know of any built-in PHP functions to remove all non-printable characters from a string, so the solution is to use the preg_replace function with an appropriate regular expression.

Scala: How to delete documents in a MongoDB with Casbah

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.8, “How to delete documents in a MongoDB with Casbah.”

Problem

You want to delete one or more documents in a MongoDB collection.

Solution

Use the findAndRemove method of the Casbah MongoCollection class to delete one document at a time, or use the remove method to delete one or more documents at a time.

Scala: How to add, update, and remove elements with immutable Maps

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.16, “How to Add, Update, and Remove Elements with Immutable Maps”

Problem

You want to add, update, or delete elements when working with an immutable map.

Solution

Use the correct operator for each purpose, remembering to assign the results to a new map.

To be clear about the approach, the following examples use an immutable map with a series of val variables. First, create an immutable map as a val:

Scala: How to add, update, and remove elements with a mutable Map

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.15, “How to Add, Update, and Remove Elements with a Mutable Map”

Problem

You want to add, remove, or update elements in a mutable map.

Solution

Add elements to a mutable map by simply assigning them, or with the += method. Remove elements with -= or --=. Update elements by reassigning them.

Given a new, mutable Map:

Scala Maps (Map class examples)

Here's a quick look at how to use the Scala Map class, with a colllection of Map class examples.

The immutable Map class is in scope by default, so you can create an immutable map without an import, like this:

val states = Map("AL" -> "Alabama", "AK" -> "Alaska")

To create a mutable Map, import it first:

Tell Git not to track a file any more (remove from repo) alvin January 21, 2012 - 10:45am

Git rm FAQ: How do I tell Git not to track a file (or files) any more? That is, I want to remove the file from the Git repo?

While working on an application named "sarah" yesterday (named for the house known as "SARAH" in the tv series Eureka), I accidentally checked some files into Git that I didn't mean to. These were were primarily binary files in my project's "bin" and "target" directories.