Draw the specified arc, which will be scaled to fit inside the specified oval. If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs slightly from SkPath::arcTo, which treats the sweep angle mod 360.

Seriously lacking documentation. For anyone having problems with this method, the start of the arc is determined by going `startAngle` degrees clockwise from the right side of the oval, instead of counterclockwise from the right side like is traditional in math. Then the method sweeps out the arc in the clockwise direction. It’s not enough to simply say the second bit of information and leave out the first.

Spectacular…

I found this example of using Android’s TextToSpeech capabilities to be much better than this blog post.

### Functors for the Beginner

Let’s talk about Functors in the OCaml programming language. I will assume that you know about modules in OCaml, if not you can refresh by reading the manual.

Functors are “functions” from structures to structures.

The above is probably the best definition I’ve seen of a functor. It touches on what I see as the main motivation behind using a functor. A Functor being a function from structure to structure means that if you keep the signature of the input structure and the signature of the output structure constant, you are free to change the implementation details without affecting any of the modules that use it. Functors allow the software designer an easy way of avoiding duplication, increasing orthogonality, all in a type safe package.

Let’s write an algorithm to determine if a string contains balanced parentheses. To start, we’ll define the type of stack we want to work with:

```module type STACK = sig
type 'a t
exception Empty
val create : unit -> 'a t
val push : 'a -> 'a t -> unit
val pop : 'a t -> 'a
val is_empty : 'a t -> bool
end```

Here we have the basic operations on a very minimalist stack. Now, we’ll create a functor that will take a stack structure of this type and return a module containing our parenthesis matching algorithm.

```module Matcher (S : STACK) = struct
let is_balanced str =
let s = S.create () in try
String.iter
(fun c -> match c with
'(' -> S.push c s
| ')' -> ignore (S.pop s)
| _ -> ()) str;
S.is_empty s
with S.Empty -> false
end```

While we rely on the Stack with the STACK type to not change the semantics of its functions, we can guarantee that for any stack with this kind of structure and with the right semantics, our algorithm will work. Any use of this functor will create a module with one function: `val is_balanced : string -> bool`. This also means that if we maintain the signature of the functor we just wrote, we can change any of the implementation details and not affect the outside world.

To use a different stack, all we have to do is change one line of code from `module M = Matcher(Stack)` to `module M = Matcher(CStack)` to change our algorithm to use a stack that keeps a count of the number of things pushed onto it in its lifetime.

Conclusion: functors allow you to write code that will work irrespective of the implementation of the given structure (so long as it does what it should), and produces a structure containing functions that we are free to modify, but only have to change in one location, that of the functor.

### Syntax Highlighting

Since I’m a programmer by trade and prefer to make blog posts on programming topics, I require the ability to post code snippets. This isn’t immediately available on Tumblr, so I looked for a way to make syntax highlighting available. According to this StackOverflow question, Tumblr will host small files for you, so that you can upload files related to custom themes. You can upload any files you like (so long as they are related to theming) on Tumblr’s Upload a static file page.

I chose Prettify, Google’s javascript syntax highlighter. All I had to do was upload 2 files, `prettify.js` and `prettify.css`, and follow the instructions on the README and I got nicely highlighted code.

### Android Contacts

In the course of programming an android app, I needed access to all contacts who had addresses entered. I couldn’t find good example code on the internet — most code either targets the wrong API level (Android 1.6, the contacts API was changed for 2.2), or had nothing to do with grabbing address data. With help from StackOverflow, here’s example code for anyone trying to work with Android’s new Contacts API.

First, you need to specify `android.permission.READ_CONTACTS` in your `AndroidManifest.xml` file, since we’re only going to read contact data, not write to it.

According to `ContactsContract.Data`, contact Data tables are implicitly joined with the `ContactsContract.Contacts` table. So, all we need to do is query the `ContactsContract.CommonDataKinds.StructuredPostal` table and we’ll still have access to important data like their display name.

Find the column names of the data you want. `ID_COLUMN` is the column name of the id of a contact, `LOOKUP_KEY_COLUMN` is the column name of the key you can use to lookup the contact, `NAME_COLUMN` is the column name of the display name of the contact, `ADDRESS_COLUMN` is the column name of the formatted address of the contact.

```private static final String ID_COLUMN = ContactsContract.Contacts._ID;
private static final String LOOKUP_KEY_COLUMN = ContactsContract.Contacts.LOOKUP_KEY;
private static final String NAME_COLUMN = ContactsContract.Contacts.DISPLAY_NAME;

Next, we can access all contacts that have an address with the following method:

```public static void getAllContacts(Activity context) {
Cursor cursor = context.getContentResolver()
.query(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI, null, null, null, null);

while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex(ID_COLUMN));
String lookup = cursor.getString(cursor.getColumnIndex(LOOKUP_KEY_COLUMN));
String displayName = cursor.getString(cursor.getColumnIndex(NAME_COLUMN));