I noticed the following statement when I was renewing my current xfinity internet plan.
Includes our xFI Gateway and all the benefits of xFi, plus
Unlimited data ($30/mo value) for peace of mind
The best WiFi coverage throughout your home, with an xFi Pod included if recommended
Hmm… After doing some research online, I found the evidence from my xfinity account usage page that the default internet monthly quota is 1.2TB, as shown in the following image.
You have 1 courtesy month to exceed 1229GB of usage without charge.
After using 1 courtesy month, if you exceed the plan you will be charged $10.00 for each 50GB of additional data provided, but charges will not exceed $100 each month, no matter how much you use. You can also purchase our unlimited data option.
Not too bad. But still, $10.00 for each 50GB of additional data provided seems just too high, even with the $100.0 additional dollar cap. So be mindful…
Union in SQL performs implicit deduping on all the columns, which can cause certain bugs if not paying enough attention.
For example, the output of the following SQL will only return ONE row.
SELECT
key
FROM (
SELECT
1 AS key
UNION ALL
SELECT
1 AS key
UNION ALL
SELECT
1 AS key
)
UNION
SELECT
key
FROM (
SELECT
1 AS key
UNION ALL
SELECT
1 AS key
UNION ALL
SELECT
1 AS key
)
If we are using UNION ALL
instead, the result will contain 6 rows instead.
** Acetaminophen and ibuprofen can help with fever and signs of discomfort. ** Teething rings, a cool washcloth, or a clean finger can be used to baby’s gums during times of teething discomfort. Brush teeth twice daily with fluoride toothpaste the size of a grain of rice on a soft toothbrush or clean finger. Avoid teething products with benzocaine. ** It is safe to take your baby outdoors if they are dressed appropriately and protected from the weather. Be cautious about exposing your baby to crowds or to people who may be sick. ** Use sunscreen (SPF 15 or higher). ** Saline drops can be used for nasal congestion, which is common in infants.
If you will be traveling with your family overseas, talk with your doctor about travel questions, or you can request an online pre-travel health consultation through our eTravel Clinic. Visit our website to learn more.
Helpful tips for this state of life.
If you will be traveling with your family overseas, talk with your doctor about travel questions, or you can request an online pre-travel health consultation through our eTravel Clinic. Visit our website to learn more.
I would like to port the data of the following table on https://www.etf.com/stock/FB into Google Spreadsheet using a programmatic manner.
I have tried Google’s built functions IMPORTHTML
and IMPORTXML
, but they do not work as expected.
The former can extract some lists / tables, but the target one is missed.
For the latter, I tried to query the element using filter like //table[@id='xxx']
, where xxx
is the id I obtained from Inspect tool, but failed again.
I suspect this is because that table is dynamically generated using some js function.
By inspecting the page source, it looks like the table data is driven by the following div element, where the giant base64Data
attributes seems to contain promising information.
<div id="etf-finder-results" data-react='{"page": "stock", "fundsTotal": "229", "tableTitle": "List of ETFs That Hold FB", "base64Data": "W3siY29sXzEiOiJUaWNrZXIiLCJjb2xfMiI6IkZ1bmQgTmFtZSIsImNvbF8zIjoiU2VnbWVudCIsImNvbF80IjoiRkIgQWxsb2NhdG...
After decoding, I was able to obtain the original json string of the entire table! I tried to curl
the url immediately and verified that the same base64 string can be retrieved.
Given an array of integers arr
.
We want to count number of indices i
, j
and k
where (0 <= i < j <= k < arr.length
) such as
arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
is equal to arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
.
Just doing brute-force to enumerate i
, j
and k
, and another loop to check the xor values in both subarrays.
class Solution:
def countTriplets(self, arr: List[int]) -> int:
n = len(arr)
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j, n):
a = b = 0
for l in range(i, j):
a ^= arr[l]
for l in range(j, k+1):
b ^= arr[l]
ans += 1 if a == b else 0
return ans
We can optimize the above solution by preprocessing all the prefix-xor values, then the xor value for any subarray can be computed in O(1) time.
class Solution:
def countTriplets(self, arr: List[int]) -> int:
n = len(arr)
ans = 0
prefix = list(arr)
for i in range(1, n):
prefix[i] ^= prefix[i - 1]
for i in range(n):
for j in range(i+1, n):
for k in range(j, n):
a = prefix[j - 1] ^ prefix[i] ^ arr[i]
b = prefix[k] ^ prefix[j - 1]
ans += 1 if a == b else 0
return ans
Instead of doing nested for-loops for all i
, j
and k
, we can enumerate j
first to determine the boundary of the two subarrays.
Then we can enumerate (say) all the left boundary i
of the left subarray and count different xor values using a dictionary.
Finally we can enumerate the right boundary k
of the right subarray and count all the xor values that appeared before.
from collections import Counter
class Solution:
def countTriplets(self, arr: List[int]) -> int:
n = len(arr)
ans = 0
for j in range(1, n):
xor = 0
counter = Counter()
for i in range(j - 1, -1, -1):
xor ^= arr[i]
counter[xor] += 1
xor = 0
for k in range(j, n):
xor ^= arr[k]
ans += counter[xor]
return ans
The fact that arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
is equal to arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
implies that
arr[i] ^ ... ^ a[k] = 0
.
On the other hand, if arr[i] ^ ... ^ a[k] = 0
, we can produce exactly k - i
unique triplets.
Therefore, we can enumerate all the subarrays (of length >= 2) that have xor value equal to 0 and do the counting accordingly.
class Solution:
def countTriplets(self, arr: List[int]) -> int:
n = len(arr)
ans = 0
xor = 0
for i in range(n):
xor = arr[i]
for j in range(i + 1, n):
xor ^= arr[j]
if xor == 0:
ans += j - i
return ans
We can further optimize the runtime of the above solution to O(n).
Note that arr[i] ^ ... ^ a[k] = 0
is equivalent to arr[0] ^ ... ^ arr[i-1] = arr[0] ^ ... ^ arr[k]
.
Therefore, # of unique triplets when k
is fixed is sum_s(k - s - 1)
for all 0 <= s < k
such that arr[0] ^ ... ^ arr[s] = arr[0] ^ ... ^ arr[k]
.
We can rearrange sum_s(k - s - 1)
as sum_s(k-1) - sum_s(s)
.
It follows that we just need to maintain (using two dictionaries) two values (count and index sum) for each distinct prefix xor while doing the prefix scan.
from collections import Counter
class Solution:
def countTriplets(self, arr: List[int]) -> int:
ans = 0
# Add a dummy entry for xor = 0 with index = -1 and cnt = 0.
xor_index_sum = Counter({0:-1})
xor_cnt = Counter({0:1})
xor = 0
for i in range(len(arr)):
xor = xor ^ arr[i]
if xor_cnt[xor] > 0:
ans += xor_cnt[xor] * (i - 1) - xor_index_sum[xor]
xor_index_sum[xor] += i
xor_cnt[xor] += 1
return ans