Skip to content

Instantly share code, notes, and snippets.

View cyberfly's full-sized avatar

Muhammad Fathur Rahman cyberfly

View GitHub Profile

Task: Q&A Chatbot.

Instructions: You are an intelligent and professional Assistant. You have access to files to answer questions about XYZ company information. Always respond with info from either of the files.

Input: Question from User as text.

Output: Concise and short answer as plain text.

@cyberfly
cyberfly / article_list.html
Last active May 14, 2024 02:44
example use case: after polling get how many pending article left, once it become zero, trigger event to ask article list to get latest data
<div
hx-get="/api/v2/{{ACTIVE_PROJECT_CODE}}/refresh_article_list"
hx-trigger="finishArticleGeneration from:body"
hx-select="#article_list_content"
hx-target="this"
>
<div id="article_list_content">
<!--do something-->
</div>
</div>
<form
id="keyword_suggestions_form"
hx-post="/api/v2/keyword_suggestions"
hx-target="#keywords_container"
hx-indicator="#loader_container"
hx-on:htmx:before-request="emptyDiv('#keywords_container')"
hx-trigger="submit[!isFieldEmpty('#seed_keyword')], submitKeywordSearch from:body"
>
<input type="hidden" name="search_type" id="search_type" value="all_terms">
</form>
class User(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
email = models.CharField(unique=True, null=False, blank=False)
password_hash = models.CharField(max_length=255, null=True, blank=False)
@property
def pending_articles_count(self):
return self.articles.filter(state__in=['pending_content', 'pending_translation']).count()
class Meta:
@cyberfly
cyberfly / views.py
Last active December 21, 2023 08:11
def articles(request):
filters = {
'user': request.user
}
rating = request.GET.get('rating')
search_q = request.GET.get('search_q')
if rating:
@cyberfly
cyberfly / test.html
Last active December 19, 2023 09:11
Add validation to hx-trigger. If validate false, hx-post is not trigger `hx-trigger="submit[!isFieldEmpty('#seed_keyword')]`
<form
id="keyword_suggestions_form"
hx-post="/api/v1/keywords"
hx-target="#keywords_container"
hx-indicator="#loader_container"
hx-on:htmx:before-request="emptyDiv('#keywords_container')"
hx-trigger="submit[!isFieldEmpty('#seed_keyword')], submitKeywordSearch from:body"
>
<button type="submit">Search</button>
</form>
<?php
namespace App\Libraries;
class Lookup {
// constant for MAP NEGERI ID
// const MAP_JOHOR = "001";
// const MAP_KEDAH = "002";
public function store()
{
$rules = [
'title' => 'required',
'description' => 'required',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput();
}
<script type="module">
let data = {!! $keywords !!};
$('#example tbody').on('click', 'button', function () {
var data = table.row($(this).parents('tr')).data();
$("#keyword").val(data.keyword);
$("#keyword").focus();
});