Thursday, March 28, 2024

Form button for two forms

Recently need line up two form submit buttons for two different forms. So I asked Copilot and Gemini. also the perplexity.

Here are the results:

Copilot:

<form>
    <!-- Form 1 content -->
    <button type="submit" formaction="/action_one">Submit Form 1</button>
    <!-- Form 2 content -->
    <button type="submit" formaction="/action_two">Submit Form 2</button>
</form>
Gemini:
<form action="form1_action.php" method="post">
  <input type="submit" value="Submit Form 1">
</form>

<form action="form2_action.php" method="post">
  <input type="submit" value="Submit Form 2">
</form>
Perplexity: - no two forms
<form action="/DEFAULT_URL" method="post">
  <!-- Input fields here -->
  <button type="submit">BUTTON 1</button>
  <button type="submit" formaction="/URL2">BUTTON 2</button>
</form>
So look not what I want, or I did not prompt properly? Any way, what I want is:
<form ...>
    ...
    ...
    <button ...>Save</button>
    <button form="back-form"...>Back</button>
</form>
<form id="back-form" ...></form>
sighing...

Monday, March 18, 2024

Regular Expressions 101

 /^.*ezsend\/link\/([\w-]+)\/([\w-]+)\/([\w-]+)?.*$

Regular expression sounds very intimating....Good site for testing - https://regex101.com/

Let's break down the regular expression ^.*ezsend\/link\/([\w-]+)\/([\w-]+)\/([\w-]+)?.*$:

^: Asserts the start of the string.

.*: Matches any character (.) zero or more times (*). This part is used to match any characters before the "ezsend/link" part of the URL.

ezsend\/link\/: Matches the literal string "ezsend/link/".

([\w-]+): This is the first capturing group, denoted by the parentheses. It matches one or more word characters (\w) or hyphens (-). Word characters include letters, digits, and underscores.

\/: Matches the forward slash / after the first token.

([\w-]+): This is the second capturing group, which matches the second token similar to the first one.

\/: Matches the forward slash / after the second token.

([\w-]+)?: This is the third capturing group, matching the third token similar to the first two. The ? makes this group optional, allowing the pattern to match URLs with or without a third token.

.*: Matches any remaining characters after the third token, if present.

$: Asserts the end of the string.

Here's how this regex works:

It starts by matching any characters before "ezsend/link/", ensuring that the URL contains this path.

Then, it matches the three tokens separated by forward slashes, allowing hyphens in each token.

The third token is optional, indicated by the ?.

Finally, it matches any remaining characters in the URL until the end of the string.

This regular expression is designed to capture the three tokens from URLs containing hyphens in each token, such as "xSwAAAAAAAA", "l-f1bdGQ92Q", and "ftG-CggAAAA".


ModelState.Clear vs TryValidateModel(manageModel)

 


`ModelState.Clear()` and `TryValidateModel(manageModel)` are both methods commonly used in ASP.NET Core applications to manage model validation.

1. `ModelState.Clear()`: This method is used to clear any model state errors that have been added to the `ModelState` dictionary. In ASP.NET Core, `ModelState` is a dictionary-like object that holds information about the state of model binding and validation for a given request. It stores information about model properties and their validation errors. Calling `ModelState.Clear()` removes all existing validation errors, effectively resetting the model state to a clean state.

2. `TryValidateModel(manageModel)`: This method is used to manually trigger model validation for a specified model object (`manageModel` in this case). By calling `TryValidateModel(manageModel)`, you are instructing ASP.NET Core to validate the specified model object against any validation rules defined in its associated data annotations or custom validation logic. If validation succeeds, the method returns `true`, indicating that the model is valid. If validation fails, the method returns `false`, and any validation errors are added to the `ModelState` dictionary.

In summary, `ModelState.Clear()` is used to clear any existing model state errors, while `TryValidateModel(manageModel)` is used to manually trigger model validation for a specific model object. These methods are often used together to ensure that model validation is performed correctly in ASP.NET Core applications.

evt.preventDefault vs evt.stopPropagation

 


