A pleasant walk through computing

Comment for me? Send an email. I might even update the post!

What does this code do? Extended explanation

Ayende posted some code that didn't work as expected, and an explanation of why. You can read his full post here.

What does this code do?

But I'm not as bright as his readers, and was still mighty confused. It took me about ten minutes to finally see what was going on.

Ayende's original code is this:

var doc = new Dictionary<string,object>
{
    ["@metadata"] = new Dictionary<string, object>
    {
        ["@id"] = "users/1"
    }
    ["Name"] = "Oren"
};


Console.WriteLine(doc["Name"]);

The final statement fails, because doc is actually equal to a string value of "Oren", not the dictionary object. Why? And--for me--I couldn't understand why it was compiling at all.

It took me a while to see the syntax parsing, and remember that C# can be very forgiving of spaces. I'm not a beginner, but it's sort of a beginner mistake. For other readers like me who aren't as bright (if you have any!), here's another look.

While it appeared to me an element was being set completely outside of the declaration, the element is being set on the declared dictionary.

The final syntax is:

var item = NewDictionary[element] = value;

But that syntax can look like this:

var item = NewDictionary              [element] = value;

Code samples

//spaces before the element don't matter
var item = new Dictionary<string, object> {}    ["a"] = 1;
//is the same as
var item = new Dictionary<string, object> { }["a"] = 1;

//For clarity, we replace the declaration with its assignment.
var dic = new Dictionary<string, object> {};
var item = dic     ["a"] = 1;
//is the same as
var item = dic["a"] = 1;

I looked for other examples of where this can be done. The simplest array case doesn't compile:

//This is OK.
int[] items = new int[1] {1};
int item = items [0] = 2;

//But this isn't.
int[] items = new int[1] { 1 } [0] = 2;

Hashtable works the same as Dictionary, which is logical.

//OK
var h = new Hashtable();
h [0] = 1;

//OK, too.
var h = new Hashtable() [0] = 1;

Thanks, Ayende, for getting my brain working!

Nexus 5 GPS Lock Problem and Three--or More!--Solutions

When my wife and I moved to Denver, I started having problems with my Nexus 5's GPS not maintaining a lock. It would go show a "Searching for GPS" message about every twenty seconds. Now, for those who don't know, Denver's a pretty stressful place to drive under the best of conditions. An unreliable navigation experience was not leading to peace and joy in our town travels. (Fortunately, my wife's Nexus 5x has worked flawlessly.)

Below are two three! general solutions to the problem. I did all of these, but not in this order. The antenna fix seemed like a likely answer, but so far (today) the GPS State solution changing the Location accuracy is the winner. I wish I'd tried it before opening my phone!

I'll update this post in a few days and report how it's going.

--------------------- Edits -----------------------

2016-12-27 19:41

While I was able to run GPS Status for an hour with no issues, the message showed up again as soon as I started Google Maps Navigation. My idea was to mute it and leave it running, to see how it behaved.

Further research revealed that some users have reported the GPS message with more recent versions of Maps. So, I've become a Maps beta tester to get the very latest version.

More info as I know it.

2016-12-28 14:15

Last night it seemed like the message had gone away. I ran Maps in Navigation mode for an hour, no problem. (I wasn't driving around, but the message, if it's going to, appears regardless.)

This morning, the message was back. So, today I'm installing other navigation-related apps to see how they behave.

2016-12-29 09:45

So far, inconclusive. The behavior in Maps seems to be that it's cycling turning off the GPS then back on to get a lock. This also seemed to be happening in other apps I tried: Waze, HereWeGo. But not all the time.

Is it possible that, even after closing, Navigation is running for a few minutes in the background and causes the behavior?

I tried something this morning that I've tried before with limited success.

  1. Open Settings > Apps > Maps
  2. Press Clear Data. This clears both data and cache.
  3. In the ... menu, choose Uninstall Updates. This reverts Maps to the factory install.
  4. Restart the phone.

