169 Matching Annotations
  1. Aug 2023
  2. May 2023
  3. Mar 2023
  4. Feb 2023
  5. Dec 2022
    1. Note: it is not possible to apply a boolean scope with just the query param being present, e.g. ?active, that's not considered a "true" value (the param value will be nil), and thus the scope will be called with false as argument. In order for the scope to receive a true argument the param value must be set to one of the "true" values above, e.g. ?active=true or ?active=1.

      Is this behavior/limitation part of the web standard or a Rails-specific thing?

  6. Oct 2022
  7. Sep 2022
  8. Aug 2022
    1. And in our case, we want it to keep track of our storage object. So let's also create a usePeristentContext hook.

      ```js import { useMutation, useQuery, useQueryClient } from 'react-query';

      export default function usePersistentContext(key) { const queryClient = useQueryClient();

      const { data } = useQuery(key, () => localStorage.getItem(key));

      const { mutateAsync: setValue } = useMutation( (value) => localStorage.setItem(key, value), { onMutate: (mutatedData) => { const current = data; queryClient.setQueryData(key, mutatedData); return current; }, onError: (_, __, rollback) => { queryClient.setQueryData(key, rollback); }, } );

      return [data, setValue]; } ```

      js function SetContext() { const [value, setValue] = usePersistentContext('item_context'); return ( <button onClick={() => setValue(value === 'on' ? 'off' : 'on')}> Click me {value} </button> ); }

  9. Jul 2022
  10. Jun 2022
  11. Apr 2022
    1. The result from the above request includes a _scroll_id, which should be passed to the scroll API in order to retrieve the next batch of results.

      This is the way to use scroll.

    1. Use with caution!

      Using regular expression in this way might cause "Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]", especially when together with "query?scroll=1m"

  12. Mar 2022
    1. ReconfigBehSci on Twitter: ‘@STWorg @ProfColinDavis @rpancost @chrisdc77 @syrpis this is the most in depth treatment of the impact of equalities law on pandemic policy that I’ve been able to find- it would seem to underscore that there is a legal need for impact assessments that ask (some) of these questions https://t.co/auiApVC0TW’ / Twitter. (n.d.). Retrieved 22 March 2022, from https://twitter.com/SciBeh/status/1485927221449613314

  13. Feb 2022
    1. js queryClient .getQueryCache() .findAll(['partial', 'key']) .forEach(({ queryKey }) => { queryClient.setQueryData(queryKey, newData) })

    1. However there are some restrictions: if you are going to use different URLs for GET/PATCH, for example, you have to use the same key, otherwise, React Query will not be able to match these queries.

      It is ok to use url as key for React query

  14. Jan 2022
    1. let's start with tag notes so i'm going to create a new note called tag note and a tag note takes
      • My tagnote structure for my tag doesnt work on repeated trying 1248hrs
    1. Data Transformation

      […]

      3. using the select option

      v3 introduced built-in selectors, which can also be used to transform data:

      /* select-transformation */
      
      export const useTodosQuery = () =>
        useQuery(['todos'], fetchTodos, {
          select: (data) => data.map((todo) => todo.name.toUpperCase()),
        })
      

      selectors will only be called if data exists, so you don't have to care about undefined here. Selectors like the one above will also run on every render, because the functional identity changes (it's an inline function). If your transformation is expensive, you can memoize it either with useCallback, or by extracting it to a stable function reference:

      /* select-memoizations */
      
      const transformTodoNames = (data: Todos) =>
        data.map((todo) => todo.name.toUpperCase())
      export const useTodosQuery = () =>
        useQuery(['todos'], fetchTodos, {
          // ✅ uses a stable function reference
          select: transformTodoNames,
        })
      
      export const useTodosQuery = () =>
        useQuery(['todos'], fetchTodos, {
          // ✅ memoizes with useCallback
          select: React.useCallback(
            (data: Todos) => data.map((todo) => todo.name.toUpperCase()),
            []
          ),
        })
      

      Further, the select option can also be used to subscribe to only parts of the data. This is what makes this approach truly unique. Consider the following example:

      /* select-partial-subscriptions */
      
      export const useTodosQuery = (select) =>
        useQuery(['todos'], fetchTodos, { select })
      
      export const useTodosCount = () => useTodosQuery((data) => data.length)
      
      export const useTodo = (id) =>
        useTodosQuery((data) =>
          data.find((todo) => todo.id === id))
      

      Here, we've created a useSelector like API by passing a custom selector to our useTodosQuery. The custom hooks still works like before, as select will be undefined if you don't pass it, so the whole state will be returned.

      But if you pass a selector, you are now only subscribed to the result of the selector function. This is quite powerful, because it means that even if we update the name of a todo, our component that only subscribes to the count via useTodosCount will not rerender. The count hasn't changed, so react-query can choose to not inform this observer about the update 🥳 (Please note that this is a bit simplified here and technically not entirely true - I will talk in more detail about render optimizations in Part 3).

      • 🟢 best optimizations
      • 🟢 allows for partial subscriptions
      • 🟡 structure can be different for every observer
      • 🟡 structural sharing is performed twice (I will also talk about this in more detail in Part 3)
    2. Data Transformation

      [...]

      2. In the render function

      As advised in Part 1, if you create custom hooks, you can easily do transformations there:

      /* render-transformation */
      
      const fetchTodos = async (): Promise<Todos> => {
        const response = await axios.get('todos')
        return response.data
      }
      
      export const useTodosQuery = () => {
        const queryInfo = useQuery(['todos'], fetchTodos)
        return {
          ...queryInfo,
          data: queryInfo.data?.map((todo) =>
            todo.name.toUpperCase()),
        }
      }
      

      As it stands, this will not only run every time your fetch function runs, but actually on every render (even those that do not involve data fetching). This is likely not a problem at all, but if it is, you can optimize with useMemo. Be careful to define your dependencies as narrow as possible. data inside the queryInfo will be referentially stable unless something really changed (in which case you want to recompute your transformation), but the queryInfo itself will not. If you add queryInfo as your dependency, the transformation will again run on every render:

      /* useMemo-dependencies */
      
      export const useTodosQuery = () => {
        const queryInfo = useQuery(['todos'], fetchTodos)
        return {
          ...queryInfo,
          // 🚨 don't do this - the useMemo does nothing at all here!
          data: React.useMemo(
            () => queryInfo.data?.map((todo) => todo.name.toUpperCase()),
            [queryInfo]
          ),
          // ✅ correctly memoizes by queryInfo.data
          data: React.useMemo(
            () => queryInfo.data?.map((todo) => todo.name.toUpperCase()),
            [queryInfo.data]
          ),
        }
      }
      

      Especially if you have additional logic in your custom hook to combine with your data transformation, this is a good option. Be aware that data can be potentially undefined, so use optional chaining when working with it.

      • 🟢 optimizable via useMemo
      • 🟡 exact structure cannot be inspected in the devtools
      • 🔴 a bit more convoluted syntax
      • 🔴 data can be potentially undefined
    1. 🤔 So what?

      Let’s review a typical Redux process for a fetch operation:

      1. Dispatch an Action fetchSomething() from within the Component
      2. This Action hits the Reducer which will update the store with something like isLoading: true
      3. The Component re-renders and displays a loader
      4. In the meanwhile the Action hits the Middleware which takes care of calling the API
      5. The API returns the response to the Middleware, which dispatches another Action: fetchSomethingSucceeded() when succeeded, or fetchSomethingFailed() when failed
      6. The succeeded/failed Action hits the Reducer, which updates the store
      7. Finally, the response is back to the Component (optionally through a memoized selector) which will show the data

      It’s a long process for just a simple fetch, isn’t it?

  15. Dec 2021
    1. Increasing StaleTime

      React Query comes with a default staleTime of zero. This means that every query will be immediately considered as stale, which means it will refetch when a new subscriber mounts or when the user refocuses the window. It is aimed to keep your data as up-to-date as necessary.

      This goal overlaps a lot with WebSockets, which update your data in real-time. Why would I need to refetch at all if I just manually invalidated because the server just told me to do so via a dedicated message?

      So if you update all your data via websockets anyways, consider setting a high staleTime. In my example, I just used Infinity. This means the data will be fetched initially via useQuery, and then always come from the cache. Refetching only happens via the explicit query invalidation.

      You can best achieve this by setting global query defaults when creating the QueryClient:

      const queryClient = new QueryClient({
        defaultOptions: {
          queries: {
            staleTime: Infinity,
          },
        },
      })
      
  16. Nov 2021
    1. The Query word can be interpreted as the word for which we are calculating Attention. The Key and Value word is the word to which we are paying attention ie. how relevant is that word to the Query word.

      Finally

  17. Sep 2021
    1. don’t store all the values from onerow together, but store all the values from each column together instead. If each col‐umn is stored in a separate file, a query only needs to read and parse those columnsthat are used in that query, which can save a lot of work.

      Why column storage is better query optimized

  18. Aug 2021
    1. So for each word, we create a Query vector, a Key vector, and a Value vector. These vectors are created by multiplying the embedding by three matrices that we trained during the training process.
    1. I'm going to try provide an English text example. The following is based solely on my intuitive understanding of the paper 'Attention is all you need'.

      This is also good

    2. For the word q that your eyes see in the given sentence, what is the most related word k in the sentence to understand what q is about?
    3. So basically: q = the vector representing a word K and V = your memory, thus all the words that have been generated before. Note that K and V can be the same (but don't have to). So what you do with attention is that you take your current query (word in most cases) and look in your memory for similar keys. To come up with a distribution of relevant words, the softmax function is then used.
    1. We can even say that server caching tools like React-Query, SWR, Apollo, and Urql fit the definition of "state management" - they store initial values based on the fetched data, return the current value via their hooks, allow updates via "server mutations", and notify of changes via re-rendering the component
  19. May 2021
    1. Note that variables cannot appear in the predicate position.
    1. This media query only targets WebKit-supported email clients—which have incredible support for HTML5 and CSS3. This media query allows you to use of modern techniques like HTML5 video, CSS3 animation, web fonts, and more.
  20. Feb 2021
    1. Can I transfer money from the Direct Express® card to a checking or savings account?
    2. Can I get cash when I need it with my Direct Express® card?
    3. How do I get cash at a bank teller window?
    4. How does the free Low Balance Alert work?
    5. How does the free Deposit Notification work?
    6. How can I protect my PIN?
    7. Do I always need to use my PIN? Can I use my card without a PIN?
    8. What if I forget my PIN?
    9. Can I change my PIN?
    10. What is a PIN?
    11. Can I pay my bills or pay for Internet purchases with my Direct Express® card?
    12. How do I check my balance on my Direct Express® card?
    13. Where can I use my Direct Express® card?
    14. How do I make purchases with my card?
    15. Is Customer Service available in languages other than English?
    16. Can I close my account and withdraw my money?
    17. Can I have a monthly paper statement mailed to me?
    18. What if I don't agree with my balance or one of my transactions?
    19. Who should I notify if I change my mailing address?
    20. How long will it take to receive a replacement card if reported lost or stolen?
    21. What if my Direct Express® card is lost or stolen?
    22. Who do I call if I have questions about how to use my Direct Express® card?
    23. What if I can't find an ATM or my ATM is "out of order"?
    24. How do I know if an ATM surcharge fee will be charged when I withdraw cash at an ATM?
    25. What is the maximum amount of cash I can withdraw from an ATM with my Direct Express® card?
    26. Where can I find Direct Express® card network ATMs?
    27. What is the Direct Express® card surcharge-free ATM network?
    28. How do I get cash at an ATM with my card?
    29. How much will people be charged for going to an out-of-network ATM?
    30. What if I don't live near a Direct Express® card surcharge-free network ATM?
    31. How do I find a surcharge free network?
    32. Is there a fee to use the ATM?
    33. How does my free ATM cash withdrawal work?
    34. How do I avoid transaction fees while using my Direct Express® card?
    35. How much do I have to pay for the Direct Express® card?
    36. What are my options if the Direct Express® card is just not for me?
    37. I plan to retire in the near future. Can I request a Direct Express® card as soon as I sign up for my Social Security benefits?
    38. Can I sign up for the Direct Express® card even if I have a bank account?
    39. Can recipients who have a Direct Express® card switch to a traditional checking or savings account and receive their payment by direct deposit?
    40. Are federal benefit recipients residing in a healthcare facility eligible for the Direct Express® card?
    41. I am a representative payee who receives another type of federal benefit payment on behalf of someone else. Can I sign up for a Direct Express® card?
    42. I am a representative payee who receives Social Security benefits on behalf of more than one person. Can I receive all of the benefits on one Direct Express® card?
    43. I am a representative payee who receives Social Security benefits for someone else. Can I sign up for a Direct Express® card?
    44. Do I need to give my federal paying agency my card information in order to receive benefits?
    45. How do I activate my Direct Express® card?
    46. How do I sign up for the Direct Express® card?
    47. What are the benefits of the Direct Express® card?
    48. How is the Direct Express® debit card different from a credit card?
    49. Will my Social Security, Supplemental Security Income, and other federal benefits be safe?
    50. How does the Direct Express® card work?
    51. What type of federal payments can I have on the Direct Express® card account?
    52. What is the Direct Express® card?
    1. # Returns a new relation, which is the logical union of this relation and the one passed as an # argument. # # The two relations must be structurally compatible: they must be scoping the same model, and # they must differ only by #where (if no #group has been defined) or #having (if a #group is # present). Neither relation may have a #limit, #offset, or #distinct set.
  21. Oct 2020
  22. Sep 2020
  23. Aug 2020
  24. Jul 2020
  25. May 2020
    1. bug_status=NEW&bug_status=ASSIGNED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED

      Passing multiple values for the same param key

  26. Mar 2020
  27. Sep 2019
  28. Nov 2018
  29. Jul 2018
  30. Jun 2018
  31. May 2018
  32. Nov 2017