model

How to add new behavior to closed classes in Scala (type classes)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 19.7, “How to add new behavior to closed classes (models) in Scala (type classes).”

Back to top

Problem

You have a closed model, and want to add new behavior to certain types within that model, while potentially excluding that behavior from being added to other types.

Back to top

Solution

Implement your solution as a type class.

Table of Contents

  1. Problem
  2. Solution
Back to top

Sencha ExtJS Store “findRecord” query examples

Here are a few short examples of how to find an object in a Sencha Store (ExtJS or Sencha Touch).

As a first example, imagine that you have a Store of users, and want to find a user with the first name of “Alvin”. Assuming that your user model has a field named firstName, your query would look like this:

var user = usersStore.findRecord('firstName', 'Alvin');

After this query you can use the user object just as though you had created it by hand. (The object returned is a Model instance.)

How to run Play Framework model methods from the Play console

Here’s a quick look at how to run Play Framework “model” methods from the Play console. In my case, my model methods are Anorm database access methods, but you may be accessing MongoDB, Cassandra, CouchDB, whatever.

First, move to your Play application directory and start the Play interpreter:

$ play

Then start the Play console:

[MyApp] $ console

Your prompt will now look like this:

A Sencha Touch (and ExtJS) store with static data alvin April 4, 2014 - 10:59am

As a quick note, the following code shows how to create a Sencha Touch (or ExtJS) store class with static data:

Important Sencha Touch 2 concepts for the new developer

Getting started with Sencha Touch 2 is kind of a pain in the rump. Having gone through this experience over the last few weeks, I've found that it really helps if you know about some Sencha Touch concepts that are hidden in the Sencha documentation.

Without any further introduction, here are the concepts that I really struggled with.

CakePHP require, notEmpty, allowEmpty, and form validation

CakePHP require, notEmpty, and allowEmpty FAQ: Help, I'm trying to edit my CakePHP model $validate field to make sure a CakePHP form field is required, but 'require' doesn't seem to be working as expected.

After fighting with a CakePHP form I just got this information beat into my head, so I thought I'd share it here. In short, if you want to make a CakePHP form field required, what you really want to use is the CakePHP notEmpty rule, like this: