Memory access patterns in high-level languages

Like many developers that work in high-level languages, I think don’t spend a lot of time thinking about memory access patterns. This is probably a good thing… for the most part, worrying about this is premature optimization. But there are times when it matters, and the compiler won’t magically “optimize” it away for you, even if you have optimizations turned on:
Continue reading

How to fix broken iCloud photostream sync on Windows

Symptom

  • Your iPhone is set to back up your photos to iCloud
  • iCloud on your Windows machine is configured to download your photos
  • iCloud isn’t downloading your photo stream.

Fix

  1. Open the Task Manager by hitting Ctrl+Shift+Esc
  2. Click the Processes tab
  3. Click Name to sort the processes by name
  4. Find the Apple Photostreams Uploader and Apple Photostreams Downloader processes. End both of them.
    • In Windows 7, these will be called ApplePhotostreamsUploader.exe and ApplePhotostreamsDownloader.exe
  5. Hold down your Windows key, and hit R to open a Run prompt
  6. Type %appdata% and hit Enter
  7. Open Apple Computer > MediaStream
  8. Delete everything in the directory
  9. Log out of your Windows account, and log back in (or just reboot, if you find that easier)
  10. Once you’ve logged back into your Windows account, open the iCloud control panel again
  11. If the Photos checkbox is empty, check it
  12. Click Options, and make sure the photo options are configured how you want them
  13. Click Apply

In a few moments, your photos should start downloading.

Notes

iCloud isn’t very smart about a great many things. Here are a few:

  • If you changed the location of your downloaded photos, it will redownload what it can, creating duplicates.
  • In the iCloud 2.x days, your downloads and uploads were usually split into a Downloads and Uploads directory, and you could change the directories if you wanted. That’s not true anymore. Instead, iCloud 3.x creates a “My Photo Stream” directory, and sticks your downloads in there. Anything you’ve shared with other people, or that other people have shared with you goes into “Shared”. If you want to push a photo from your computer to iCloud, put it into Uploads

How to get Medicare to reimburse you for seeing a non-Medicare doctor

This post explains how to get reimbursed by Medicare directly, and is applicable to people who have Part B coverage. I have included the exact forms and letters that I used to get reimbursed by Medicare directly; you simply need to fill in the blanks. These forms can also be used if patients see their provider “virtually” (i.e. by phone or video conference).

The problem

I have a family member that gets reimbursed directly by Medicare for out-of-pocket costs that she pays herself. Several unusual criteria apply to our case… This family member:

  • Has a health care provider that does not accept Medicare
  • Lives in a rural, health professional shortage area (HPSA)
  • “Sees” her provider virtually. Medicare refers to these types of visits as telehealth, and they are reimbursed at the same rate as normal, in-person visits; there are no special telehealth billing codes. To be eligible for telehealth reimbursement, you must meet certain criteria.
  • Uses me as her Social Security Payee, which makes her my legal dependent. (I have to do everything on her behalf.)

Despite all of these special circumstances, we’re able to get reimbursed by Medicare directly, which is $3-4,000 a year. We had to appeal twice on our first attempt at getting reimbursed. The language and documents I have distilled below reflect this. It helps to very, very clear about why your request is valid.

Need an example of an appeal letter? Post in the comments below, and I’ll clean mine up.

