Carrying the Whale

Personal ruminations for the spammers to ignore…

I was working through a programming problem earlier and thought I’d share this since I didn’t find many really good examples of this kind of thing on the ‘net. This is a Generic Factory Method that can be used to set common Properties on objects of any given type. This example is C# and XNA. In my example, I have a UI system that uses dozens of different Controls, some are animated, some are interactive, some are just simple labels. All of them, however, use two basic objects: the SpriteBatch object from XNA (a surface to draw on), and the UITexture object which contains parameters about where various graphics are located in my UI texture.

Here’s the simple code, the first section here defines the Interface that my base control class implements, the relevant lines of code for this example are SpriteBatch, UITexture, and Initialize, the other properties are used in other areas:

public interface IControl
{
    bool IsVisible { get; set; }
    bool IsReadyForDisposal { get; set; }

    SpriteBatch SpriteBatch { set; }
    SensoriumContent UITexture { set; }
    void Initialize(ControlParameters parameters);

    void Draw(GameTime gameTime);
    void Dispose();
}

This section is a method that creates the generic object and sets its common properties (SpriteBatch and UITexture) and passes in the specific parameters for the object through a collection. You can pass your parameters any way that makes the most sense to you, however you must implement Initialize() as appropriate for your concrete object. This method is in the interfaceComponent object.

public T CreateControl<T>(ControlParameters parameters) where T : IControl, new()
{
    var control = new T();
    control.SpriteBatch = spriteBatch;
    control.UITexture = gameObject.UITextureContentObject; // This object is created elsewhere, is a public Property of my implementation of the XNA Game object
    control.Initialize(parameters);

    return control;
}

To create the concrete object you’d create a new ControlParameters object (this example is just an empty object) and then pass that into your Generic Factory Method

    var controlParameters = new ControlParameters(); // Normally, you'd pass your actual parameters into this object through the constructor
    var testControl = interfaceComponent.CreateControl<TestControl>(controlParameters);

What you end up with after this is an object of TestControl type that has SpriteBatch and UITexture set, then the remaining parameters set through the Initialize method.

In the end, this doesn’t actually save you a whole lot of time in the above example, since it’s just as easy to do: new TestControl(spriteBatch, uiTexture); and just assign the values during Construction of the object. The above example would be used for situations where you may set many defaults on an object, and instantiating the objects through a Generic method like this can save a little bit of time and/or simplify your constructors by removing repetitive parameter passing.

In the nav bar above you’ll find a link to this page: Devanagari Alphabet



This is for reading, translation, writing, and typing in Hindi. This chart contains all of the most common or directly typeable consonants, vowels, and conjucts in Devanagari.

You will find some additional notes about how to type using Devanagari input on an English keyboard once I add that page, but for now here are some basic notes about typing Devanagari. The keyboard is laid out generally vowels on the left and consonants on the right, with several special modifier matra scattered around the corners depending on what keys were left available.

There are also three special keys that are used to “clip” glyphs in various ways, the d will remove the implied short a from a glyph (“लल” “lala” to “ल्ल” “lla” or ”सत” “sata” to” स्त” “sta” for example), and the # and $ will create conjunct r forms (“क” “ka” to “क्र” “kr” and “र्क” “rk” for example).

Those who pay extra special attention may notice that there are several matra on the keyboard that are not listed on the Devanagari Alphabet page. This is because there are several matra sounds in the Unicode Standard 6.0 that are not used in standard Hindi. I have not included these on the alphabet page, but they are shown on the keyboard. More details to come!

This article is first in a series regarding the new XNA Game Studio 4.0 released from Microsoft. I’ve been reading quite a bit on it and found there’s a lack of detail on what the XNA Game Component Model is and how to use it, so I hope to provide some simple answers to questions that came up as I was learning XNA 4.

What is a Game Component? The first question to ask is actually “What is a Game?”. When you create a new XNA Game Studio 4.0 project the template provides you a Game object and two Components, GraphicsDeviceManager and SpriteBatch. It is fairly easy to understand the methods that the Game object provides, and it’s clear that the provided methods work like they sound they will “Initialize” “LoadContent” “Update” “Draw” and “UnloadContent” are all pretty obvious. What is not clear is how to leverage all of that functionality. This is where the Game Component comes in.

One of the things the Game object provides is a list of Components and a list of Services. You may create one of two basic types of components and you may define Interfaces to be registered as Services. These lists are a core part of the Game logic, as any Component that is registered with the Game object will have its Update and Draw methods called. Essentially, XNA provides you a base class to use for any object that needs to be updated or drawn each “tick” or “frame” of the game. In my observation, most people do this on their own. It seems the logic is that since I can’t see what’s going on “under the hood”, it’s easier for me to write my own logic even though it does the same thing.

