teleren/devto huggingface dataset:
Arduino MAX30100 程式庫讀取資料的小臭蟲
Tags: max30100, arduino, spo2
Published: 2021-12-17 07:04:34

如果你有使用 [Arduino MAX30100 程式庫](https://github.com/gabriel-milan/Arduino-MAX30100)撰寫 Arduino 程式, 可能會遇到一個小問題, 若是沒有快速的讀取資料, 就可能會導致後續不再能夠讀取新的資料。以下以程式庫內的 [MAX30100_RawData](https://github.com/gabriel-milan/Arduino-MAX30100/blob/9ea5d11ff2cd69d884e7c5226224a983eeb5bbc7/examples/MAX30100_RawData/MAX30100_RawData.ino#L69)為例, 原本的 loop() 如下：

```cpp
void loop()
{
    uint16_t ir, red;

    sensor.update();

    while (sensor.getRawValues(&ir, &red)) {
        Serial.print(ir);
        Serial.print('\t');
        Serial.println(red);
    }
}
```

因為是不間斷的讀取資料, 所以可以正常運作, 不斷顯示讀到的原始資料：

```
Initializing MAX30100..SUCCESS
2105	1025
2114	1031
2128	1040
2142	1062
2171	1067
...
```

但是如果因為進行其他事務導致耽擱了時間, 我們以加入 delay(500) 為例：

```cpp
void loop()
{
    uint16_t ir, red;

    sensor.update();

    while (sensor.getRawValues(&ir, &red)) {
        Serial.print(ir);
        Serial.print('\t');
        Serial.println(red);
    }
    Serial.println("=======");
    delay(500);
}
```

你看到的輸出結果就可能會是這樣：

```
Initializing MAX30100..SUCCESS
35	36
=======
=======
=======
=======
=======
=======
...
```

你會看到 loop 裡面的 while 後來都沒有發生作用, 只看到印出分隔每次 loop() 的 "======="。這表示已經沒有讀取到新的資料了, 最主要的原因是程式庫從 MAX30100 模組讀取資料的 [MAX30100::readFifoData()](https://github.com/gabriel-milan/Arduino-MAX30100/blob/9ea5d11ff2cd69d884e7c5226224a983eeb5bbc7/src/MAX30100.cpp#L142) 是這樣寫的：

```cpp
void MAX30100::readFifoData()
{
    uint8_t buffer[MAX30100_FIFO_DEPTH * 4];
    uint8_t toRead;

    toRead = (readRegister(MAX30100_REG_FIFO_WRITE_POINTER) - readRegister(MAX30100_REG_FIFO_READ_POINTER)) & (MAX30100_FIFO_DEPTH - 1);

    if (toRead)
    {
        burstRead(MAX30100_REG_FIFO_DATA, buffer, 4 * toRead);

        for (uint8_t i = 0; i < toRead; ++i)
        {
            // Warning: the values are always left-aligned
            readoutsBuffer.push({.ir = (uint16_t)((buffer[i * 4] << 8) | buffer[i * 4 + 1]),
                                 .red = (uint16_t)((buffer[i * 4 + 2] << 8) | buffer[i * 4 + 3])});
        }
    }
}
```

其中 toRead 是用來計算模組上還有多少筆資料待讀取。MAX30100 使用一個總共 16 筆資料的環狀佇列, 並透過 FIFO_WR_PTR 暫存器紀錄下一筆資料要寫入的位置編號, 編號為 0~15；FIFO＿RD＿PTR 暫存器則是第一筆待讀取資料的位置編號。當兩個暫存器指向同一個位置時, 就表示佇列滿了, 這時若有新的資料就會被丟棄, 並且在 OVF_COUNTER (Overflow counter) 暫存器記錄被丟棄的資料筆數, 最多為 15。在上面的函式中, 透過這一列程式計算待讀取資料的筆數：

```cpp
toRead = (readRegister(MAX30100_REG_FIFO_WRITE_POINTER) - readRegister(MAX30100_REG_FIFO_READ_POINTER)) & (MAX30100_FIFO_DEPTH - 1);
```

也就是寫入位置與待讀取位置的差距, 但是並沒有考慮到佇列已滿, 也就是差距為 0 的狀況。如果讀取資料的速度不夠快, 佇列滿了, 這列程式就會得到待讀取資料為 0 筆的結論, 使得後面真正讀取資料的 if 內的程式根本不會執行。為了解決這個問題, 我們將程式小改一下, 只要 OVF_COUNTER 不為 0, 就表示佇列已滿, 將 toRead 設為 16 即可：

```cpp
if(readRegister(MAX30100_REG_FIFO_OVERFLOW_COUNTER) == 0)
  toRead = (readRegister(MAX30100_REG_FIFO_WRITE_POINTER) - readRegister(MAX30100_REG_FIFO_READ_POINTER)) & (MAX30100_FIFO_DEPTH-1);
else
  toRead = 16;
```

修改過後, 同樣的程式就可以得到正確的結果了：

```
Initializing MAX30100..SUCCESS
=======
8649	2722
8646	2725
8639	2731
8615	2718
8601	2716
8582	2702
8570	2703
8570	2698
8579	2701
8591	2709
8594	2707
8602	2712
8585	2716
8568	2714
8526	2711
8491	2700
=======
8437	2672
8422	2664
8426	2667
8431	2667
.....
```
What challenges do I need to overcome to excel at app development as a freelancer?
Tags: programming, appdevelopment
Published: 2021-12-17 06:44:01

Facts state that about 3 million apps are available on Google Play Store, over 2 million on Apple Store, and about half a million apps on Windows and Amazon Store. While it is true that app development will continue to expand, freelance app developers face some challenges while developing one.

Familiarizing yourself with those challenges and surpassing them can help you get jobs with the best app development companies. Here are some of them:

Development approach

Deciding which development approach to take is one of the most primary challenges for app developers. Why so? App development is much like building a structure. So, if the foundation is not strong enough, the building may collapse. Similarly, if a developer does not take the right approach, they might not build a satisfactory app. For example, freelance app developers must choose which framework and language will help them build a pleasing application.

Device compatibility and screen size

Working with device compatibility is another challenge for app development companies and freelancers. People involved in app development have to be mindful of the device that will run their application. For example, it could be an Android-based or an iOS-based device. In both cases, the development procedure shall vary.

Moreover, different devices have different sizes and pixel densities. It happens even with those devices that use the same operating system, iOS, for instance. A 16-inch Macbook Pro has 226 pixels per inch, whereas an 11-inch iPad Pro has 264 pixels per inch. App developers must consider the factor to build user-friendly apps.

Performance

Suppose you have developed a good-looking application. It doesn't matter if it doesn't perform effectively. Application performance includes many factors, such as battery and storage consumption.

All freelance app developers must consider all these factors during app development. Whatsapp saw 600 million downloads in 2020 because it adheres to performance guidelines.

With Eiliana, you can overcome such obstacles with regular freelance app development opportunities. Being immune to the challenges, you can excel in the field.
Advent of PBT 2021 - Day 17 - Solution
Tags: challenge, testing, webdev, javascript
Published: 2021-12-17 06:37:50

---
title: Advent of PBT 2021 - Day 17 - Solution
published: true
description: Advent of Property Based Testing 2021 - Day 17 - Solution
tags: challenge,testing,webdev,javascript
//cover_image: https://direct_url_to_image.jpg
---

Our algorithm was: **isHumbleNumber**.
[Go to the subject itself for more details](https://dev.to/dubzzz/advent-of-pbt-2021-day-17-3p8b)

CodeSandbox with a possible set of properties you may have come with: https://codesandbox.io/s/advent-of-pbt-day-17-solution-75tuu?file=/src/index.spec.ts&previewwindow=tests

---

## Property 1: should consider any composite of primes <=7 as humble

> for any number n product of factors <=7
> it should consider n as an humble number

Written with fast-check:

```ts
it("should consider any composite of primes <=7 as humble", () => {
  fc.assert(
    fc.property(
      fc.array(fc.integer({ min: 2, max: 7 }), { minLength: 1 }),
      (factors) => {
        // Arrange
        let n = 1;
        for (const f of factors) {
          if (n * f > 2 ** 31 - 1) break;
          n = n * f;
        }

        // Act / Assert
        expect(isHumbleNumber(n)).toBe(true);
      }
    )
  );
});
```

---

## Property 2: should consider any composite with one prime factor >7 as non-humble

> for any number n with at least one factor not divisible by any number in [2, 7]
> it should consider n as a non-humble number

Written with fast-check:

```ts
it("should consider any composite with one prime factor >7 as non-humble", () => {
  fc.assert(
    fc.property(
      fc
        .integer({ min: 11 }) // 8,9,10 would be filtered
        .filter((v) => v % 2 !== 0)
        .filter((v) => v % 3 !== 0)
        .filter((v) => v % 5 !== 0)
        .filter((v) => v % 7 !== 0),
      fc.array(fc.integer({ min: 1, max: 195225786 })),
      (tooLarge, factors) => {
        // Arrange
        let n = tooLarge;
        for (const f of factors) {
          if (n * f > 2 ** 31 - 1) break;
          n = n * f;
        }

        // Act / Assert
        expect(isHumbleNumber(n)).toBe(false);
      }
    )
  );
});
```

---

[Back to "Advent of PBT 2021"](https://dev.to/dubzzz/advent-of-pbt-2021-13ee) to see topics covered during the other days and their solutions.

More about this serie on [@ndubien](https://twitter.com/ndubien) or with the hashtag [#AdventOfPBT](https://twitter.com/search?q=%23AdventOfPBT).
Advent of PBT 2021 - Day 17
Tags: challenge, testing, webdev, javascript
Published: 2021-12-17 06:37:33

---
title: Advent of PBT 2021 - Day 17
published: true
description: Advent of Property Based Testing - Day 17
tags: challenge,testing,webdev,javascript
//cover_image: https://direct_url_to_image.jpg
---

> _Advent of PBT 2021 — Learn how to use property based testing and [fast-check](https://github.com/dubzzz/fast-check) through examples_

Our algorithm today is: **isHumbleNumber**.
It comes with the following documentation and prototype:
```ts
/**
 * Check if a number is an Humber number.
 *
 * Humble numbers are positive integers which have
 * no prime factors > 7.
 *
 * Source: https://rosettacode.org/wiki/Humble_numbers
 *
 * @param n - The number to be checked,
 *            superior or equal to zero and up to 2**31 -1
 */
declare function isHumbleNumber(n: number): boolean;
```

We already wrote some examples based tests for it:
```ts
it("should consider any prime number <=7 as humble", () => {
  expect(isHumbleNumber(2)).toBe(true);
  expect(isHumbleNumber(3)).toBe(true);
  expect(isHumbleNumber(5)).toBe(true);
  expect(isHumbleNumber(7)).toBe(true);
});

it("should consider any number <=7 as humble", () => {
  expect(isHumbleNumber(0)).toBe(true);
  expect(isHumbleNumber(1)).toBe(true);
  expect(isHumbleNumber(4)).toBe(true);
  expect(isHumbleNumber(6)).toBe(true);
});

it("should consider any compositite of 2, 3, 5 or 7 as humble", () => {
  expect(isHumbleNumber(2 * 2 * 2 * 2 * 2)).toBe(true);
  expect(isHumbleNumber(2 * 2 * 3 * 3 * 5 * 5 * 7 * 7)).toBe(true);
});

it("should consider number with prime factor >7 as non-humble", () => {
  expect(isHumbleNumber(11)).toBe(false);
  expect(isHumbleNumber(2 * 11)).toBe(false);
});
```

How would you cover it with Property Based Tests?

In order to ease your task we provide you with an already setup CodeSandbox, with examples based tests already written and a possible implementation of the algorithm: https://codesandbox.io/s/advent-of-pbt-day-17-qvdwh?file=/src/index.spec.ts&previewwindow=tests

You wanna see the solution? Here is the set of properties I came with to cover today's algorithm: https://dev.to/dubzzz/advent-of-pbt-2021-day-17-solution-3gfe

---

[Back to "Advent of PBT 2021"](https://dev.to/dubzzz/advent-of-pbt-2021-13ee) to see topics covered during the other days and their solutions.

More about this serie on [@ndubien](https://twitter.com/ndubien) or with the hashtag [#AdventOfPBT](https://twitter.com/search?q=%23AdventOfPBT).
Creating Fastmail Masked Emails without 1Password anytime and everywhere
Tags: reverseengineering, go, automation
Published: 2021-12-17 06:35:15

---
canonical_url: https://david.coffee/creating-fastmail-masked-emails-without-1password-anytime-and-everywhere
---

_Mirrored from my blog - https://david.coffee/creating-fastmail-masked-emails-without-1password-anytime-and-everywhere_

I love Masked Emails, Fastmails take on one-time-use email addresses. I've been doing something similar myself for years now, but it is a bit of a shame that it's so tightly coupled to 1Password. Sure you _can_ create them through the webinterface now, but it's still kind of a pain to use and not very convenient (unless you use 1Password). 

You can't even manually trigger creation of one within 1Password, so when the extension doesn't detect an email signup field, you're sorta out of luck. 

What I want is something like this: 

![showcase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wii2jj73rhd5p772dpoa.gif)
 
Let's get it working. 

The first thing I noticed is that the request to create a new masked email (through 1Password) isn't actually coming from the 1Password servers like I first thought, it goes directly from the client to api.fastmail.com, like seen on a reverse-proxy like Proxyman:

![Network screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92b732w7yzgak1q0tudb.jpg)

By the way, Fastmail also stated they put this functionality right into their open-source JMAP project [in a blogpost](https://blog.1password.com/making-masked-email-with-jmap/). 

After a bit of reverse-engineering the request format to the API server and replicating it in Golang:

![Requests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/el57zmcpp3qfw3xysnxt.jpg)
 
 I present you: https://github.com/dvcrn/maskedemail-cli

```
maskedemail-cli -accountid xxxx -token abcdef12345 create facebook.com
```

... and you get a new masked email for facebook.com, right in your shell!

## Glueing the CLI to shortcuts with KeyboardMaestro

I wanted this to be available everywhere whenever I need to. A full extension for a product that isn't mine would have been too much work, and I wanted it to work outside browsers as well. With something like KeyboardMaestro this is trivial to do

Here's the macro from above:

![KeyboardMaestro Macro](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kf7tums456almy9l9pa8.png)
 
1. Insert "..."
2. Retrieve the URL from the current browser window. I had to use some glue applescript here because Firefox has no scripting interface
3. Pipe it into the maskedemail-cli
4. Remove the "..." and paste the newly created email

## Other thoughts

I am sure this will become more available in the near future. Fastmail likely has some kind of exclusivity thing with 1Password for now, but it's great to see that we can hack ontop of it so easily. It's also very cool that this is built right into JMAP. I hope we'll see more email providers implementing it!

PS - I just wanted an excuse to write something on dev.to
Random Colour Generator JS
Tags: javascript, webdev, beginners, opensource
Published: 2021-12-17 06:18:01

Hey Folks!
Today I came up with this colour generator function.
This can be a really cool projects for newbie developers!
Well as the name suggests, it will randomly assign a new colour to the body of HTML page.
I am sharing my GitHub repository link for the same,which contains these functions in "script.js"
1) `getRandomColor()`
2) `getRandomColorLight()`
3) `getRandomColorDark()`
I would recommend you to have a look at it.

https://github.com/prakhart111/ColorFlipper


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4fvhkr3litijqt1i4a6.png)

Hope You liked it!
and comment down your way to do the same.
Follow me on:
Twitter : https://twitter.com/PrakharTandon29
GitHub : https://github.com/prakhart111
How to Fix Windows Update Error Code 0x8024402F
Published: 2021-12-17 05:19:19

In this blog by BloggingCoffe, we will talk about one of the most irritating errors “How to Fix Windows Update Error Code 0x8024402F?” Not only is the Windows 0x8024402f error restricted to Windows 10 OS (Windows 8.1, 8, and 7), but also users have complained of the error 0x8024402f. According to a Windows 10 user, when they attempted to download/install update, an error message comes out:

“There were some problems installing updates, but we’ll try again later. If you keep seeing this and want to search the web or contact support for information, this may help (0x8024402f).”

Well, this is truly maddening as when the error code 0x8024402f seems it avert Windows 10 from updating. Thus, firstly study the causes and then move to solutions. Read full detail <a href="https://bloggingcoffe.com/how-to-fix-windows-update-error-code-0x8024402f/">Here </a>
Use dio in Flutter / Dart
Tags: flutter, dart, dio
Published: 2021-12-17 04:59:55

We use dart's built-in `HttpClient` to call HTTP API:

```dart
HttpClient httpClient = HttpClient();
HttpClientRequest request = await httpClient.getUrl(uri);
// ...
```

But using `dio` to do so is much easier. If you are Python developer, thinking this as the built-in `urllib` vs the `requests` lib. The latter one is much easier to use.

Let's do a quick demo of using thsi `dio` package.

1, Create a folder named "diotest", then create the `pubspec.yaml` file:

```yaml
name: diotest
environment:
  sdk: '>=2.10.0 <3.0.0'
```

2, Install the `dio` package:
```bash
$ dart pub add dio
```

3, Create `main.dart` and write code like this:
```dart
import 'package:dio/dio.dart';

void main() async {
  BaseOptions options = BaseOptions(
    baseUrl: "https://httpbin.org",
    connectTimeout: 3000,
    receiveTimeout: 3000,
  );
  Dio dio = Dio(options);
  try {
    Response resp = await dio.get(
      "/get",
      queryParameters: {"search": "dio"},
    );
    print("Response:");
    print("Status:\n${resp.statusCode}");
    print("Header:\n${resp.headers}");
    print("Data:\n${resp.data}");
  } catch (e) {
    print("Exception: $e");
  }
}
```

All set, now just run it:
```bash
$ dart main.dart
Response:
Status:
200
Header:
connection: keep-alive
access-control-allow-credentials: true
date: Fri, 17 Dec 2021 04:50:26 GMT
access-control-allow-origin: *
content-length: 306
content-type: application/json
server: gunicorn/19.9.0

Data:
{args: {search: dio}, headers: {Accept-Encoding: gzip, Host: httpbin.org, User-Agent: Dart/2.14 (dart:io), X-Amzn-Trace-Id: Root=1-61bc1712-57909160379aeca870fa551c}, origin: 67.83.137.85, url: https://httpbin.org/get?search=dio}
```

For more on sending POST / PUT / DELETE / Upload Files, you can just visit the [example page](https://github.com/flutterchina/dio#examples)

## Reference
* [dart package](https://pub.dev/packages/dio)
* [dio examples](https://github.com/flutterchina/dio#examples)
React vs Vue: What is the Best Framework for your Project in 2022?
Tags: javascript, react, vue, jamstack
Published: 2021-12-17 04:32:00

React and Vue are rising stars in the JavaScript front-end frameworks ecosystem. React is backed by Facebook, and Vue is completely a community-driven project. The choices that React developers and Vue developers make have consequences as the project size grows, but they may not realize them when they first pick up on over the other.

Both React and Vue can accomplish the same thing. However, they provide different paths to reach the final destination. In this article, you'll look at different comparisons that will help you differentiate between React and Vue and ultimately help you decide which one you should choose in your future projects.

Read the full blog on [Adeva](https://adevait.com/javascript-developers/react-vs-vue).

Thanks for reading 💜

---

I publish a [monthly newsletter](https://www.ravsam.in/newsletter/) in which I share personal stories, things that I am working on, what is happening in the world of tech, and some interesting dev-related posts which I come across while surfing on the web.

Connect with me through [Twitter](https://twitter.com/ravgeetdhillon) • [LinkedIn](https://linkedin.com/in/ravgeetdhillon) • [Github](https://github.com/ravgeetdhillon) or send me an [Email](mailto:ravgeetdhillon@gmail.com).

— [Ravgeet](https://www.ravgeet.in/), *Full Stack Developer and Technical Content Writer*
Styling in React.js
Tags: webdev, react, javascript, beginners
Published: 2021-12-17 04:13:31

Today we are going to learn styling in css and how to declare variables and all.


For styling we can use inline and external file css which can be component based or page based. So we are going to use className for naming the component.

Also we can use variable for reuse value through the component.

Given below the example

```
 <div className="nav-wrapper">
      <nav className='nav-heading'>{c}</nav>
      <ul className='nav-items'>
        <li>Home</li>
        <li>Contact</li>
        <li>About</li>
      </ul>
    </div>
```

Css Code

```
.nav-wrapper{
    display: flex;
    height: 80px;
    background-color: aliceblue;
    width: 100vw;
    padding: 0 !important;
}
```

{% youtube y5ZsVNcpiLM %}
Release 0.3 Seneca-ICTOER/IPC144
Tags: opensource, osd600
Published: 2021-12-17 03:29:29

For this assignment we had to contribute to a Seneca repository. I chose the IPC144 [repo](https://github.com/Seneca-ICTOER/IPC144).

### Issue

The [issue](https://github.com/Seneca-ICTOER/IPC144/issues/89) is that the documents where mine specifically is pointers-arrays-and-structs.md were automatically converted to markdown text from the old IPC [website](https://ict.senecacollege.ca/~ipc144/pages/content/searc.html) so we have to check the conversion and fix anything that wasn't correct.

### PR

The [PR](https://github.com/Seneca-ICTOER/IPC144/pull/104) was pretty simple. For this file the only things that were changed are small. 

The first changes were making sure types are inline code. ex char* should be `char*`

The second was creating alt text for images and linking them to the `img` directory like such `![Representation of RAM](../../static/img/memorymap.png)` 

Lastly we add admonitions such as notes or caution like this 
```md
:::note
`a` and `p` are interchangeable. `p` may also be used as an array!
:::
```

Overall thoughts

It was cool contributing to a project for my school. Now I can cross that off my bucket list I guess haha. It was also seeing that that PR's for checking content that teaches others is just as important as code.
Get AAD AccessToken via PowerShell with user password
Published: 2021-12-17 03:00:01

I needed to get Azure AD Access Token by using hard-coded username and password. To do so, we can use ``grant_type=password``.

# Prerequisites

I registered an application to Azure AD to user for this.

# PowerShell script

I used following PowerShell script to get access token. As I didn't want to user MSAL as part of script, so I simply use ``Invoke-RestMethod``.
 
```powershell
$body = 'grant_type=password' + `
'&client_id=<client id>' + `
'&username=<user>@<yourdomain>.onmicrosoft.com' +`
'&password=<user password>' +`
'&resource=<resource i.e. https://graph.microsoft.com>' +`
'&client_secret=<client secret>' +`
'&scope=<score i.e. User.Read>'
$token = (Invoke-RestMethod -Method Post -Uri https://login.microsoftonline.com/common/oauth2/token -Body $body).access_token
```
How to Filter and Group the Blazor AutoComplete Items
Tags: blazor, dotnet, csharp, webdev
Published: 2021-12-17 02:48:51

In this video, you will learn how to group the [Blazor AutoComplete](https://www.syncfusion.com/blazor-components/blazor-autocomplete) items as well as how to filter them. You will also see different filter types in the AutoComplete and how to apply those filters. 

Explore our tutorial videos: https://www.syncfusion.com/tutorial-v... 

Download this example from GitHub: https://github.com/SyncfusionExamples... 

{% youtube XtqNSV0B3h8 %}