Supporting documentation

  1. Fill out a “Patient request for medical payment” form
  2. A signed, dated letter from your provider that states that they refuse to submit claims to Medicare, and that they are not (and don’t wish to become) a Medicare provider (Microsoft Word | Google Doc)
  3. A copy of an itemized bill for services rendered in the last however many months. This bill should contain the date of service, cost, and the service rendered. Once you’ve got the reimbursement process down, you should submit a reimbursement request every 3 months or so. (Microsoft Excel | Google Spreadsheet)
  4. A request to be reimbursed that references the pieces of documentation above. (Microsoft Word | Google Doc)
    • For telehealth reimbursement only: A letter stating that there are no suitable providers in a 500 mile radius of the patient’s address, or that the patient is in an HPSA-designated region. I included this information in the reimbursement request itself (#3). By the way: telehealth visits are generally only applicable to mental health services.

You do NOT need to include diagnostic information.

Ways you may need to change the included sample letters

  • Change the billing codes so they’re relevant for your case.
  • Change the provider’s name and credential information.
  • Look for stuff in the letters that looks <Like this>, and replace it with information relevant to your case.
  • If you are doing this for yourself or for someone who is not a dependent: Each of the sample letters is written by me on behalf of a legal dependent. If this doesn’t apply to you, modify each document so it’s written from the perspective of the patient themselves: use “I”, “me”, etc., and have them sign it.
  • If you are not trying for telehealth reimbursement, remove the sections that talk about being in a health professional shortage area and/or telehealth references.
  • Make sure the Conclusions section in the request letter is relevant. For example: my version includes comments about telehealth; yours may not, so delete them. Make sure they make sense for you.

Send the paperwork certified mail

You won’t be sending your 3-4 pieces of documentation to Medicare. You’re going to be sending them to a Medicare Carrier, which varies by state. Find yours here.

We did not send our first appeal certified mail, and it got lost. This cost us three months. Save yourself the time and aggravation, and send your documentation certified mail.

Be prepared to wait

It took me over a year to finally get reimbursed by Medicare. It took three incomplete attempts, and two appeals before I won my case. You may not succeed the first time… but keep at it. If you can push through the bureaucratic apathy, you will probably succeed.

Good luck! Ask any questions in the comments below, and I’ll do my best to answer them. Getting Medicare to reimburse you for covered expenses is NOT easy.

redis: Sorted Sets as iterable key-value work queues

I’m in the process of building an internal search engine at work, and first on the block are our network share drives. During a typical week, we have about 46,000 unique documents that are written to in our Lexington office. This number only represents things like Word docs, Excel spreadsheets, PowerPoint presentations, PDFs, and so forth. (A count of all touches is 3-4x higher.)

This presents some challenges: crawling the network shares at regular intervals is slow, inefficient, and at any given time, a large portion of the search index may be out of date, which is bad for the user experience. So I decided an incremental approach would be better: if I re-index each document as it’s touched, it eliminates unnecessary network and disk IO, and the search index is updated in close to realtime.

Redis

My second-level cache/work queue is a redis instance that I interact with using Booksleeve. The keys are paths that have changed, and the values are serialized message objects stored as byte arrays that contain information about the change. The key-value queue structure is important, because the only write operation that matters is the one that happened most recently. (Why try to index a document if it gets deleted a moment later?)

This is great in theory, but somewhere along the way, I naively assumed it was possible to iterate over redis keys… but you can’t. Not easily or efficiently, anyway. (Using keys in a production environment is dangerous, and should be avoided.)

Faking iteration

The solution was relatively simple, however, and like all problems in software development, it was solved by adding another level of indirection: using the redis Sorted Set data type.

For most use cases, the main feature that differentiates a Set from a Sorted Set is the notion of a score. But with a Sorted Set, you can also return a specific number of elements from the set. In my case, each element returned is the key to a key-value pair representing some work to be done.

Implementing this is as easy as writing the path to the Sorted Set at the same time as the key-value work item is added, which can be done transactionally:

using (var transaction = connection.CreateTransaction())
{
    int i = 0;  //dummy value representing some "work"
    foreach (var word in WORDS)
    {
        transaction.SortedSets.Add(REDIS_DB, set, word, SCORE);
 
        //Set the key => message (int i) value
        transaction.Strings.Set(REDIS_DB, word, i.ToString());
        i++;
    }
    transaction.Execute();
}

Downstream, my consumer fills its L1 cache by reading n elements from the Sorted Set:

var pairs = new Dictionary<string, string>();
using (var transaction = connection.CreateTransaction())
{
    //Get n keys from the set into the Dictionary
    var keyList = connection.Wait(connection.SortedSets.RangeString(REDIS_DB, set, 0, LIMIT));
 
    foreach (var key in keyList)
    {
        var value = Encoding.Default.GetString(connection.Strings.Get(REDIS_DB, key.Key).Result);
        pairs.Add(key.Key, value);
 
        //Remove the key from the SortedSet
        transaction.SortedSets.Remove(REDIS_DB, set, key.Key);
        //Remove the key from the Keys
        transaction.Keys.Remove(REDIS_DB, key.Key);
    }
    transaction.Execute();
}

And there we have fake key “iteration” in redis.

How to install iCloud on Windows Server

Symptom
iCloud sync stops working, or you get an error message on startup that says: The procedure entry point _objc_init_image could not be located in the dynamic link library objc.dll’ and will not start.

Cause
Apple has configured newer versions of iCloud (version 3+, I believe) to only work on Windows 7 or 8, but there’s no reason you can’t use it on Windows Server operating systems.

Fix
You’ll need about 3 minutes, and two utilities.

  1. Install 7-zip.
  2. Install Orca, a Microsoft-provided MSI editor.
    • Orca is bundled with the Windows SDK, and getting it out of that bundle isn’t straightforward, so I’ve extracted it, and zipped it up so you can get it as a standalone program.
  3. Download the iCloud control panel installer, if you haven’t already
  4. Open iCloudSetup.exe with 7-zip.
    1. Right-click it
    2. Select 7-zip > Open with 7-zip
  5. Extract the appropriate version of iCloud somewhere (usually this is iCloud64)
  6. Open Orca, and open the iCloud MSI you just extracted
  7. Go to the LaunchCondition table
  8. Change this line:
    • From: (VersionNT >= 601) AND (MsiNTProductType = 1)
    • To: (VersionNT >= 601) AND (MsiNTProductType = 3)
  9. Save and quit

You should then be able to install iCloud on your Windows Server OS using the MSI you just modified.