So then you ask, what if I want to change the draw order of my components? Turns out that the base class provides basic implementations of event handlers for dealing with exactly that. If one component’s position in the list changes it affects all other components, and so their “OnOrderChanged” events are raised. Additionally, the Game.Component Collection can be sorted, enumerated, and otherwise tampered with as you see fit, so again, it’s not worth the time to write this code again, use the out-of-the-box functionality. A final note about this class. It’s also worth mentioning that you can create your own GameComponent class and as long as you implement the five basic interfaces it requires, you can still use the Game.Components collection and your custom GameComponent class will have its Interface-driven methods called right on queue.

I will add some sample code here soon that demonstrates a very simple application that creates a component to draw a graphic on the screen. Approximately 30 lines of code in three classes (main, displaystring, displaystringdata), 10 lines per class, and it could probably be fewer, but I put some irrelevants in to make it pretty.

There are only a few simple things to understand about cooking. If you care about the science, you can look up details on things like caramelization, sucrose inversion and related topics, but that’s secondary to the basic principals.

In order for most raw ingredients to taste good you need a certain amount of heat. The trick is in the timing. Some things are ok with overcooking, but most things have a “Sweet spot”, once they’re cooked “enough”, then you’re done. While overcooking (I’m not talking about BURNING) is not bad for most things, it does tend to reduce the flavor over time.

So, let’s give a couple examples, from difficult to easy:

Milk – when you cook milk with too much temperature, it “curdles”, this is bad. Most dairy products are somewhat sensitive to heat, so you cook dairy either for a short time at somewhat high temperatures, or you cook them longer at lower temperatures. An easy milk-based recipe is rice pudding. At it turns out, milk and butter interact in an interesting way which makes them thicken over time. Cook rice (I’ll explain that below) until it’s sticky, add a bunch of milk to it, say a quarter gallon and a quarter cup of butter. Cook this over medium to medium high heat for about 30 minutes, stirring constantly. What happens is that the butter and milk thicken slowly (you must stir constantly) as the heat and milk and butter react to each other. The rice should also shed some and this adds to the thickness, add some chopped up raisins and I bet a mashed bananna would probably be good as well to add sweetness. Add nuts if you want some crunchy chunks and some additional healthy fats and protein.

Note, there’s no sugar in there but natural fruit sugars. To prepare rice, I’d recommend a cooker. I had always done it in a pan, but after I got a cooker, there’s no looking back. If you must prepare it in a pan it’s like this: 1 cup of rice (rinse it off first), 2 cups of water, put it in a pan and put it on a temperature that’s just enough to make the water boil. Let it boil down until the water is just above the level of the rice and then put a cover on the pan with a small crack to let a small amount of steam escape. Cook like this for about ten minutes – basically you want the steam to be captured in the pan and you cook it until there’s no more water. Timing is important. Also, do NOT stir the rice, resist the urge!

