static

How to configure Nginx to serve multiple static websites on one server

UPDATE: These days you should put your server configurations in files in the /etc/nginx/sites-enabled directory.

As a short note, if you need to configure Nginx to serve multiple static websites out of one nginx.conf file, I have been using this approach, and it seems to work well:

How to use Scala imports like Java static imports

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 7.5, “How to use ‘static imports’ in Scala.”

Problem

You want to import members in a way similar to the Java static import approach, so you can refer to the member names directly, without having to prefix them with their class name.

Solution

Use this syntax to import all members of the Java Math class:

How to create static members with Scala companion objects

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 6.6, “How to create static members with Scala companion objects.”

Problem

You want to create a class that has instance methods and static methods, but unlike Java, Scala does not have a static keyword.

Notes on using static fields in Android

Here are a few notes on using static fields in Android, from this SO page. (Note: Some of the stuff on that page is very wrong.)

Because static fields live until an Android app is killed (while instance fields are destroyed a lot), I’ve been using static fields to persist some of my Android app’s “state” data, but I was just thinking that I can probably do the same thing at the Activity level using onSaveInstanceState(Bundle) and then restoring the state with onCreate(Bundle) and onRestoreInstanceState(Bundle). The correct approach really depends on the problem you’re trying to solve.

Scala “object” examples

This article is a collection of Scala “object” examples. I put the word object in quotes there because it has at least two meanings in Scala. In the first meaning, just like Java, an object is an instance of a class.

In its second meaning, Scala has an object keyword, and using that keyword lets you do a variety of things, including creating a main method to launch your application, to create the equivalent of Java’s static methods, and also to create something called a companion object.