Skip to content

Instantly share code, notes, and snippets.

@PostPCEra
Created May 20, 2024 22:46
Show Gist options
  • Select an option

  • Save PostPCEra/cb1d4ae00a5505328b95513ea6ff0213 to your computer and use it in GitHub Desktop.

Select an option

Save PostPCEra/cb1d4ae00a5505328b95513ea6ff0213 to your computer and use it in GitHub Desktop.

Revisions

  1. PostPCEra created this gist May 20, 2024.
    44 changes: 44 additions & 0 deletions Toggle-filter-Category-list.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    all_tags = []; // init with empty array ; accuumulate all selcted tags here
    // ------------------------
    get_all_selected_tags = function (tag) {
    // if tag already exists in the list, remove it, otherwise add it to list
    if (all_tags.includes(tag)) {
    all_tags = all_tags.filter((item) => item != tag); // remove tag
    } else {
    all_tags.push(tag); // add tag
    }
    console.log("all tags:", app.all_tags);
    return all_tags;
    };

    /* NARROW the SCOPE : to get Things Cheper in PROGRAMMMING or LIFE ...
    -=== Patterns of LLM Prompts.
    - you need to narrow the question to get a CHEAPER and Better and Quicker answers with AI
    - above is TRUE either with HUMANS or AI
    - Here is example
    - When I click a Tweet Category buttons I should get Tweets in that category. And the category button is Togglable, meaning If I click second time that Category is NOT in the list.
    - User can click multiple buttons one after another, each Button click is Considered Toggleed State.
    - build a program to get Tweets from REST API Server
    - Ask estimate people say 2 to 3 days.
    - Tell them SERVER API exists just you need to call from front-end UI, people say Estimate 1.5 day
    - say Front-end UI and Code also exists, there is API to get all Tweets /tweets
    - you need to build /tweets/?tags=news,sports
    - people say estimate is .5 day
    - design of it is 2 hours, implementaiton Coding& Testing is 2 hours
    - Design is: Have a List(Array) to hold Categories and with each Button click Change the List and finally Build URL from the List to make Rest API call
    - coding& implementation: is 2 hours, have a function(List, categoryString) and it Rerurns new List
    -- ========== Prompt to Gemini =============
    I am coding in python, i have below function , if newone already exists in list, it should be removed other wise it newone should be added to list:
    handle_list(list1, newone):
    if newone in list1:
    # remove newone from list1
    else
    list1.append(newone)
    return list1
    --- ====== Gemini One line answer ======================
    def handle_list(list1, newone):
    return [x for x in list1 if x != newone] + [newone]
    */