Saturday, April 29, 2023

When to Charge Your Apple Watch

I have heard individuals complain about the battery life of their Apple Watch (or lack thereof) because they feel they need to charge it overnight, but then they don't get their sleep data.

A routine that works well for me is to charge it twice. I charge in the morning as I get ready for the day (shave, shower, etc.) then again at night when I get ready for bed (brush my teeth, wash my face, etc.).

It's always charged and I get my sleep data.

I hope this helps!

Thursday, March 7, 2019

Drinking Diet Soda During Pregnancy and the Link to Autism

There is as much evidence linking diet soda to autism as there is vaccines. By this, I mean there is none. Being a parent is hard and I know you want to protect your kid, but part of protecting your kid is protecting them from preventable diseases. I also know that you wouldn't like it if your kid got something because another kid wasn't protected.

Diet soda doesn't cause autism, nor do vaccinations. The difference is that a vaccine will actually save your kid's life.

Get your kids vaccinated!

Wednesday, May 23, 2018

How to Disable Browser Autocomplete in a Password Box

Most modern browsers are coded to ignore autocomplete="off" on an <input type="password"> field, with the assumption that the site is just trying to be annoying and that the user should be allowed to save and autocomplete their password if they want to.

Most of the time, this is what the user wants. Most sites only have one place and one use case for entering a password: signing in. Some sites also require verification of the password for sensitive operations. Again, the assumption of "if the user wants to save the password, let them" might be OK for these situations as well.

Where this really breaks down is administrative uses.

If I'm an admin and I want to create users, in some applications, I need to set their password. Having the site autocomplete my password, is at best annoying, and could be a security concern.

There are also other uses of <input type="password">: credit card CCV codes, security question/answers, cryptographic keys, etc. and having the browser autocomplete your password is not a good idea.

In these cases, you need/want to disable autocomplete. This is the way I've found that seems to work in the latest version of IE, Firefox, Chrome, and Edge.

<input id="password" name="password" type="password"
 autocomplete="new-password"
 readonly="readonly"
 style="background-color:#fff" />

<script>
setTimeout(function() {
 $("#password").prop("readonly", false).css("background-color", "");
}, 50);
</script>

Starting out in readonly mode is enough for IE, Firefox, and Edge, but has no effect in Chrome. The background-color style just resets the style so it doesn't appear grayed out when the page first loads. The <script> is needed to enable the field after the page has loaded. I tried enabling it when the document loads (e.g. $(function() { ... })), but in Firefox, it triggered the autocomplete anyway. Introducing the delay was the only way to get it to work (50 ms seems to work in my testing - a 10 ms delay didn't work reliably).