evt.preventDefault()` and `evt.stopPropagation()` are both methods commonly used in JavaScript to control event propagation and behavior.

1. `evt.preventDefault()`: This method is used to prevent the default behavior of an event. In many cases, when an event (such as a click or form submission) occurs, the browser executes some default behavior associated with that event. For example, clicking on a link navigates the browser to the URL specified in the link's `href` attribute. By calling `evt.preventDefault()` inside an event handler function, you can prevent this default behavior from occurring. This is useful when you want to handle an event in a custom way, such as submitting a form via Ajax instead of the default form submission behavior.

2. `evt.stopPropagation()`: This method is used to stop the propagation of an event through the DOM tree. When an event occurs on an element, it typically "bubbles" up through the DOM tree, triggering event handlers on ancestor elements. By calling `evt.stopPropagation()`, you prevent the event from propagating any further in the DOM tree. This means that event handlers on parent elements will not be executed. This is useful when you want to handle an event on a specific element without triggering event handlers on its ancestors.

In summary, `evt.preventDefault()` is used to prevent the default behavior of an event, while `evt.stopPropagation()` is used to stop the event from propagating further through the DOM tree. Both methods are commonly used together to control event behavior in JavaScript applications.


Tuesday, February 20, 2024

AI席卷全球龙头狂卷

最近几天,AI市场竞争日趋激烈。各大科技公司都在积极布局AI领域,推出各种新产品和新服务。特别时谷歌双子座(Google Gemini)和OpenAi 索拉(Sora),连我这样的小白也心潮起伏,决定恶补学习不能被时代浪潮抛弃啊:)



主要竞争者和热点

目前,AI市场的主要竞争者包括:

谷歌:谷歌在AI领域拥有强大的技术实力和丰富的资源,是AI市场的主要领导者。

微软:微软在AI领域也进行了大量投入,在一些细分领域具有领先优势。

亚马逊:亚马逊在AI领域主要集中在云服务方面,为企业提供AI解决方案。

Facebook:Facebook在AI领域主要集中在自然语言处理和计算机视觉方面。

百度:百度是中国领先的AI公司,在搜索、广告、自动驾驶等领域拥有广泛的应用。

阿里巴巴:阿里巴巴是中国另一家领先的AI公司,在电商、金融、物流等领域拥有广泛的应用。

竞争热点

自然语言处理:自然语言处理是AI领域的重要分支,主要研究人机之间的语言交互。

计算机视觉:计算机视觉是AI领域的重要分支,主要研究计算机对图像和视频的理解和处理。

机器学习:机器学习是AI的核心技术,主要研究计算机从数据中学习和自动改进的能力。

深度学习:深度学习是机器学习的一个重要分支,主要使用人工神经网络进行学习。

本人小白,一直在用Chatgpt帮助写程序,没有花钱也没有花精力,只是免费3.5;觉得写程序足够了,虽然它的知识库比较旧。今天加圈,希望向高手学习,我不由得抛出一块砖:),敬请指教。

下面主要就三家-聊天室(Chatgpt),谷歌双子座(Google Gemini)),微软副驾驶(Copilot)做个入门比较。

打开后我输入:

可否写一篇最新人工智能AI产品介绍比较,比如 coze,Taskade,copilot,Google Gemini, discord,midjourney, openai chatgpt,Sora等等

Chatgpt3.5回答:当我上次更新知识库时,即2022年1月,我并没有收集到关于所有这些产品的详细信息。然而,我可以根据我之前了解到的信息和推测为你提供一些一般性的介绍。请注意,这些信息可能已经过时,建议查阅最新的资料以获取准确和详细的信息。

因为这一原因,不再做比较,等搞好4.0再说。

Gemini和Copilot回答基本相似,都提及了刚刚推出的Sora和Gemini。Gemini还给了个比较表,而Copolit附上了信息来源地址。




接着提问:可否具体详细介绍并列出您的排行及推荐

Copilot排行推荐:Cozen,Taskade,Copilot,Gemini,Discord,Midjourney,Chatgpt, Sora
Gemini排行推荐:Gemini,Chatgpt,Copilot,Midjourney,Sora
Gemini把自己排第一,Copilot还挺谦虚,不过力压Gemini:)

接着做了一些生成图片和诗词指令,都还不错,Gemini似乎快一些,谷歌毕竟是老牌实力雄厚,听说这次全力以赴试图登上AI龙头位置。免费二年使用还是有很大吸引力,Copilot免费版本似乎也不错,交费三家差不多,20美元左右。

图像生成Copilot用的是Dall-E-OpenAI开发的一系列图像生成器,而GGemini使用Imagen生成图像,Imagen是Google AI于2023年5月推出的一个文本到图像扩散模型,可以生成逼真和富有创意的图像。

输入:请创作一首有关龙的传人之词,词牌为《西江月》
完全失败,三家全都是驴头不对马嘴,Coplit可能觉得不好意思,生成了不少图片。

再输入:您知道西江月多少字吗?
回答倒是正确50字上下阕,但就是写不出来,知识库还没有那么广,慢慢学习。


咋天首次用AI写了个春节报道文案,还是不错能省一半时间:)喜欢写作的我也许可以在这方面用用功,
听说不少写手写个大纲出文本,再用文本出图,发表在亚马逊自嗨平台(self publishing)。

最后谈谈现在流行的一个工程师,就是Prompt Engineer-指令工程师。

具体职责:

研究和理解各种生成式 AI 模型的特性和能力。
分析用户需求,并将其转化为清晰具体的指令 (prompt) 给 AI 模型。
设计、测试和优化不同的 prompt,以获得最佳的输出结果。
评估和分析 AI 模型的输出,并根据需要进行调整和改进。
根据特定领域和任务,开发和应用 prompt 工程技术。
与其他团队成员 (如数据科学家、工程师) 合作,构建和实现 AI 应用。

所需技能:

人工智能、自然语言处理 (NLP) 和机器学习方面的知识。
扎实的编程能力,熟悉各种编程语言和工具。
优秀的沟通和写作能力,能够清晰地表达自己的想法。
批判性思维和解决问题的能力,能够分析复杂的场景并找到解决方案。
对新技术和趋势的敏感性,并愿意不断学习和提升技能。

职业发展路径:

随着经验的积累,可以进一步提升技术水平,成为资深 prompt engineer。
可以专注于特定的领域,成为该领域的专家。
转向管理岗位,带领团队开发和实施 AI 应用。
创业,建立自己的 AI 公司。

薪资水平:

Prompt engineer 的薪资水平因地域、经验、公司规模等因素而异。在美国,prompt engineer 的平均年薪约为 150,000 美元。

是不是很诱人?!AI说我消减了不少工作,但我也创造了许多机会,所言虚否?!