Different vegetables cook at different rates, we’re talking basic physics here, density and all that. Cauliflower and broccoli cook quickly, carrots cook somewhat slowly, potatoes are in between. All of them can be most easily prepared by cooking them in water, or in a steamer (pan with holes in the bottom that sits in another pan – put the water in the pan and the vegetables in the steamer tray, cook until tender.

The best way to tell is to test, if it’s still bitter and tough, it’s not cooked enough! This is especially true for beans! I usually buy all my beans in their dried bulk form. To make them eadible there’s a few different approaches, but generally you want “reconstitute” the beans first, which is put them in a bowl of water for about eight hours (overnight) and then you can cook them by boiling them in water (no steaming for beans generally) for however long it takes, some beans cook more quickly than others, for example, kidney beans cook more quickly than garbanzo beans. The way to tell is when they’ve just become soft (remember what I said at the top about timing and cooking too much?). You can cook them longer, but they start to lose flavor.

Spices are a totally different beast altogether, but most dishes are done with one primary spice and one complimentary spice, when you read recipies you’ll usually see this trend. Indian dishes are much more difficult to cook because they use multiple spices and the ratio is much deterministic of the final flavor – that is to say, most Indian dishes use all of the same spices, it’s just a matter of which one dominates by being a larger ratio compared to the others. I won’t go into more detail about that, but suffice it to say the most common spice blends are salt + something else. Garlic/salt. Oregano/salt. etc.

A slight variation on spice flavoring is also when dairy is used as a primary flavor. Let’s talk sauce – Before I reduced my dairy intake I used to make the most fantastic alfredo sauce ever, and it’s so totally simple it’ll make you cry:

Cook your pasta by boiling in water for 10 minutes or so (you know, do I have to say it again? Until soft!) and in your other pan do the following:

Half a stick of butter, on medium heat until it’s melted. Add about a tablespoon of flour to it (there are many alternatives, but the point is this is a thickening agent, you could use, for example corn starch) and then add about a cup of milk to start. Whisk it so that the milk and butter and flour are all nicely homogenized (sounds almost like the rice pudding, doesn’t it? Stir constantly!). Grab a brick of nice parmesean cheese and grate it all in, stirring as needed. The cheese melts into the thick milk/butter/flour base and you’ll start to see a nice alfredo sauce. Add more milk as needed! Add some parsley or oregano or cilantro for a complementary spice. That’s really up to your whim more than anything, and after a few attempts with different amounts you’ll start to see how it all works out.

I used to make alfredo with three cheese tortellini and I’d cook up some ground jimmy dean’s breakfast sausage (has rosemary in it) and add that at the very end. It’s one of the only things I truly miss about becoming a vegetarian!

Cooking meat is fairly easy, and follows many of the same principals, ground dishes need to be chopped up with a wooden spoon or equivalent while cooking for – can you guess how long? The idea is to use as much heat as needed, so medium high or high depending on how quickly you need it to cook. The higher the heat the more likely it is to burn, but with meats you really want the temperature to be higher. Meats are dense, to cook them, you need more temperature, again, basic physics, right? To cook a steak, you might not want to use high heat because you need it to sit on one side for longer without charring too badly before you flip it, the thickness of the steak determines the time and temperature. Thinner steaks can be cooked at higher temperature for shorter time than thicker steaks, but again you always want at least med-high for meat cooking, so it’s not a huge difference.

My curries these days are made in several different ways, I’ll spare you the spice details, but basically I made a tomato and onion based sauce using either butter or oil, add chopped up peppers (I like anaheims and pablanos for flavor) with garic and ginger and my spice blends (cumin, turmeric, chili powder, corander, and for some dishes garam masala which is actually a blend of like 10 other spices) — Ok, forget all that about the spices, what I was going to talk about is the things you add afterwards. In my curries, I add different vegtables, sometimes green beans, peas, carrots, potatoes, cauliflower, etc… This really depends on what I’m trying to make, sometimes the dish uses beans of various types instead and the spices shift depending on the theme. Stupid tangents… Depending on how much time I have and how prepared I am, I may cook the vegetables either IN the curry or separately and add them to the curry base. When you do it the first way, you lose a lot of flavor, but it’s much easier. Basically, add a ton of water to your sauce base, add the vegetables and cook until it’s all done.

The RIGHT way to do that is cook your vegetables in a steamer until they’re tender, then add them once the sauce is finished. Again, it’s a laziness or preparedness thing for me. Sometimes I want to try a new spice blend and I get ahead of myself cooking the curry sauce and then I’m like … oh, right, I need vegetables cooked, F it – add like four cups of water dump the veggies in and let it roll on medium-low for an hour. This somewhat compensates for the loss of flavor, but also has the added benefit of letting the veggies soak up a bit of the flavor. Always a give and take.

Next there’s different stir fry variations, these are pretty easy overall, as it’s just chop up a bunch of shit into smallish pieces (1/4″ max) add some oil to your pan (3-4 tablespoons), add the veggies and fry for – you’ll never guess how long. The smaller pieces can cook quickly, and soak up and spices you might add like black pepper or chili powder, etc. There’s an Indian dish called “Alu Gobi” which literally means “Potato Cauliflower” which is much like a stir fry, but you add larger chunks of potatos (1″ cubes) and cauliflower florets after you’ve fried up your chopped peppers and onions and garlic/ginger in the oil or butter. You also add a lot of turmeric to this to give it that fruity Indian flavor, and make sure the alu and gobi are well covered on the outside. It’s required to cook the potatoes and califlower before on this because as a stir-fry you can’t add a ton of water like you would with a curry sauce based dish. This dish is also prepared with a slightly higher salt ratio and with many seeds in their raw form rather than powder. It’s one of my favorites, and easy to make.

Um, I could get into deep fry methods, but I think the above should keep you busy for a while. I don’t really have any special tools, I use big spoons, a wisk, and various sizes of pots and pans. For specialty items, I have a food processor (black and decker, $30 from Fred Meyer) and a rice cooker ($30 at Cosco) and a food grater and peeler. For staple items I keep frozen peas (must be cooked) and frozen beans, canned tomato puree (like thinner tomato paste, but not as thin as tomato sauce), a bag of potatoes (I put them in just about everything), and various bulk beans: masoor (red lentil) is used to thicken certain kinds of bean dishes, black and green urid (another kind of lentil), garbanzos, kidney beans, and I keep some carrots, califlower and other things in the fridge to use as desired. I also keep garlic and ginger (raw forms) on hand with a ton of different spices. All those spices are pretty secondary, though, you can buy them in small quantities and try them out one at a time in simple dishes, eventually, you’ll have a respectable collection of spices that you know how to use and everyone will call you a master chef!

Special note on garlic and ginger, I keep both raw ginger root which is grated using the small grind side of the food grater. Alternatively, you can scrape the skin off using a serrated steak knife and then just keep grinding at it with the knife, this produces much the same effect. I also have a peeler for taking the skin off the ginger root, potatoes or carrots if needed. For example, when I make hummus and I serve it with carrots, I skin them because you eat the carrots raw, but when I cook, I usually leave the skin on for the extra vitamins!

Two simple recipies to start you with because they’re easy as hell and people pay retarded amounts for them:

Hummus – 1 cup dried garbanzo beans (or two cans), 1/2 cup lemon juice, half a small jar (8oz/1cup approx) in a food processor – add water to keep it from getting too thick. Add spices as desired. Seriously, that’s it. I typically put garlic, paprika, cumin, olive oil and jalapenos in my hummus. Serve with bread, crackers, vegetables, whatever.

Chai (Tea) – 1 quart of water, 4-6 tea bags, 6-8 cloves, 4-6 GREEN cardamoms (popped – you want the little beads inside to come out), and an inch of ground up ginger root. Bring to a boil, add 1 quart of milk, bring to a boil again and IMMEDIATELY remove from heat. Pour through a strainer into another container (like a serving caraffe) to remove all the floaty stuff. Sugar to taste. Easy as hell and super tasty! Any black tea will work, I use either English Breakfast or Orange Pekoe.

A penny for the Old Guy

I

We are the hollow men
We are the stuffed men
Leaning together
Headpiece filled with straw. Alas!
Our dried voices, when
We whisper together
Are quiet and meaningless
As wind in dry grass
Or rats’ feet over broken glass
In our dry cellar

Shape without form, shade without colour,
Paralysed force, gesture without motion;

Those who have crossed
With direct eyes, to death’s other Kingdom
Remember us – if at all – not as lost
Violent souls, but only
As the hollow men
The stuffed men.

II

Eyes I dare not meet in dreams
In death’s dream kingdom
These do not appear:
There, the eyes are
Sunlight on a broken column
There, is a tree swinging
And voices are
In the wind’s singing
More distant and more solemn
Than a fading star.

Let me be no nearer
In death’s dream kingdom
Let me also wear
Such deliberate disguises
Rat’s coat, crowskin, crossed staves
In a field
Behaving as the wind behaves
No nearer -

Not that final meeting
In the twilight kingdom

III

This is the dead land
This is cactus land
Here the stone images
Are raised, here they receive
The supplication of a dead man’s hand
Under the twinkle of a fading star.

Is it like this
In death’s other kingdom
Waking alone
At the hour when we are
Trembling with tenderness
Lips that would kiss
Form prayers to broken stone.

IV

The eyes are not here
There are no eyes here
In this valley of dying stars
In this hollow valley
This broken jaw of our lost kingdoms
In this last of meeting places
We grope together
And avoid speech
Gathered on this beach of the tumid river

Sightless, unless
The eyes reappear
As the perpetual star
Multifoliate rose
Of death’s twilight kingdom
The hope only
Of empty men.

V

Here we go round the prickly pear
Prickly pear prickly pear
Here we go round the prickly pear
At five o’clock in the morning.

Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
                                        For Thine is the Kingdom
Between the conception
And the creation
Between the emotion
And the response
Falls the Shadow
                                                    Life is very long
Between the desire
And the spasm
Between the potency
And the existence
Between the essence
And the descent
Falls the Shadow
                                        For Thine is the Kingdom
For Thine is
Life is
For Thine is the

This is the way the world ends
This is the way the world ends
This is the way the world ends
Not with a bang but a whimper.

Some of you may remember that several years ago a friend recommended Dan Gilbert’s Stumbling on Happiness and I liked the book so much, I purchased ten copies of it and gave it away to friends. The book is about the various research projects that Dan Gilbert has performed at Harvard over the last howevermany years, and it’s an interesting piece. It’s basically about why humans are so bad at predicting the future, and more directly, why we’re so bad at predicting what will make us happy.

This Emotional Life is a PBS production hosted by Dan Gilbert which covers, in a much more friendly manner, many of the same topics. I watched the first episode of the series this weekend on Netflix streaming, and it was pretty entertaining. I have to give this series a thumbs up, and if you have the time it’s worth a watch. Entertaining and educational, regardless of your age!

Some links for fun: Netflix, Dan Gilbert, This Emotional Life