AI Tips Archive

These are not all my original works. I’ll be adding links to the original articles I found. This is just my archive to organize interesting prompts I’ve discovered, sharing them with the world while giving full credit to the real writers.

Text Humaniser Prompt

Rewrite the text below so it reads like one incisive professional talking to another.

  • Keep every idea and fact unless changing it makes the point clearer.
  • Active voice. Paragraphs no longer than three short sentences.
  • Vary sentence length; avoid a metronome rhythm.
  • Swap jargon or $10 words for plain ones. Use contractions.
  • Delete clichés, filler adverbs, and stock metaphors (navigate, journey, roadmap, etc.).
  • No bullet points unless they’re essential for scan-ability.
  • No summary footer. End on a crisp final line, not a recap.
  • Never use em dashes; use commas, periods, or rewrite the sentence instead.
  • Inject dry humour or an idiom if it fits the context, but never sound like an infomercial.
  • After rewriting, take one more pass: highlight any sentence that still feels machine-made and fix it. Return only the rewritten text.
Original post: Read here

Zustand Structure coding tools rule

Structuring Application State with Zustand

This guide provides principles for structuring application state using Zustand, a small, fast, and scalable bearbones state-management solution.

1. Define a Clear State Interface (with Actions)

Start by defining a TypeScript interface that explicitly describes the structure of your application’s state and the actions that will modify it. This is crucial for type safety and maintainability.

interface MyStore {
  dataItems: Item[];
  selectedItem: Item | null;
  isLoading: boolean;
  error: string | null;

  actions: {
    setDataItems: (items: Item[]) => void; // Sets the entire list of data items.
    setSelectedItem: (item: Item | null) => void; // Sets the currently selected item.
    updateItem: (id: string, updates: Partial<Item>) => void; // Updates a specific item's properties by ID.
    clearError: () => void; // Clears any error message.
  };
}

Explanation:

  • The interface clearly defines the state and the functions (actions) that modify it.
  • Descriptive comments explain the purpose of each action.

2. Creating the Zustand Store

Use the create function from Zustand to create your store. It’s common to also use middleware like devtools (for debugging) and immer (for simplified immutable updates).

import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware';

export const useMyStore = create<MyStore>()(
  devtools(
    immer((set) => ({
      dataItems: [],
      selectedItem: null,
      isLoading: false,
      error: null,

      actions: {
        setDataItems: (items) => set({ dataItems: items }),
        setSelectedItem: (item) => set({ selectedItem: item }),
        updateItem: (id, updates) =>
          set((state) => {
            const index = state.dataItems.findIndex((item) => item.id === id);
            if (index !== -1) {
              state.dataItems[index] = { ...state.dataItems[index], ...updates };
            }
          }),
        clearError: () => set({ error: null })
      }
    })),
    { name: 'my-store' } // Optional: Name for devtools
  )
);

Explanation:

  • create: The core function from Zustand.
  • devtools: Enables Redux DevTools integration for easy state inspection.
  • immer: Simplifies immutable updates. You can write code that looks mutable, but Immer handles the immutability behind the scenes.
  • set: The function provided by Zustand to update the store’s state.
  • The function passed to create defines the initial state and the actions.

3. Using the Store in Components

Use the useMyStore hook (or whatever you named your store hook) to access the state and actions in your components.

import { useMyStore } from './your-store-file'; // Adjust the path

const MyComponent = () => {
  const { dataItems, selectedItem, actions } = useMyStore();

  const handleUpdateItem = (id: string, updates: Partial<Item>) => {
    actions.updateItem(id, updates);
  };

  return (
    <>
      {/* Example: Displaying a list of items */}
      <ul>
        {dataItems.map((item) => (
          <li key={item.id}>
            {item.name} - <button onClick={() => handleUpdateItem(item.id, { name: "Updated Name" })}>Update Name</button>
          </li>
        ))}
      </ul>
    </>
  );
};
0.02g of CO2/view

Cleaner than 98% of pages tested

Website Carbon