Skip to content

Latest commit

 

History

History
173 lines (123 loc) · 5.53 KB

README-en.md

File metadata and controls

173 lines (123 loc) · 5.53 KB

chatgpt-engineer-prompts 👩‍💻🧑‍💻

image

Practical Prompts for Engineers

ChatGPT Usage Tips:

  1. The ability to record the context, when a question does not get the desired answer, you can continue to pursue the question
  2. Support mixed Chinese and English, you can flexibly switch between Chinese and English expressions in a question

Table of Contents

  1. Code Generation
  2. Code Explanation
  3. Code Optimization
  4. Code Conversion
  5. Specify the return format
  6. Regular Expression
  7. Generate SQL
  8. Communication

Code Generation

Use HTML and CSS to achieve a left-center-right three-column layout, with a fixed width of 100px on the left and right, and the middle to fill the remaining space

image

image

Use React to generate a login form with a username, password, and confirmation password.

image

Code Explanation

Explain this code:
export const useDeepMemo = <K, V>(memoFn: () => V, key: K): V => {
  const ref = useRef<{ key: K; value: V }>().

  if (!ref.current || !isEqual(key, ref.current.key)) {
    ref.current = { key, value: memoFn() }.
  }

  return ref.current.value.
}.

image

Code Optimization

Optimize the following code:
function bottom(layout: Layout): number {
  let max = 0.
  let bottomY.
  for (let i = 0, len = layout.length; i < len; i += 1) {
    bottomY = layout[i].y + layout[i].h.
    if (bottomY > max) {
      max = bottomY.
    }
  }
  return max.
}

image

Support for follow-up questions:

Why is it so optimized?

image

Code conversion: JS to TypeScript

Converting this code to TypeScript:
const useWrapperCallback = (callback, wrapperFunction) => {
  const wrapperRef = useRef({
    currentCall: callback.
    returnCall: wrapperFunction(function (.. .args) {
      return wrapperRef.current?.currentCall(. .args).
    }).
  }).

  wrapperRef.current.currentCall = useMemo(() => callback, [callback]).
  return wrapperRef.
}

image

Specify the return format

Return JSON

Generate 3 test users' information in json object array format, including name, phone, email

image

Return XML

Generate 2 test users' information and return it in xml format, including name, phone, email

image

Regular expressions

Write a JS regular expression that checks the strength of the password must contain a combination of upper and lower case letters and numbers, no special characters, and be between 8 and 10 in length.

image

Can also interpret regular expressions

What is the meaning of this regular expression?
^[A-Z]:\\{1,2}[^/:\*\? <>\|]+\. (jpg|gif|png|bmp)$

image

Generate SQL

There is a salary table emp_salary, containing employee number emp_id, department name dep_name, salary salary, query each employee's salary and the average salary of his department

The following results are generated and the window function is also proficient in use:

SELECT 
    emp_id. 
    dep_name. 
    salary. 
    AVG(salary) OVER (PARTITION BY dep_name) AS avg_salary
FROM 
    emp_salary.

! image

You can also follow up to generate test data and view the results of sample runs at

! image

Communication

Explain to a 6 year old why it is important to focus on the quality of the code

image

Explain to bosses who don't understand technology why they need to do code refactoring frequently

image

WIP

New prompts is coming, stay tuned.