I like the autocomplete="new-password" method and wish browsers would standardize around this (since they don't want to use the current standard of "off"). This attribute value works in current versions of Chrome (66.0.3359.181 at the time of this writing) and was the only thing that worked in Chrome, but has no effect in other browsers.

Thursday, August 4, 2016

World of Warcraft Error # 132 after installing Windows 10 Anniversary Update

I recently installed the Windows 10 Anniversary Update. After doing so however, my World of Warcraft installation started crashing during launch with a message stating Error 132 memory something or other referenced such and such.

I searched online for a solution and tried a bunch of things listed on this helpful Youtube link - the DX9 fix worked, but I found a better fix. I happened across a post listing what's new in the update and found that they "added support" for World of Warcraft in the Game DVR. On a hunch, I turned it off (in the settings of the X-Box app). Voila, WoW started working again with DX11.

Edit: After posting I found that Blizzard has an official post with the same resolution: http://us.battle.net/forums/en/wow/topic/20748004624#post-1.

Tuesday, January 26, 2016

SQL to de-dupe overlapping ranges of dates

I came across a situation today where I was given a set of date ranges (begin date to end date) and needed to de-duplicate the ranges so any overlapping dates are "collapsed" so the final result would only contain the distinct range(s) of dates. There are probably a number of solutions to this problem, but I rather liked what I came up with so I decided to post it here for posterity. Code first, explanation after:

-- Declare a table variable for test data
DECLARE @Data TABLE
(
 BeginDate DATETIME,
 EndDate  DATETIME
);
-- Fill the test data
INSERT INTO @Data
SELECT '2016-01-01', '2016-01-05'
UNION ALL SELECT '2016-01-03', '2016-01-10'
UNION ALL SELECT '2016-01-12', '2016-01-15'
UNION ALL SELECT '2016-01-14', '2016-01-18'
UNION ALL SELECT '2016-01-16', '2016-01-25'
UNION ALL SELECT '2016-01-16', '2016-01-20'
UNION ALL SELECT '2016-01-16', '2016-01-20'
UNION ALL SELECT '2016-02-01', '2016-03-13'
UNION ALL SELECT '2016-05-01', '2016-05-30'
UNION ALL SELECT '2016-05-28', '2016-06-10';

WITH S AS (
 SELECT BeginDate, MAX(EndDate) AS EndDate -- Select the starting ranges
 FROM @Data D
 WHERE NOT EXISTS(SELECT * FROM @Data WHERE BeginDate < D.BeginDate AND EndDate >= D.BeginDate)
 GROUP BY BeginDate
UNION ALL
 SELECT S.BeginDate, D.EndDate -- recursively expand the ranges
 FROM S
 INNER JOIN @Data D ON D.BeginDate BETWEEN S.BeginDate AND S.EndDate
   AND D.EndDate > S.EndDate
)
SELECT BeginDate, MAX(EndDate)
FROM S
GROUP BY BeginDate;

In this example, I used a common table expression (CTE) for my test data. The work is done by the "S" CTE. It starts by selecting any date range that doesn't have another date range that overlaps its begin date, grouping by that begin date, to select the max end date (to eliminate any ranges that start on the same day). It then recursively joins back to the original data, bringing in any date range that overlaps and has an end date further out. In the final output, you select the BeginDate and MAX(EndDate) to get your distinct list of date ranges.

If you have additional columns you need to group by, you'll need to add them in. For example:

-- Declare a table variable for test data
DECLARE @Data TABLE
(
 ID   INT,
 BeginDate DATETIME,
 EndDate  DATETIME
);
-- Fill the test data
INSERT INTO @Data
SELECT 1, '2016-01-01', '2016-01-05'
UNION ALL SELECT 1, '2016-01-03', '2016-01-10'
UNION ALL SELECT 1, '2016-01-12', '2016-01-15'
UNION ALL SELECT 1, '2016-01-14', '2016-01-18'
UNION ALL SELECT 1, '2016-01-16', '2016-01-25'
UNION ALL SELECT 2, '2016-01-16', '2016-01-20'
UNION ALL SELECT 2, '2016-01-16', '2016-01-20'
UNION ALL SELECT 2, '2016-02-01', '2016-03-13'
UNION ALL SELECT 2, '2016-05-01', '2016-05-30'
UNION ALL SELECT 2, '2016-05-28', '2016-06-10';

WITH S AS (
 SELECT ID, BeginDate, MAX(EndDate) AS EndDate -- Select the starting ranges
 FROM @Data D
 WHERE NOT EXISTS(SELECT * FROM @Data WHERE ID = D.ID AND BeginDate < D.BeginDate AND EndDate >= D.BeginDate)
 GROUP BY ID, BeginDate
UNION ALL
 SELECT S.ID, S.BeginDate, D.EndDate -- recursively expand the ranges
 FROM S
 INNER JOIN @Data D ON S.ID = D.ID
   AND D.BeginDate BETWEEN S.BeginDate AND S.EndDate
   AND D.EndDate > S.EndDate
)
SELECT ID, BeginDate, MAX(EndDate)
FROM S
GROUP BY ID, BeginDate;

Thursday, December 3, 2015

Starting a numbered list at a different number in Gmail or other web email client

I recently was sending a colleague a series of questions across multiple emails and I wanted to continue numbering the list where the previous email left off. The rich text editor used by Gmail doesn't have this built-in (not that I can find at least), but I figured out a way using my trusty browser tools.

I'm a web developer so using the browser tools is perfectly normal for me on an average day, but although this might be unfamiliar, it's fairly easy to accomplish.

  1. If you haven't done so already, open your formatting tools by clicking the A button in the toolbar, then insert the ordered list by clicking the "1 2 3" icon.
  2. Right-click your list and choose "Inspect element". If your browser doesn't have "Inspect element" or another "Inspect" option, you can press F12 to open the browser tools then click the button in the top left - this lets you then click the list to select it.
  3. You'll see the HTML of the current page. The <ol> tag is what you're looking for. Your tools might have auto-selected an <li> instead, in which case you'd look for the parent.
  4. Right-click the <ol> tag and choose "Add Attribute".
  5. Type "start=N" (no quotes) where N is the number you want to start with

Your browser should update immediately and you'll see the new number as your starting point.

Monday, August 10, 2015

David Hasselhoff Screensaver

It's good sense to lock your computer when you're away. My co-workers have a habit of punishing those who don't by changing their desktop background to a picture of David Hasselhoff (usually the one where he's naked holding a puppy), a practice known as "Hoffing". I decided to go one further and create a screensaver that displays mister Hasselhoff in all his glory.

This is the result. Extract the file on your victim's computer, right-click the .scr file and choose "Install". And here is the source code in case you're worried about malicious code (or just want to see how it works). I leaned heavily on the code from Frank McCown at http://www.harding.edu/fmccown/screensaver/screensaver.html.

Update 2015-09-17 - I found that the previous version was crashing when trying to move the image. I've uploaded new versions of the .scr and source code (same links) to resolve the issue.