I tried Maps after this, and it worked solidly for about ten minutes (usually it takes less time than that for the message to start appearing). Then, I reapplied the Maps update (I'm a beta tester, remember, so it was the latest beta version). Tried it, and it's been running solidly for about ten minutes.

So, what does this mean? Is it a caching problem? Maybe a(nother) factory reset is in my future.

2017-01-01

In the last couple of days, I have:

  1. Taken apart my phone and checked for a solid antenna connection.
  2. Factory reset my phone--twice.
  3. Tried various GPS-related apps. (I don't like HereWeGo maps, by the way. Too little screen devoted to the actual map!).
  4. Changed the Location settings from "High Accuracy" to "Device Only"

The antenna connection seems fine. If there's a hardware problem, I have to assume it's a failing GPS radio module, and that can only be fixed by replacing the phone (yuck).

There were times when powering my phone off/on worked for a while. At other times, it seemed the problem only existed when running Google Maps. But more frequently, the problem existed in any app. The "Searching for GPS" message also occurred in Safe Mode.

This is why I finally changed my Location settings.

Settings > Location > Mode = Device only

I tried it this morning when my wife and I drove to and from breakfast. She navigated using Maps and her Nexus 5x, and I used my Nexus 5. It was eerie, like being in a baseball stadium, because the two voices were just out of sync enough to sound like someone announcing who was coming up to bat.

There were zero problems. The next test is drive into a more congested area, like downtown. And I won't really be convinced until I've been message-free for several days. So, where will I navigate to next!?

2017-01-03

Zero problems the last three days. I have one big drive tomorrow. If that goes well, I'll consider the problem licked. I'll also be filing a bug report to Google. After all, if High Accuracy triggers this problem, then I consider that a significant defect.

---------------------------------------------------

Location Accuracy

You'd think that using the most accurate location setting would be the right thing to do. But, at least in my case, it isn't. I don't know why the locking problem only started up in Denver. I've never experienced it anywhere else. But here's the solution that has worked for me.

  1. Open Settings > Location
  2. Change Mode to "Device Only"
  3. Restart. (May make no difference, just a habit.)

GPS State

The second thing to try is to install the excellent GPS Status & Toolbox app and follow the instructions at the blog entry, below. There free version of the app works just fine for this.

https://mobiwia.com/78-gps/76-tip1

Here's a copy of the instructions.

What to do when your GPS does not lock?

Steps to follow if you have a non-locking GPS:

  1. Menu / Tools / manage aGPS state.
  2. Select 'Reset' to clear the internal state of the GPS.
  3. Select 'Download' to re3.download the assistance data. You will need an active internet connection at this step.
  4. Close the GPS Status application for 10 seconds.
  5. Go outside and find a spot where large part of the sky is visible.
  6. Make sure you have the 'Keep the screen on' settings turned on (in Menu / Settings / Display & Tools'.
  7. Let the program run and try to acquire your GPS position for at least 15 minutes.

Antenna Connection

Finally, some Nexus 5 phones don't make a good connection from the back of the phone to the GPS antenna. This video explains how to MacGyver the situation. Warning: Requires opening the phone, and delicate operations that might damage the phone. Watch the whole video to see what's entailed.

Nexus 5 GPS Signal Antenna Fix

How to Bypass the New Microsoft Office Startup and Save Screens

Starting with Office 2013, there are two changes that some people will like and use, but that I hate and don't.

Startup Screen

I rarely need to open a template other than the blank one. However, the default Office behavior is to show a Van Gogh Starry Night of choices.

image

Do this to disable the new startup screen and go immediately to a blank document, as it has been for two decades. Instructions are for Word 2016.

  1. Open Word
  2. Open a blank (or existing) document
  3. Choose File > Options
  4. In the General > Start up options, uncheck "Show the Start screen when this application starts"
  5. Click OK. Word now opens to a blank document.

image

Backstage View (Save Screen)

Microsoft OneDrive is intended to be deeply integrated into MS Office. Microsoft wants you saving there by default. The Save screen reflects that when you save a new document (or Save As an existing one).

image

However, many people prefer to save locally, even if that means saving to the local OneDrive folder for later synchronization.

Do this to show the file Save As dialog that you've seen since raptors tried to eat your computer.

  1. Open Word
  2. Open a blank (or existing) document
  3. Choose File > Options
  4. In Save > Save documents, check "Don't show the Backstage when opening or saving files"
  5. Click OK. Save/Save As shows the good, old dialog.

image

Hello, old friend.

image

References

http://www.howtogeek.com/tips/how-to-bypass-the-backstage-view-when-saving-new-files-in-office-2013/