Health Insurance… Obamacare & Grinding Gears…

Ok, so I’m not entirely dumb & I’d like to think I’ve got a clue, but oh my goodness, this ObamaCare crap really grinds my gears…

Turns out the plan I selected doesnt support an HSA – why the hell not, I mean, if you’re going to spend any money on medical crap, why the hell would I not use an HSA – so because I selected it via the marketplace, I’ve got to go back to them and wait for hours on hold to figure it out…

Talk about gear grinding…

 

Sorted Hashtable Keys

By default, a hashtable does not keep a sorted list of keys, but sometimes it’s useful to do so.

In order to do this in one line with linq, you’ll need to cast the keys to an array of strings, and then order them as follows:

dailyStatsKeys = dailyStats.Keys.Cast<string>().OrderByx => x).ToList();

or

dailyStatsKeys = dailyStats.Keys.Cast<string>()
.
OrderByDescendingx => x).ToList();

where dailyStats is a hashtable declared and populated elsewhere.

C# System.Func

I needed to create a hook into a class I’m working on that will return a GameObject for a given index.  Now, I could have just built that function into my class, but I’d rather make this class re-usable by other projects down the line (and even other classes within the same project).

public System.Func<int,Transform,TransformrowForRowIndex;

The first two parameters are passed to the function from the calling method, while the third is the returned object.  So in this case, I would invoke the function as follows:

row = rowForRowIndex(r,cachedRow);

Where, r is the index of the row I want to generate, and cachedRow is a row object that has been previously created but is free for use.

You can obviously use different parameters & return type than I am, just remember, the last entry is always the return type, so

public System.Func<bool> isValid;

will return a bool and takes no parameters, while

public System.Func<int,float> rootOfInt;

will return a float and take 1 int as a parameter.

You can also use lambdas to create in-line functions using this syntax:

public System.Func<int,float> rootOfInt = (x) => Mathf.Sqrt(x);

While this is similar to System.Action, the big difference is that System.Func can return a value, System.Action is always type Void.

Fixed it!

Finally got my WP install updated to the latest & greatest… turns out a few files/folders where still owned by root and not www-data so the auto-upgrade feature was unable to work…

Now I just need to figure out my permalink issue and get rid of these ugly ones, but I’ll save that for another day.

LINQ, C# and Unity…

Having never ‘learned’ c#, the LINQ syntax sometimes escapes me, and it takes a bit of getting used to, but honestly, it’s worth the price of admission!  I recently needed to find the first object in a list whose Y value was greater than another Y value (basically making sure it was on screen).

My first thought was to use a foreach loop, with a break and a bool flag along with a var to store the index like so:

       bool found = false;
       int rowIndex = 0;

                foreach (float y in rowYPos)
                {
                    if (y>scrollOffset)
                    {
                        found = true;
                        break;
                    }
                    rowIndex++;
                }

This code works, and will return the index of the first entry that exceeds scrollOffset;

However, with LINQ all that becomes:

            int firstRowIndex = rowYPos.FindIndex(x=>x>scrollOffset);

Much shorter, less local vars and pretty self-explanatory.  I didn’t benchmark it to see which was faster, though my hope is that the LinQ method would be, It’s not something that happens often enough to make it a worry.

Handy tip: You’ll need to add a using System.Linq; to the start of the file…