If you work with the vi editor a lot, you'll find yourself tinkering with various vi configuration settings from time to time. Many times you'll want to modify the configuration of your current vi session, and to do that you'll use one of many available vi set commands. In this vi (and vim) tutorial, I'll share the vi set commands I use most often.
A couple of things happened recently that make me feel like a piece of meat in the organ grinder of life. First, I was in talks with a publisher about publishing a book with them, and their contract began, “You grant to Us ... the exclusive right to ... sell and otherwise commercially exploit your Work.” I thought, “Well, I guess that’s what work is about, organizations exploiting your work for their commercial profit,” but their writing felt dirty and sleazy, like it was totally controlled by a scumbag lawyer or CEO.
Next, I live in the Terracina apartments in Broomfield, Colorado, and they were recently bought by a new company. With the old company everything here felt like a family, but when the new company bought the place they fired the previous staff, and with most of the new staff it feels like I’m just a number. When I walk in the office the reception feels like, “Number 232 ... you always complain that your kitchen range is vibrating because your downstair’s music is so loud, what do you want? We’re trying to make a lot of money here and you’re a troublemaker.” Twice the office manager has barely looked away from her computer monitor while talking to me.
Both situations remind me of the Bon Seger song, Feel Like a Number.
Scala FAQ: How do I get the current month as an integer or as a string in Scala?
This short blog post contains a collection of Scala number and date examples. I created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe the examples here much at all, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).
Scala numeric types
Scala has these numeric types:
The new scala-lang.org docs website looks great. It’s also a reminder to me that I probably didn’t stress enough in the Scala Cookbook that everything in Scala is an object, including numbers. (Hopefully I made it clear that functions are objects.) This Scala REPL example shows some of the methods that are available on Scala integers (
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.5, “Comparing Floating-Point Numbers in Scala.”
You need to compare two floating-point numbers in Scala, but as in some other programming languages, two floating-point numbers that should be equivalent may not be.
Scala FAQ: How can I format numbers and currency in Scala, such as to control the number of decimal places and commas in the values, typically for printed output.
For basic number formatting, use the
f string interpolator shown in Recipe 1.4 of the Scala Cookbook, “Substituting Variables into Strings”:
scala> val pi = scala.math.Pi pi: Double = 3.141592653589793 scala> println(f"$pi%1.5f") 3.14159
A few more examples demonstrate the technique:
Scala FAQ: I’m writing an application and I need to use very large integer or decimal (floating-point) numbers; what’s the best approach?
Use the Scala
BigDecimal classes. You can create a
scala> var b = BigInt(1234567890) b: scala.math.BigInt = 1234567890
Scala FAQ: How do I parse a number (
Float, etc.) from a
String in Scala?
to* methods that are available on a
String (courtesy of the Scala
Play Framework form mapping field validators (boolean, text, nonEmptyText, date, email, number, etc.)
The Play Framework scala.play.api.data.Forms object provides form validation helpers (which I've also seen referred to as mappings, data manipulation helpers, and constraints) such as these: