Archive of

Build command for deploying your flutter web app to cloudflare pages

set -x && if cd flutter; then git pull && cd .. ; else git clone https://github.com/flutter/flutter.git; (cd flutter && git fetch --tags && git checkout 3.22.3); fi && ls && flutter/bin/flutter doctor && flutter/bin/flutter clean && flutter/bin/flutter config --enable-web && cp .env.production .env && sed -i "s/VERSION_PLACEHOLDER/`git rev-parse --short HEAD`/" .env && flutter/bin/flutter build web --web-renderer html --base-href="/" --release

C# Linq:FirstOrDefault vs SingleOrDefault

In C#, both FirstOrDefault and SingleOrDefault are LINQ methods that operate on collections, but they serve different purposes:

FirstOrDefault

  • Purpose: Returns the first element in a collection that satisfies a specified condition, or the default value for the type if no such element is found.

  • Behavior:

    • If the collection contains multiple elements that satisfy the condition, it returns the first one.
    • If no elements satisfy the condition, it returns the default value (null for reference types, 0 for numeric types, etc.).
  • Use Case: When you're interested in getting the first match or a default value if none exist, and you don't care if there are multiple matches.

SingleOrDefault

  • Purpose: Returns the single element in a collection that satisfies a specified condition, or the default value for the type if no such element is found.

  • Behavior:

    • If the collection contains exactly one element that satisfies the condition, it returns that element.
    • If no elements satisfy the condition, it returns the default value.
    • If more than one element satisfies the condition, it throws an InvalidOperationException because the expectation is that there should be exactly one match.
  • Use Case: When you're expecting either one or zero matches, and multiple matches would indicate an error in your data or logic.

Summary

  • FirstOrDefault: Use when you want the first matching element or a default value, and multiple matches are acceptable.
  • SingleOrDefault: Use when you expect exactly one matching element or a default value, and multiple matches are an error.

fix TypeError: Instance of 'MappedListIterable': type 'MappedListIterable' is not a subtype of type 'FutureOr>'

--- a/lib/services/note_tag_service.dart
+++ b/lib/services/note_tag_service.dart
@@ -9,6 +9,5 @@ class NoteTagService {
   Future<Map<String, int>> getMyTagCloud() async {
     var apiResult = (await _noteTagApi.getMyTagCloud()).data;
     if (!apiResult['successful']) throw ApiException(apiResult);
-    return apiResult['data'].map((item) => {item['tag'] as String: item['count'] as int});
-  }
+    return { for (var item in apiResult['data']) item['tag'] as String : item['count'] as int };  }
+  }

C# inline regular expression syntax and usage

I found this brilliant answer at Stack overflow. It is way more clearer and useful than Microsoft's official one

You can use inline modifiers as follows:

// case insensitive match
Regex MyRegex = new Regex(@"(?i)[a-z]+");  // case insensitive match

or, inverse the meaning of the modifier by adding a minus-sign:

// case sensitive match
Regex MyRegex = new Regex(@"(?-i)[a-z]+");  // case sensitive match

or, switch them on and off:

// case sensitive, then case-insensitive match
Regex MyRegex = new Regex(@"(?-i)[a-z]+(?i)[k-n]+");

Alternatively, you can use the mode-modifier span syntax using a colon : and a grouping parenthesis, which scopes the modifier to only that group:

// case sensitive, then case-insensitive match
Regex MyRegex = new Regex(@"(?-i:[a-z]+)(?i:[k-n]+)");

You can use multiple modifiers in one go like this (?is-m:text), or after another, if you find that clearer (?i)(?s)(?-m)text (I don't). When you use the on/off switching syntax, be aware that the modifier works till the next switch, or the end of the regex. Conversely, using the mode-modified spans, after the span the default behavior will apply.

Finally: the allowed modifiers in .NET are (use a minus to invert the mode):

x allow whitespace and comments
s single-line mode
m multi-line mode
i case insensitivity
n only allow explicit capture (.NET specific)

Step 6 in detail: Configure Telegram Sync in HappyNotes

If you haven't read Step1 to Step 5, click Step 1 ~ Step 5

  1. Open the HappyNotes App:

    • Open https://happynotes.shukebeta.com with your favorite broswer and then navigate to the **Settings** page.
  2. Access Telegram Sync Settings:

    • Within the Settings page, look for the "Note Sync - Telegram" option.
    • Tap on it to open the sync settings page.
  3. Add a New Sync Configuration:

    • On the sync settings page, click on the "+ Add" button to create a new sync configuration.
  4. Enter the Required Information:

    • Source Note Choose the appropriate source note to sync from the options provided (e.g., Public, Private, All, Tag).

      • All - for backup purpose. It will sync every new note to the channel you specified. (Please don't use a public channel if you have any private notes!!!)
      • Private - only sync private notes to specified channel, you definitely should not use a public channel for this type of notes!
      • Public - only sync public notes to specified channel - if you use a telegram channel for your blog or microblog purpose, this option is for you!
      • Tag - only sync notes that are tagged with specific tag, You must know that it does not check the private/public flag, every new note that has the specified tag will be sent to the specified channel.
    • Channel Id: In the "Channel Id" field, enter the Channel Id you obtained earlier which looks like -100123456789.

    • Channel Name: This is a remark for the channel id, you can use the same channel name on Telegram or anything else you want.

    • Telegram Bot Token: In this field, paste your Telegram Bot Token . I strongly recommend you to use copy/paste feature instead of manually typing the token to avoid typos.

    • **Token Remark: ** Just like the channel name, this Token Remark helps you remember which token you are using for this channel. You can use your bot's name or anything else you want.

  5. Save the Configuration:

    • After filling in the details, click the "Save" button to store your sync configuration.
  6. Test the Sync Setting:

    • Once saved, you'll see your new configuration listed on the sync settings page.
    • Tap the "Test" button to send a test message to your Telegram channel.
    • If the test is successful, you’ll receive a confirmation message in your Telegram channel indicating that the sync is working, and the Test button will disappear.
  7. Activate or Adjust Sync Settings:

    • You can Disable or Activate or Delete a setting based on your requirements.
    • Make sure your bot is active and configured correctly to ensure smooth synchronization.